refactor(ai): move credential lowering into providers - #43515
Open
kitlangton wants to merge 1 commit into
Open
Conversation
kitlangton
force-pushed
the
provider-credentials
branch
from
August 19, 2026 21:17
1233a3a to
ea3c38f
Compare
kitlangton
force-pushed
the
provider-credentials
branch
from
August 19, 2026 21:34
ea3c38f to
48ea841
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.
What
This PR follows merged #43513.
Replace the native provider package
model(modelID, settings)boundary withmodel({ 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 | oauthcredential plus structured request defaults. Providers decide whether that credential becomes bearer auth,x-api-key,x-goog-api-key, Azureapi-key, Vertex OAuth, Bedrock bearer auth, or provider-specific ambient/configured auth.Before / After
Before
Core had package-name switches for Anthropic
authToken, VertexaccessToken, and the defaultapiKeypath. That made Core responsible for provider auth semantics and could erase the distinction between API keys and OAuth credentials.After
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.tsdefines the neutral credential algebra, structured model input/defaults, route-default projection, and semanticbearerAuthOption/apiKeyOrBearerAuthOptionhelpers.packages/core/src/model-resolver.tspasses neutral credentials and structured defaults while retaining key configuration overlay, metadata handling, URL interpolation, selection, and refresh.packages/core/src/aisdk-native.tsmaps legacy native descriptors into provider-owned settings without moving auth lowering back into Core.packages/ai/README.md,packages/ai/AGENTS.md, and the tutorial document the ownership boundary and call shape.Scope
HttpApichanges.Testing
cd packages/ai && bun run test test/auth.test.ts test/provider-package.test.ts(24 passed)cd packages/ai && bun typecheckcd packages/core && bun run test test/model-resolver.test.ts test/aisdk-native.test.ts(58 passed)cd packages/core && bun typecheckbun 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 --checkRepository-wide
bun run lintstill exits on the existing octal-escape error inpackages/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]