Skip to content

[Docs] Make model routing logic clearer - #2642

Open
akeimach wants to merge 3 commits into
v4-spikefrom
alyssamaruyama/stg-2795-make-sure-v3-model-routing-doc-updates-are-covered-in-v4
Open

[Docs] Make model routing logic clearer#2642
akeimach wants to merge 3 commits into
v4-spikefrom
alyssamaruyama/stg-2795-make-sure-v3-model-routing-doc-updates-are-covered-in-v4

Conversation

@akeimach

@akeimach akeimach commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

why

Making sure the recently added instructions in #2408 are also present in the v4 docs

what changed

test plan


Summary by cubic

Clarifies v4 model routing in packages/docs/v4/configuration/models.mdx, aligning v4 with STG-2795. Adds a routing table, explains per‑call server-side selection when model is omitted, notes Gateway requires Browserbase-hosted browsers and doesn’t support stopSequences, and expands troubleshooting for missing LLM config, missing Browserbase session or provider key on pinned models, and stop‑sequence errors.

Written for commit db0b5c9. Summary will update on new commits.

Review in cubic

@akeimach
akeimach requested a review from a team as a code owner August 7, 2026 16:03
@changeset-bot

changeset-bot Bot commented Aug 7, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: db0b5c9

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cubic analysis

All reported issues were addressed across 1 file

Linked issue analysis

Linked issue: STG-2795: Make sure v3 model routing doc updates are covered in v4

Status Acceptance criteria Notes
Explain server-side selection when no model is configured (selection happens per call and picks up new models) The diff adds prose clarifying that when no model is configured, Browserbase selects a model server-side on every call and picks up new models as they are added.
Add a table mapping configuration to where inference runs (No model; model no apiKey; model with apiKey; client-side LLM) The diff inserts a table that maps each configuration case to where inference runs, covering the four listed cases.
Document routing semantics: routing is per instance (no ‘auto’ model name) and note about per-call overrides The diff adds a Note stating routing is per instance, there is no "auto" model name, and references per-call overrides.
Warn that Model Gateway rejects stopSequences and recommend pinning model with provider apiKey when needed The diff adds a Warning that Model Gateway rejects stopSequences and suggests pinning a model with provider API key when stopSequences are required.
Add troubleshooting entries for three gateway-related errors (LLM not configured during initialization; model inference requires provider API key or Browserbase session; Gateway does not support stop sequences) with solutions The diff inserts three Accordion troubleshooting entries each describing the error and providing solutions (launch with apiKey, pass model with apiKey, or supply client-side LLM / drop stopSequences, etc.).
Architecture diagram
sequenceDiagram
    participant App as Stagehand SDK
    participant Router as Model Router
    participant Browser as Browser Session
    participant Gateway as Model Gateway
    participant Provider as Provider API

    Note over App,Provider: Model routing decision - set per instance, not per call
    Note over App,Provider: "auto" is not a model name - omit "model" to route via Gateway

    App->>Router: act()/extract()/observe() -> resolveModel(config)
    Router->>Browser: check Browserbase session? (apiKey + session ID)

    alt No model configured + Browserbase session
        Router->>Gateway: route without model field
        Gateway->>Gateway: select model server-side per call (picks up new models)
        Gateway-->>App: inference result
    else No model configured + local browser
        Router-->>App: error "an LLM was not configured" (first call, not create())
    else model without apiKey + Browserbase session
        Router->>Gateway: route with pinned model
        Note over Gateway: NEW: stopSequences rejected by Gateway
        Gateway-->>App: inference result
    else model without apiKey + local browser
        Router-->>App: error "model inference requires a provider API key..."
    else model with apiKey
        Router->>Provider: route straight to provider (bypass Gateway)
        Provider-->>App: inference result (stopSequences supported)
    else client-side LLM callback
        App->>App: run custom LLM callback locally (bypass Gateway)
        App-->>App: inference result
    end
Loading

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread packages/docs/v4/configuration/models.mdx Outdated

@filip-michalsky filip-michalsky left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some small adjustments needed otherwise the errors enum is a nice touch!

When no model is configured, Stagehand routes inference through Model Gateway without a `model` field and Browserbase selects one automatically. An explicit model without a provider-specific API key still routes through Model Gateway, but pins that model instead.
When no model is configured, Stagehand routes inference through Model Gateway without a `model` field and Browserbase selects one automatically. Selection happens server-side on every call, so your code never pins a model name and picks up new models as Browserbase adds them.

What you pass decides where a call goes:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the "auto" model name is accepted by the Stagehand V3 api service please see here https://github.com/browserbase/core/blob/main/apps/stagehand-api-v3/lib/auto-mode/auto-model-router.ts#L8

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

talked offline, v4 is different from v3 api so this is still valid

</Note>

<Note>
Routing is per instance, not per call. There is no `"auto"` model name: every `modelName` carries a provider prefix, so to route a call you omit `model` rather than naming a router. A [per-call override](#per-call-model-overrides) pins that call to a specific model.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmmm... what does it mean "per instance"? we do currently route per call-
mode: "auto"
stagehand.act -> auto

next step in the trajectory
stagehand.extract -> auto

etc.

currently, each step on trajectory fed into act/extract/observe is auto-routed.

There is a very nuanced interplay with caching as well...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated this a bit for clarity. But this is a stagehand "instance" if that clears things up!

const stagehand = await Stagehand.create({
  browser,
  model: {
    modelName: "openai/gpt-5.4-mini",
    apiKey: process.env.OPENAI_API_KEY,
  },
});

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 1 file (changes from recent commits).

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread packages/docs/v4/configuration/models.mdx Outdated
Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants