1/2 Add gateway concept to protocol - #2438
Open
monadoid wants to merge 4 commits into
Open
Conversation
|
monadoid
marked this pull request as ready for review
July 26, 2026 19:51
monadoid
marked this pull request as draft
July 26, 2026 19:51
monadoid
marked this pull request as ready for review
July 26, 2026 19:52
Contributor
There was a problem hiding this comment.
All reported issues were addressed across 6 files
Architecture diagram
sequenceDiagram
participant Client as Stagehand Client
participant SDK as Stagehand SDK
participant Parser as ModelConfig Parser
participant Gateway as Gateway Dispatcher
participant Provider as Upstream Provider (OpenAI/Anthropic)
participant BbGateway as Browserbase Gateway
Note over Client,Parser: NEW: Model config selection flow
Client->>SDK: startSession({ model: modelConfig })
alt KnownModelConfig (direct)
Client->>SDK: { modelName: "openai/gpt-5.4-mini", apiKey: "sk-..." }
SDK->>Parser: validate(MODEL_CONFIG_SCHEMA)
Parser->>Parser: match KnownModelConfigSchema
Parser-->>SDK: KnownModelConfig { modelName, apiKey, headers? }
SDK->>Gateway: dispatch(modelConfig, apiKey)
Gateway->>Provider: POST /v1/chat/completions (apiKey in header)
Provider-->>Gateway: inference response
Gateway-->>SDK: response
else UnlistedModelConfig (direct, uncataloged)
Client->>SDK: { type: "unlisted", modelName: "openai/gpt-new-preview", apiKey: "sk-..." }
SDK->>Parser: validate(MODEL_CONFIG_SCHEMA)
Parser->>Parser: match UnlistedModelConfigSchema
Parser-->>SDK: UnlistedModelConfig { type, modelName, apiKey }
SDK->>Gateway: dispatch(modelConfig, apiKey)
Gateway->>Provider: POST /v1/chat/completions (apiKey in header)
Provider-->>Gateway: inference response
Gateway-->>SDK: response
else BrowserbaseModelConfig (gateway-managed, cataloged)
Client->>SDK: { modelName: "browserbase/openai/gpt-5.4-mini" }
Note over Client,SDK: NEW: No apiKey needed - Browserbase handles auth/billing
SDK->>Parser: validate(MODEL_CONFIG_SCHEMA)
Parser->>Parser: match BrowserbaseModelConfigSchema
Parser-->>SDK: BrowserbaseModelConfig { modelName }
SDK->>Gateway: dispatch(modelConfig)
Gateway->>BbGateway: POST /v1/chat/completions (Browserbase credentials)
BbGateway->>BbGateway: authorize project, handle billing
BbGateway->>Provider: forward to upstream model
Provider-->>BbGateway: inference response
BbGateway-->>Gateway: response
Gateway-->>SDK: response
else BrowserbaseUnlistedModelConfig (gateway-managed, uncataloged)
Client->>SDK: { type: "unlisted", modelName: "browserbase/openai/gpt-new-preview" }
Note over Client,SDK: NEW: No apiKey, uncataloged model via Browserbase
SDK->>Parser: validate(MODEL_CONFIG_SCHEMA)
Parser->>Parser: match BrowserbaseUnlistedModelConfigSchema
Parser-->>SDK: BrowserbaseUnlistedModelConfig { type, modelName }
SDK->>Gateway: dispatch(modelConfig)
Gateway->>BbGateway: POST /v1/chat/completions (Browserbase credentials)
BbGateway->>BbGateway: authorize project, handle billing
BbGateway->>Provider: forward to uncataloged upstream model
Provider-->>BbGateway: inference response
BbGateway-->>Gateway: response
Gateway-->>SDK: response
else CustomModelConfig (customer endpoint)
Client->>SDK: { modelName: "...", baseURL: "https://custom.endpoint", apiKey: "..." }
SDK->>Parser: validate(MODEL_CONFIG_SCHEMA)
Parser->>Parser: match CustomModelConfigSchema
Parser-->>SDK: CustomModelConfig { modelName, baseURL, apiKey }
SDK->>Gateway: dispatch(modelConfig)
Gateway->>Provider: POST to baseURL/v1/chat/completions (apiKey in header)
Provider-->>Gateway: inference response
Gateway-->>SDK: response
end
SDK-->>Client: session with LLM client
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
monadoid
force-pushed
the
add-explicit-model-gateway-protocol
branch
from
July 27, 2026 20:38
beb241b to
5fba8ca
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Model provider and inference gateway are related but different choices:
For direct inference, Stagehand calls the provider with the caller's provider key. Browserbase is an explicit gateway in front of an upstream provider/model: it authorizes the project and handles billing while the selected upstream model can still be an OpenAI or Anthropic model.
The protocol previously inferred Browserbase routing from a missing provider key and treated model IDs as a closed catalog. Neither belongs in the public contract: routing should be explicit, while a newly released model from an integrated provider should not require a Stagehand release.
What changed
Adds the
browserbase/...namespace for explicit Browserbase gateway inference.Replaces the per-model allowlist with an open, provider-qualified model-name schema. Providers remain a closed set:
Removes the
type: "unlisted"path. Without a global model catalog, an integrated provider's new model ID is the normal direct-provider form.Keeps custom OpenAI-compatible endpoints explicit through
baseURL:Regenerates protocol JSON, exported TypeScript types, and generated Python models.
This PR defines the protocol contract. #2440 implements execution of the direct, Browserbase, and custom-endpoint targets.
Test plan