Repository navigation
Conversation
BedrockMantleResponsesAPIConfig authenticates with a Bearer token or falls
back to AWS SigV4 when no token is present, but BedrockMantleChatConfig was
Bearer-only. The chat HTTP handler already invokes the signing hook; the chat
config just inherited the no-op default, so the two backends for the same
provider behaved differently and chat-completions users were forced to set a
static key even when IAM-role or default AWS credentials were available.
Factor the Bearer-or-SigV4 logic out of the responses config into a shared
BedrockMantleAuthMixin in bedrock_mantle/common_utils.py and apply it to both
configs. The chat config now takes an injected aws_signer for unit testing,
honors AWS_BEARER_TOKEN_BEDROCK as a Bearer source, and the misleading
BEDROCK_MANTLE_{REGION}_API_KEY claim in its docstring (never read by the code)
is removed.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Greptile SummaryThis PR fixes a bug where
Confidence Score: 5/5Safe to merge — the change is a faithful refactor with no behavioral changes to the responses backend and a well-tested fix to the chat backend. The mixin's sign_request is logically identical to the code it replaced in the responses config; the extraction was verified line-by-line. The chat config now gets the same Bearer-or-SigV4 path it was missing, tested by six targeted unit tests covering every auth branch. No existing tests were weakened, no rules are violated, and all new tests are mock-only. No files require special attention.
|
| Filename | Overview |
|---|---|
| litellm/llms/bedrock_mantle/common_utils.py | New file introducing BedrockMantleAuthMixin with shared Bearer-or-SigV4 sign_request logic and region resolution; faithfully extracted from the responses backend with no behavioral changes. |
| litellm/llms/bedrock_mantle/chat/transformation.py | Adds BedrockMantleAuthMixin to BedrockMantleChatConfig's MRO and introduces init to inject an aws_signer; now has the same SigV4 fallback behavior as the responses backend. |
| litellm/llms/bedrock_mantle/responses/transformation.py | Removes duplicate sign_request and _resolve_region implementations in favor of the shared mixin; logic is preserved verbatim, only re-exported names (_MANTLE_HOST_RE → MANTLE_HOST_RE) changed. |
| tests/test_litellm/llms/bedrock_mantle/test_bedrock_mantle_transformation.py | Adds TestBedrockMantleChatAuth covering Bearer-skips-SigV4, each env-var Bearer source, SigV4 credential-scope from api_base host, and ValueError on missing credentials; all tests use mocks or in-process signing, no real network calls. |
Reviews (2): Last reviewed commit: "style(bedrock_mantle): use X | None over..." | Re-trigger Greptile
Use the X | None annotation form in the new common_utils mixin and the chat config __init__ so the change does not push the repo's UP045 strict-rule total over its ceiling.
|
Thanks for the PR! Triggering Greptile for a code review: |
|
Closing this as the PR was merged. It was done to run internal cicd and to speed up the process. Sorry for the inconvenience and thank you for your contribution! |
Relevant issues
Linear ticket
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
make test-unit@greptileaiand received a Confidence Score of at least 4/5 before requesting a maintainer reviewCI (LiteLLM team)
Branch creation CI run
Link:
CI run for the last commit
Link:
Merge / cherry-pick CI run
Links:
Screenshots / Proof of Fix
Ran a live proxy against real Bedrock Mantle with a chat model that has no
api_keyconfigured, so it must fall back to SigV4 over default AWS credentials (a local AWS SSO profile here, no Bearer token in the environment).dev_config.yaml entry used for the run (not part of this PR):
Response:
{ "id": "chatcmpl-710687e4-6053-42aa-8d64-dd6b8dd7008b", "model": "mantle-gpt-oss-120b", "object": "chat.completion", "choices": [ { "finish_reason": "stop", "index": 0, "message": {"content": "Hello!", "role": "assistant"} } ], "usage": {"completion_tokens": 99, "prompt_tokens": 75, "total_tokens": 174} }The proxy log confirms the outbound request to Mantle was signed with SigV4 (note
X-Amz-Date,X-Amz-Security-Token, and anAuthorizationheader whose masked value begins withAW, i.e.AWS4-HMAC-SHA256, notBearer):Before this change the same config returns an auth error because the chat backend never signs the request and sends no credentials.
Type
🐛 Bug Fix
Changes
BedrockMantleResponsesAPIConfigauthenticates with a Bearer token when one is available and otherwise falls back to AWS SigV4 over the standard credential chain, butBedrockMantleChatConfigwas Bearer-only. The chat HTTP handler already calls thesign_requesthook on the provider config; the chat config simply inherited the no-opBaseConfig.sign_request, so the same provider behaved differently across its two backends and chat-completions users were forced to set a static key even when IAM-role or default AWS credentials were available.This factors the Bearer-or-SigV4 logic out of the responses config into a shared
BedrockMantleAuthMixininlitellm/llms/bedrock_mantle/common_utils.pyand applies it to both configs, so the two paths can never drift apart. The Bearer precedence islitellm_params.api_key, thenBEDROCK_MANTLE_API_KEY, then the standardAWS_BEARER_TOKEN_BEDROCK; with no token it SigV4-signs for servicebedrockwith the region pinned to the already region-resolved request host. The chat config takes an injectedaws_signerso the SigV4 branch is unit-testable with a mock signer instead of monkeypatching.Two pre-existing chat-config inconsistencies are fixed along the way. The chat path now honors
AWS_BEARER_TOKEN_BEDROCKas a Bearer source the way the responses path already did, and the misleadingBEDROCK_MANTLE_{REGION}_API_KEYregion-aware fallback advertised in the chat docstring (which the code never read) is removed.Tests extend
tests/test_litellm/llms/bedrock_mantle/test_bedrock_mantle_transformation.pywith aTestBedrockMantleChatAuthclass covering Bearer-skips-SigV4, theBEDROCK_MANTLE_API_KEYandAWS_BEARER_TOKEN_BEDROCKBearer sources, SigV4 signing with the credential scope resolved from the request host, and a clearValueErrorwhen neither a token nor usable credentials exist. Each case fails against the no-opsign_requestthe chat config inherited before this change.