Skip to content

fix(amazon-bedrock): support inference profile ARNs as model ids#16970

Open
xianjianlf2 wants to merge 1 commit into
vercel:mainfrom
xianjianlf2:fix/bedrock-inference-profile-arn-14117
Open

fix(amazon-bedrock): support inference profile ARNs as model ids#16970
xianjianlf2 wants to merge 1 commit into
vercel:mainfrom
xianjianlf2:fix/bedrock-inference-profile-arn-14117

Conversation

@xianjianlf2

Copy link
Copy Markdown

Background

@ai-sdk/amazon-bedrock can't be used with AWS Bedrock application inference profiles. Passing an inference profile ARN as the model id fails with 400 The provided model identifier is invalid.

The provider builds REST URLs by interpolating the model id with encodeURIComponent(modelId). For a standard id (us.amazon.nova-2-lite-v1:0) that's fine, but an inference profile ARN contains a slash:

arn:aws:bedrock:us-east-1:123456789012:application-inference-profile/abc123xyz

encodeURIComponent turns that / into %2F. Bedrock treats the model id as a greedy path label and expects the slash to stay literal — its own docs show the ARN unencoded in the path, e.g. POST /model/arn:aws:bedrock:us-east-1:111122223333:prompt/PROMPT12345:1/converse (Converse API reference) — so %2F is rejected. (Colons already work either way, which is why standard ids with encoded : succeed.)

Fixes #14117

Summary

  • Add a shared encodeModelId helper that encodes each /-separated segment individually (modelId.split('/').map(encodeURIComponent).join('/')), keeping slashes literal while still percent-encoding every other special character.
  • Use it in all four URL builders that previously called encodeURIComponent(modelId): chat (getUrl), embedding (getUrl), image (getUrl), and the Bedrock-Anthropic buildRequestUrl.
  • Slash-free model ids encode identically to before, so existing behavior is unchanged.

Manual Verification

  • New unit tests for encodeModelId assert that a standard id still percent-encodes its colon (us.amazon.nova-2-lite-v1:0us.amazon.nova-2-lite-v1%3A0) and that an inference profile ARN keeps its slash literal (arn%3Aaws%3A…%3Aapplication-inference-profile/abc123xyz).
  • The full @ai-sdk/amazon-bedrock suite still passes unchanged (410 tests), confirming the swap is behavior-preserving for existing (slash-free) model ids — no request URLs changed for them.
  • pnpm check (oxlint + oxfmt) clean; the package builds with type declarations.
  • The resulting path matches AWS's documented inference-profile URL format (literal /, percent-encoded :).

Checklist

  • All commits are signed (PRs with unsigned commits cannot be merged)
  • Tests have been added / updated (for bug fixes / features)
  • Documentation has been added / updated (for bug fixes / features) — not needed; no public API or docs surface changes
  • A patch changeset for relevant packages has been added (for bug fixes / features - run pnpm changeset in the project root)
  • I have reviewed this pull request (self-review)

Related Issues

Fixes #14117

…cel#14117)

The provider built REST URLs with `encodeURIComponent(modelId)`, which
encodes the `/` in an application inference profile ARN (e.g.
`arn:aws:bedrock:...:application-inference-profile/abc123`) to `%2F`,
making Bedrock reject it with `400 The provided model identifier is
invalid`.

Add a shared `encodeModelId` helper that encodes each `/`-separated
segment individually, keeping slashes literal while still percent-
encoding other characters (e.g. the `:` in an ARN). Use it in the chat,
embedding, image, and Bedrock-Anthropic URL builders. Standard slash-free
model ids encode identically to before, so existing behavior is unchanged.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

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