Skip to content

refactor(ai): move credential lowering into providers - #43515

Open
kitlangton wants to merge 1 commit into
v2from
provider-credentials
Open

refactor(ai): move credential lowering into providers#43515
kitlangton wants to merge 1 commit into
v2from
provider-credentials

Conversation

@kitlangton

@kitlangton kitlangton commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

What

This PR follows merged #43513.

Replace the native provider package model(modelID, settings) boundary with model({ id, settings, credential, defaults }). Core continues to select and refresh integration credentials, but native provider packages now own provider-specific auth lowering.

The package boundary carries a neutral key | oauth credential plus structured request defaults. Providers decide whether that credential becomes bearer auth, x-api-key, x-goog-api-key, Azure api-key, Vertex OAuth, Bedrock bearer auth, or provider-specific ambient/configured auth.

Before / After

Before

providerPackage.model(modelID, {
  ...settings,
  apiKey: coreMappedCredential,
  headers,
  body,
  limits,
})

Core had package-name switches for Anthropic authToken, Vertex accessToken, and the default apiKey path. That made Core responsible for provider auth semantics and could erase the distinction between API keys and OAuth credentials.

After

providerPackage.model({
  id: modelID,
  settings,
  credential: {
    type: "oauth",
    accessToken,
  },
  defaults: {
    headers,
    body,
    limits,
  },
})

Core passes the selected credential without interpreting its wire representation. Each provider package lowers it locally, removes competing stale auth headers where necessary, and preserves provider settings or environment fallback when no non-empty selected credential exists.

How

  • packages/ai/src/provider-package.ts defines the neutral credential algebra, structured model input/defaults, route-default projection, and semantic bearerAuthOption / apiKeyOrBearerAuthOption helpers.
  • Native provider entrypoints adopt the structured contract and keep auth behavior local across OpenAI, Anthropic, Google, Azure, Vertex, Bedrock, OpenRouter, xAI, and compatible providers.
  • Anthropic, Google, Azure, and Vertex remove competing key or authorization headers when switching credential modes.
  • Azure consumes key credential configuration for resource/base URL selection while Core retains configuration overlay and credential refresh ownership.
  • Vertex preserves OAuth/ADC and express-key behavior; Bedrock preserves bearer/SigV4 and ambient credential behavior.
  • packages/core/src/model-resolver.ts passes neutral credentials and structured defaults while retaining key configuration overlay, metadata handling, URL interpolation, selection, and refresh.
  • packages/core/src/aisdk-native.ts maps legacy native descriptors into provider-owned settings without moving auth lowering back into Core.
  • Package/type and Core resolver/adapter tests cover credential precedence, empty selected-secret fallback, competing headers, Azure credential configuration, native mappings, and package contract shape.
  • packages/ai/README.md, packages/ai/AGENTS.md, and the tutorial document the ownership boundary and call shape.

Scope

  • Builds on merged refactor(ai): flatten provider request options #43513, which owns flat provider request options.
  • Excludes the stale-document deletion and reference cleanup from docs(ai): remove stale design documents #43512.
  • Leaves credential selection, OAuth refresh, configuration overlay, and provider enablement in Core.
  • Leaves provider-specific auth lowering in native AI provider packages.
  • Leaves Vertex service-account/ADC and Bedrock SigV4 credentials as provider settings rather than forcing them into the neutral OpenCode integration credential algebra.
  • No Protocol or Server HttpApi changes.

Testing

  • cd packages/ai && bun run test test/auth.test.ts test/provider-package.test.ts (24 passed)
  • cd packages/ai && bun typecheck
  • cd packages/core && bun run test test/model-resolver.test.ts test/aisdk-native.test.ts (58 passed)
  • cd packages/core && bun typecheck
  • bun turbo typecheck --concurrency=3 (33/33 tasks passed; also passed in the pre-push hook)
  • bunx prettier --check $(git diff --name-only -- '*.ts' '*.md')
  • bunx oxlint $(git diff --name-only -- '*.ts') (0 errors; warnings only)
  • git diff --check

Repository-wide bun run lint still exits on the existing octal-escape error in packages/session-ui/src/v2/components/prompt-input/index.tsx:163; the changed-file lint has no errors.

Flow

flowchart LR
  Integration[Integration connection] --> Core[Core selects and refreshes credential]
  Catalog[Catalog model and settings] --> Resolver[Core model resolver]
  Core --> Resolver
  Resolver -->|neutral key or oauth credential| Package[Native provider package]
  Resolver -->|structured headers body limits| Package
  Package --> Auth{Provider auth lowering}
  Auth -->|bearer| Bearer[Authorization header]
  Auth -->|provider key| Key[Provider-specific key header]
  Auth -->|ambient or configured| Ambient[ADC or SigV4]
  Package --> Model[Executable LanguageModel]
Loading

@kitlangton
kitlangton force-pushed the provider-credentials branch from 1233a3a to ea3c38f Compare August 19, 2026 21:17
Base automatically changed from flat-provider-options to v2 August 19, 2026 21:32
@kitlangton
kitlangton force-pushed the provider-credentials branch from ea3c38f to 48ea841 Compare August 19, 2026 21:34
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