Repository navigation
fix(bedrock): strip bedrock/ prefix and URL-encode ARNs in get_bedrock_model_id (LIT-3274) - #28551
Conversation
…k_model_id for invoke path
The invoke path (used by /v1/messages → Anthropic SDK / Claude Code) called
get_bedrock_model_id() which, when falling back to the raw model string, did
not strip the 'bedrock/' routing prefix and did not URL-encode ARNs.
For a model like:
bedrock/arn:aws:bedrock:us-east-1:<ACCOUNT>:inference-profile/global.anthropic...
the URL built was:
/model/bedrock/arn:aws:bedrock:…/invoke-with-response-stream ❌
Bedrock returned a JSON error body. LiteLLM's AWSEventStreamDecoder passed
those bytes into botocore's EventStreamBuffer which expects binary event-stream
framing. Checksum validation failed on the JSON prelude (0x223a7b22 == ':{"')
producing a misleading botocore.eventstream.ChecksumMismatch instead of the
actual Bedrock error.
Fix: strip 'bedrock/' (and 'invoke/') routing prefix from model string, then
URL-encode if the result is an ARN — matching what the converse path already
does in converse_handler.py.
Fixes: LIT-3274
|
|
Greptile SummaryThis PR fixes a
Confidence Score: 5/5The change is narrowly scoped to the else-branch of get_bedrock_model_id, and the new ARN early-return path does not affect non-ARN models or the model_id-from-optional-params path. The fix correctly delegates prefix stripping to the existing strip_bedrock_routing_prefix utility, which already handles compound prefixes in one pass. The early return for ARN models bypasses the old invoke/ replace, but that replace was always a no-op for ARNs. The new tests exercise every documented edge case without making real network calls. No files require special attention.
|
| Filename | Overview |
|---|---|
| litellm/llms/bedrock/base_aws_llm.py | Adds routing-prefix stripping and ARN URL-encoding to get_bedrock_model_id; correctly reuses strip_bedrock_routing_prefix to handle compound prefixes, and early-returns before the now-redundant invoke/ replace for ARN models. |
| tests/test_litellm/llms/bedrock/test_base_aws_llm.py | Six new unit tests covering the ARN handling fix; all are pure string/URL construction tests with no network calls, satisfying the mock-only test policy. |
Reviews (4): Last reviewed commit: "fix(bedrock): use strip_bedrock_routing_..." | Re-trigger Greptile
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
@greptile review |
Real Bedrock API call results (reproduction + fix verification)BEFORE fix — broken URLRoot cause confirmed: Bedrock receives malformed URL (extra AFTER fix — correct URLFix confirmed: Correct URL → Bedrock returns HTTP 403 (cross-account IAM, expected for test creds). LiteLLM HTTP error handler catches 4xx before touching
Unit test results |
…fixes
Address greptile review: the original fix used a loop with break, so
bedrock/invoke/arn:... only stripped bedrock/ leaving invoke/arn:...
which is not an ARN → fell through to .replace('invoke/','',1) →
bare unencoded ARN → same malformed-URL bug.
strip_bedrock_routing_prefix() iterates without break, correctly
stripping bedrock/ then invoke/ in sequence. Also adds test case
for the compound-prefix scenario.
|
@greptile review |
1 similar comment
|
@greptile review |
|
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. |
Problem
/v1/messageswith Bedrock inference profile ARNs fails withChecksumMismatch(HTTP 500).Root cause:
get_bedrock_model_id()inbase_aws_llm.pyfalls back to the raw model string whenmodel_idis not set inoptional_params. It did not strip thebedrock/routing prefix or URL-encode ARNs.For
bedrock/arn:aws:bedrock:us-east-1:<ACCT>:inference-profile/global.anthropic...the built URL was:Bedrock returned a JSON error body.
AWSEventStreamDecoderpassed those bytes into botocore'sEventStreamBufferwhich expects binary event-stream framing. Checksum validation failed on the JSON prelude (0x223a7b22 == ':{"') — producing a misleadingChecksumMismatchinstead of the real error.Fix
Strip
bedrock/(andinvoke/) routing prefix, then URL-encode if the result is an ARN — matching what the converse path already does inconverse_handler.py.After fix:
Real AWS call returns HTTP 403 (IAM permission error) instead of
ChecksumMismatch.Tests
5 new unit tests in
TestGetBedrockModelIdArnHandling:bedrock/prefix → stripped + encodedinvoke/prefix stripping still works121/121 pass in bedrock test suite.
Fixes: LIT-3274