Skip to main content
Model Gateway lets you use Stagehand without wiring up model providers yourself. Instead of managing separate API keys for OpenAI, Anthropic, and Google, just use your Browserbase API key and pick a model. Browserbase routes the request to the upstream provider for you.

Setup

When only a Browserbase API key is provided (without a provider-specific API key), Stagehand automatically routes model requests through Model Gateway. No additional configuration is needed.
import { Stagehand } from "@browserbasehq/stagehand";

const stagehand = new Stagehand({
  env: "BROWSERBASE",
  apiKey: process.env.BROWSERBASE_API_KEY,
  model: "openai/gpt-5",
});

await stagehand.init();
Compare this to the traditional setup, where you manage both a Browserbase key and a separate provider key:
// without Model Gateway — you manage two sets of credentials
const stagehand = new Stagehand({
  env: "BROWSERBASE",
  apiKey: process.env.BROWSERBASE_API_KEY,
  model: {
    modelName: "openai/gpt-5",
    apiKey: process.env.OPENAI_API_KEY,
  },
});
Model Gateway requires Browserbase-hosted browsers. It does not work with env: "LOCAL".

Switching models

With Model Gateway, switching between providers is a config change — no new accounts, API keys, or code rewiring required:
const stagehand = new Stagehand({
  env: "BROWSERBASE",
  apiKey: process.env.BROWSERBASE_API_KEY,
  model: "openai/gpt-5",
});

Key benefits

  • One key, one bill — LLM inference, browser infrastructure, and caching all run through your Browserbase API key. No separate provider accounts to manage.
  • Market-price tokens — Tokens are billed at the same price as going direct to the provider. No markup.
  • Built-in reliability — Retries, backoff, and rate limit handling are managed for you.
  • No tier-gating — Access new models immediately without hitting provider spend thresholds. No need to “earn” access to the latest releases.
  • Action caching — Model Gateway works with Stagehand’s managed action caching, so repeated steps are reused instead of re-run, reducing cost and latency across sessions.

Supported providers

ProviderExample Model
OpenAIopenai/gpt-5
Anthropicanthropic/claude-sonnet-4-6
Googlegoogle/gemini-2.5-flash
Need a provider that isn’t listed? Reach out — Browserbase is happy to work with teams on additional model support.

Pricing

Model Gateway tokens are billed at market price — the same rate you’d pay going direct to the provider. There is no additional markup. Usage appears on your existing Browserbase bill alongside browser time, proxy bandwidth, and other platform usage. See Plans for details on included allocations and overages.

Next steps

Stagehand

The AI SDK for browser agents. Natural language selectors, self-healing actions, and built-in caching.

Functions

Deploy your Stagehand agents as serverless functions on Browserbase infrastructure.