Skip to content

fix(core): normalize provider endpoint templates - #41816

Merged
kitlangton merged 3 commits into
v2from
normalize-bedrock-endpoint
Aug 11, 2026
Merged

fix(core): normalize provider endpoint templates#41816
kitlangton merged 3 commits into
v2from
normalize-bedrock-endpoint

Conversation

@kitlangton

@kitlangton kitlangton commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

What

Resolve Bedrock Mantle catalog endpoints from the provider's configured region without teaching the generic model resolver about Bedrock.

This is the adapter-based alternative to #41786 and closes #40075.

Before / After

Before: models.dev supplies Mantle endpoints such as https://bedrock-mantle.${AWS_REGION}.api.aws/openai/v1. With settings.region: "us-west-2" and no AWS_REGION, ModelResolver rejected the intermediate catalog settings before the native Mantle adapter or provider could interpret them.

The regression test failed before the fix with:

Cannot initialize amazon-bedrock/test-model: AWS_REGION is required to resolve the provider endpoint

After: AISDKNative translates the known Mantle placeholder from the effective configured or credential region, preserving model-specific /v1 and /openai/v1 paths. Generic environment expansion and unresolved-variable validation then run on the effective mapped settings before provider loading. Explicit provider configuration therefore wins over the process environment while providers still construct routes from concrete URLs.

How

  • packages/core/src/aisdk-native.ts resolves only the Mantle AWS_REGION placeholder while translating the AI SDK catalog package into the native AI package.
  • packages/core/src/model-resolver.ts maps provider-specific settings first, then performs one-pass generic environment expansion and validation before loading or constructing the provider.
  • Constructed routes receive a final unresolved-variable invariant check for provider-generated endpoints.
  • Opaque third-party AI SDK packages use the same preparation before their loader runs because their wrapper route does not expose the provider's effective endpoint.
  • packages/ai is unchanged; the native Mantle provider continues receiving a concrete baseURL and region.

Scope

  • Generic ${ENV} behavior remains unchanged for other providers.
  • Unknown unresolved variables still fail with UnresolvedProviderVariablesError.
  • This does not add a generalized provider preparation hook or address unrelated models.dev templates.

Testing

  • Before-fix reproduction: cd packages/core && bun run test test/model-resolver.test.ts failed with unresolved AWS_REGION.
  • cd packages/core && bun run test test/model-resolver.test.ts test/aisdk-native.test.ts (47 pass)
  • cd packages/core && bun typecheck
  • Push hook: bun turbo typecheck --concurrency=3 (33 successful)

Flow

flowchart LR
  A[Catalog model and config] --> B[AI SDK native adapter]
  B -->|Mantle template plus region| C[Effective provider settings]
  C --> D[Generic environment expansion]
  D --> E{Variables unresolved?}
  E -->|Yes| F[UnresolvedProviderVariablesError]
  E -->|No| G[Provider constructs route]
  G --> H[Final endpoint invariant]
  H --> I[LanguageModel]
Loading

@kitlangton
kitlangton marked this pull request as ready for review August 11, 2026 19:42
@kitlangton
kitlangton merged commit e333672 into v2 Aug 11, 2026
10 checks passed
@kitlangton
kitlangton deleted the normalize-bedrock-endpoint branch August 11, 2026 19:42
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