Skip to content

2/2 Implement explicit model gateway - #2440

Open
monadoid wants to merge 5 commits into
add-explicit-model-gateway-protocolfrom
implement-model-gateway
Open

2/2 Implement explicit model gateway#2440
monadoid wants to merge 5 commits into
add-explicit-model-gateway-protocolfrom
implement-model-gateway

Conversation

@monadoid

@monadoid monadoid commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

Why

#2438 makes model routing explicit in the protocol. This PR implements that contract in the runtime.

Model IDs from integrated providers are intentionally open: openai/gpt-future-preview is valid direct-provider input without a Stagehand catalog update. The runtime still validates the stable configuration choices it owns: direct credentials, Browserbase gateway selection, and custom endpoint configuration.

What changed

  • Adds one server-side resolver with three execution targets:

    openai/gpt-future-preview
      → direct provider inference
    
    browserbase/openai/gpt-future-preview
      → Browserbase gateway → openai/gpt-future-preview
    
    { baseURL, modelName }
      → OpenAI-compatible endpoint
    
  • Dispatches on the resolved target instead of treating a missing provider API key as Browserbase routing.

  • Adds the Browserbase gateway client, which:

    • derives the regional Stagehand API URL;
    • authenticates with the Browserbase API key and session ID;
    • forwards the upstream provider-qualified model name unchanged.
  • Implements the OpenAI-compatible endpoint path.

  • Updates direct-provider adapters to forward an open provider model ID.

  • Removes all runtime handling of type: "unlisted".

Test plan

  • Focused schema, resolver, gateway-dispatch, and runtime-state tests pass.
  • Gateway behavior is covered with mocked transport and real request construction.
  • Live Browserbase gateway coverage remains an opt-in integration test because it requires dedicated credentials and a deployed endpoint.

@changeset-bot

changeset-bot Bot commented Jul 26, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 5800c9e

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

@monadoid monadoid changed the title Implement model gateway Implement explicit model gateway Jul 26, 2026
@monadoid
monadoid force-pushed the implement-model-gateway branch from d2b2604 to 7f253fa Compare July 26, 2026 20:01

@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.

Review completed against the latest diff

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

Re-trigger cubic

Comment thread packages/server/llm/gatewayClient.ts
Comment thread packages/sdk-python/src/stagehand/_generated/models.py Outdated
Comment thread packages/sdk-python/src/stagehand/_generated/models.py
Comment thread packages/server/services/llmService.ts
Comment thread packages/server/llm/openAiCompatibleClient.ts
Comment thread packages/server/controllers/stagehandController.ts
Comment thread packages/server/services/extractService.ts
Comment thread packages/server/services/observeService.ts
Comment thread packages/server/llm/aiSdkClient.ts
Comment thread packages/server/llm/gatewayClient.ts
@monadoid
monadoid force-pushed the implement-model-gateway branch from 7f253fa to 63fbb89 Compare July 27, 2026 20:38
@monadoid
monadoid force-pushed the add-explicit-model-gateway-protocol branch from beb241b to 5fba8ca Compare July 27, 2026 20:38
@monadoid monadoid changed the title Implement explicit model gateway 2/2 Implement explicit model gateway Jul 28, 2026

@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.

1 issue found across 15 files (changes from recent commits).

Confidence score: 4/5

  • In packages/sdk-python/src/stagehand/client_models.py, the Stagehand(...) constructor now throws a raw Pydantic extra-field error when callers pass model_api_key or model_headers for Browserbase gateway models, which can break previously working client initialization with an opaque message—add explicit handling that rejects or ignores these fields with a clear SDK-level error/migration hint.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="packages/sdk-python/src/stagehand/client_models.py">

<violation number="1" location="packages/sdk-python/src/stagehand/client_models.py:161">
P3: Constructing `Stagehand(model="browserbase/...", model_api_key=...)` or passing `model_headers` now raises a raw Pydantic extra-field validation error. Browserbase gateway models have no per-model connection fields; reject those options explicitly with the SDK's argument-validation path (or otherwise handle them) before expanding `connection`.</violation>
</file>

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

Re-trigger cubic

if base_url is None:
if model.startswith("browserbase/"):
return ModelConfig(
root=BrowserbaseModelConfig.model_validate({

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.

P3: Constructing Stagehand(model="browserbase/...", model_api_key=...) or passing model_headers now raises a raw Pydantic extra-field validation error. Browserbase gateway models have no per-model connection fields; reject those options explicitly with the SDK's argument-validation path (or otherwise handle them) before expanding connection.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/sdk-python/src/stagehand/client_models.py, line 161:

<comment>Constructing `Stagehand(model="browserbase/...", model_api_key=...)` or passing `model_headers` now raises a raw Pydantic extra-field validation error. Browserbase gateway models have no per-model connection fields; reject those options explicitly with the SDK's argument-validation path (or otherwise handle them) before expanding `connection`.</comment>

<file context>
@@ -155,6 +156,13 @@ def _model_config(
     if base_url is None:
+        if model.startswith("browserbase/"):
+            return ModelConfig(
+                root=BrowserbaseModelConfig.model_validate({
+                    "model_name": model,
+                    **connection,
</file context>

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.

1 participant