fix(amazon-bedrock): support inference profile ARNs as model ids#16970
Open
xianjianlf2 wants to merge 1 commit into
Open
fix(amazon-bedrock): support inference profile ARNs as model ids#16970xianjianlf2 wants to merge 1 commit into
xianjianlf2 wants to merge 1 commit into
Conversation
…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>
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.
Background
@ai-sdk/amazon-bedrockcan't be used with AWS Bedrock application inference profiles. Passing an inference profile ARN as the model id fails with400 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:encodeURIComponentturns 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%2Fis rejected. (Colons already work either way, which is why standard ids with encoded:succeed.)Fixes #14117
Summary
encodeModelIdhelper that encodes each/-separated segment individually (modelId.split('/').map(encodeURIComponent).join('/')), keeping slashes literal while still percent-encoding every other special character.encodeURIComponent(modelId): chat (getUrl), embedding (getUrl), image (getUrl), and the Bedrock-AnthropicbuildRequestUrl.Manual Verification
encodeModelIdassert that a standard id still percent-encodes its colon (us.amazon.nova-2-lite-v1:0→us.amazon.nova-2-lite-v1%3A0) and that an inference profile ARN keeps its slash literal (arn%3Aaws%3A…%3Aapplication-inference-profile/abc123xyz).@ai-sdk/amazon-bedrocksuite 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./, percent-encoded:).Checklist
pnpm changesetin the project root)Related Issues
Fixes #14117