[STG-2090] Add Azure Entra model auth support

Merged
MO
4mo ago
+932-51

Why

Support Azure OpenAI Microsoft Entra ID bearer-token auth through the Stagehand model config shape.

What changed

  • Adds an explicit Azure model config branch with auth: { type: "azureEntraId", token } and providerOptions.azure.
  • Adapts Azure Entra auth to the AI SDK Azure tokenProvider option.
  • Bumps @ai-sdk/azure to the v5-compatible release with tokenProvider support.
  • Regenerates the server-v3 OpenAPI spec and adds parser/schema/runtime tests.

Validation

  • pnpm --filter @browserbasehq/stagehand run build:esm
  • pnpm --filter @browserbasehq/stagehand run test:core -- packages/core/dist/esm/tests/unit/llm-provider.test.js packages/core/dist/esm/tests/unit/api-variables-schema.test.js packages/core/dist/esm/tests/unit/public-api/llm-and-agents.test.js
  • pnpm --filter @browserbasehq/stagehand-server-v3 run gen:openapi
  • pnpm --filter @browserbasehq/stagehand-server-v3 run build:esm-tests
  • pnpm --filter @browserbasehq/stagehand-server-v3 run test:server -- packages/server-v3/dist/tests/unit/requestModelConfig.test.js
  • pnpm --filter @browserbasehq/stagehand run typecheck
  • pnpm --filter @browserbasehq/stagehand-server-v3 run typecheck

Summary by cubic

Adds Azure OpenAI Microsoft Entra ID bearer-token auth to Stagehand. Implements STG-2090 and updates types, schemas, and OpenAPI to support the new azure provider.

  • New Features

    • Add provider: "azure" with auth: { type: "azureEntraId", token } and providerOptions.azure (resourceName, baseURL, apiVersion, useDeploymentBasedUrls, headers).
    • Map Entra auth to the @ai-sdk/azure tokenProvider; Azure runs without experimental mode and never sends an API key when provider auth is set.
    • Preserve same-provider non-credential options when overriding credentials (inherit baseURL/headers/providerOptions; strip apiKey/auth) across client and server.
    • Prevent API key fallback when provider auth exists: ignore env/header/base-config keys, keep per-request Azure configs via withModelApiKeyFallback, and reject configs that mix apiKey with Entra auth.
    • Expand public types and Zod schemas (add AgentType: "azure"); regenerate OpenAPI with Azure schemas and normalize the generator output to preserve Azure union branches.
    • Add unit tests for schema validation, AI SDK client options, API client defaults, server request model config parsing, and tokenProvider behavior.
  • Dependencies

    • Bump @ai-sdk/azure to ^2.0.109.