Skip to content

fix(amazon-bedrock): preserve ARN model IDs unencoded in URL paths#14257

Open
giulio-leone wants to merge 1 commit into
vercel:mainfrom
giulio-leone:fix/bedrock-arn-encoding
Open

fix(amazon-bedrock): preserve ARN model IDs unencoded in URL paths#14257
giulio-leone wants to merge 1 commit into
vercel:mainfrom
giulio-leone:fix/bedrock-arn-encoding

Conversation

@giulio-leone
Copy link
Copy Markdown
Contributor

Summary

Fixes #14117

encodeURIComponent(modelId) breaks inference-profile ARNs because it encodes :%3A and /%2F, producing an invalid URL that Bedrock rejects with "The provided model identifier is invalid".

Changes

  • New utility bedrockEncodeModelId(modelId) — returns the raw ARN when modelId starts with arn:, otherwise falls back to encodeURIComponent.
  • Applied in all four getUrl / buildRequestUrl call sites:
    • bedrock-chat-language-model.ts
    • bedrock-embedding-model.ts
    • bedrock-image-model.ts
    • anthropic/bedrock-anthropic-provider.ts
  • Regression tests in bedrock-encode-model-id.test.ts (5 cases: standard model IDs, application-inference-profile ARNs, cross-region inference-profile ARNs, non-ARN colons, plain IDs).

Before / After

Input Before After
us.amazon.nova-2-lite-v1:0 .../model/us.amazon.nova-2-lite-v1%3A0 .../model/us.amazon.nova-2-lite-v1%3A0
arn:aws:bedrock:us-east-1:123456789012:application-inference-profile/abc .../model/arn%3Aaws%3A... .../model/arn:aws:bedrock:us-east-1:123456789012:application-inference-profile/abc

Inference-profile ARNs (e.g.
arn:aws:bedrock:us-east-1:123456789012:application-inference-profile/abc)
were broken by encodeURIComponent encoding colons and slashes. The
Bedrock REST API requires the literal ARN in the path segment.

Introduce bedrockEncodeModelId() that skips encoding for arn: prefixed
IDs while preserving existing percent-encoding for regular model IDs.

Applied in all four getUrl / buildRequestUrl call sites:
- bedrock-chat-language-model.ts
- bedrock-embedding-model.ts
- bedrock-image-model.ts
- anthropic/bedrock-anthropic-provider.ts

Fixes vercel#14117

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@tigent tigent Bot added ai/provider related to a provider package. Must be assigned together with at least one `provider/*` label bug Something isn't working as documented provider/amazon-bedrock Issues related to the @ai-sdk/amazon-bedrock provider labels Apr 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai/provider related to a provider package. Must be assigned together with at least one `provider/*` label bug Something isn't working as documented provider/amazon-bedrock Issues related to the @ai-sdk/amazon-bedrock provider

Projects

None yet

Development

Successfully merging this pull request may close these issues.

generateText doesn't work with AWS Bedrock application inference profile ARNs

1 participant