feat(core): support modelName "auto" when using the Stagehand API
Why
Passing model: "auto" failed at the constructor with:
ERROR: No known environment variable for provider 'auto'
followed by an UnsupportedModelError, because Stagehand always resolved a provider API key and built a local LLM client β even when all inference runs server-side through the Stagehand API.
What changed
model: "auto" is now accepted in the constructor and in per-primitive (act/extract/observe) model overrides when running through the Stagehand API (env: "BROWSERBASE", disableAPI: false, experimental: false). The API resolves "auto" server-side.
modelUtils.ts: newAUTO_MODEL_NAMEconstant +isAutoModel()helper.v3.tsconstructor: for"auto", skip provider API-key lookup and local client creation; throw a clearStagehandInvalidArgumentErrorwhen the API won't be used (LOCAL env,disableAPI: true, orexperimental: true).v3.tsresolveLlmClient: per-call"auto"overrides no-op onto the default client in API mode and throw the same clear error otherwise.v3.tsact(): local act-cache replay is skipped for"auto"sessions β there is no local client for self-heal; the server-side cache still applies.v3.tsinit(): if the API reportsavailable: false,"auto"has no local fallback β the just-created session is ended best-effort and a clearStagehandInitError(with sessionId) is thrown instead of failing later with an undefined-client TypeError.api.tsprepareModelConfig:"auto"never inherits the default model's provider config or API key (the server picks the provider); explicit per-call options still pass through.
Agent/CUA mode is intentionally out of scope.
Known limits (intentional, kept surgical)
middlewareon a per-call{ modelName: "auto" }override is inert β consistent with middleware being documented local-only and already inert in API mode for concrete models.- The public
llmClient!: LLMClientfield isundefinedfor"auto"sessions; tightening that type ripples across the public surface and is left for a follow-up.
Tests
- New
tests/unit/auto-model.test.ts(10 tests): constructor accept/reject matrix (string + object form), per-call resolution guard, and wire-level assertions that"auto"payloads carry no inherited API key. - Full core unit suite: 869 passed; the 4
flowlogger-eventstorefailures reproduce on cleanmain(pre-existing, unrelated). - Typecheck, eslint, and prettier clean.
π€ Generated with Claude Code
Summary by cubic
Enables model: "auto" in @browserbasehq/stagehand when using the Stagehand API, delegating model selection to the server and avoiding local provider keys. Outside API mode, "auto" now fails fast with clear errors.
- New Features
- Accept
"auto"in the constructor and per-call overrides only in API mode (env: "BROWSERBASE",disableAPI: false,experimental: false). - No local LLM client or provider API key; the API selects the provider and payloads donβt inherit API keys.
- Clear errors:
StagehandInvalidArgumentErrorwhen not in API mode or when a customllmClientis supplied;StagehandInitErrorif the API is unavailable. On"auto"init failure, only end sessions created by this init and leave caller-suppliedbrowserbaseSessionIDsessions untouched. - Per-call
"auto"reuses the default client in API mode; explicit options pass through. Local act-cache and agent-cache replay are disabled for"auto"sessions.
- Accept