Skip to content

fix(bedrock_mantle): add SigV4 fallback to chat completions auth - #30693

Closed
6matt wants to merge 2 commits into
BerriAI:litellm_internal_stagingfrom
6matt:litellm_bedrock_mantle_chat_sigv4
Closed

6matt wants to merge 2 commits into
BerriAI:litellm_internal_stagingfrom
6matt:litellm_bedrock_mantle_chat_sigv4

Conversation

@6matt

@6matt 6matt commented Jun 17, 2026 •

Copy link
Copy Markdown
Contributor

Relevant issues

Linear ticket

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have added meaningful tests
  • My PR passes all unit tests on make test-unit
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • I have requested a Greptile review by commenting @greptileai and received a Confidence Score of at least 4/5 before requesting a maintainer review

CI (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_key configured, 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):

  - model_name: mantle-gpt-oss-120b
    litellm_params:
      model: bedrock_mantle/openai.gpt-oss-120b
      aws_region_name: us-east-1
AWS_PROFILE=... AWS_REGION=us-east-1 python litellm/proxy/proxy_cli.py \
  --config litellm/proxy/dev_config.yaml --detailed_debug 2>&1 | tee litellm.log
curl -sS http://localhost:4000/v1/chat/completions \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer sk-1234' \
  -d '{"model": "mantle-gpt-oss-120b", "messages": [{"role": "user", "content": "Say hello in exactly one short sentence."}]}'

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 an Authorization header whose masked value begins with AW, i.e. AWS4-HMAC-SHA256, not Bearer):

POST Request Sent from LiteLLM:
curl -X POST \
https://bedrock-mantle.us-east-1.api.aws/v1/chat/completions \
-H 'Content-Type: application/json' -H 'X-Amz-Date: 20260617T224704Z' -H 'X-Amz-Security-Token: IQ****w=' -H 'Authorization: AW****ec' \
-d '{'model': 'openai.gpt-oss-120b', 'messages': [{'role': 'user', 'content': 'Say hello in exactly one short sentence.'}], 'stream': False}'

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

BedrockMantleResponsesAPIConfig authenticates with a Bearer token when one is available and otherwise falls back to AWS SigV4 over the standard credential chain, but BedrockMantleChatConfig was Bearer-only. The chat HTTP handler already calls the sign_request hook on the provider config; the chat config simply inherited the no-op BaseConfig.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 BedrockMantleAuthMixin in litellm/llms/bedrock_mantle/common_utils.py and applies it to both configs, so the two paths can never drift apart. The Bearer precedence is litellm_params.api_key, then BEDROCK_MANTLE_API_KEY, then the standard AWS_BEARER_TOKEN_BEDROCK; with no token it SigV4-signs for service bedrock with the region pinned to the already region-resolved request host. The chat config takes an injected aws_signer so 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_BEDROCK as a Bearer source the way the responses path already did, and the misleading BEDROCK_MANTLE_{REGION}_API_KEY region-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.py with a TestBedrockMantleChatAuth class covering Bearer-skips-SigV4, the BEDROCK_MANTLE_API_KEY and AWS_BEARER_TOKEN_BEDROCK Bearer sources, SigV4 signing with the credential scope resolved from the request host, and a clear ValueError when neither a token nor usable credentials exist. Each case fails against the no-op sign_request the chat config inherited before this change.

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

codecov Bot commented Jun 17, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@greptile-apps

greptile-apps Bot commented Jun 17, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a bug where BedrockMantleChatConfig never signed requests with SigV4, forcing users to supply a static Bearer token even when IAM-role or default AWS credentials were available — unlike the responses backend, which already had Bearer-or-SigV4 fallback. The fix factors the shared auth logic into a new BedrockMantleAuthMixin in common_utils.py and applies it to both config classes so the two backends can never drift apart again.

  • common_utils.py introduces BedrockMantleAuthMixin with a single sign_request implementation (Bearer-first, SigV4 fallback) and a shared _resolve_region helper; the extracted logic is byte-for-byte identical to what was previously in the responses backend only.
  • BedrockMantleChatConfig gains BedrockMantleAuthMixin in its MRO and an __init__ that accepts an injectable aws_signer for unit testing without monkeypatching.
  • Six new unit tests cover every auth branch for the chat path (Bearer via arg/env vars, SigV4 with credential scope resolved from the api_base host, and clear ValueError on missing credentials); all tests are pure in-process, consistent with the no-network-calls rule for this test directory.

Confidence Score: 5/5

Safe 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.

Important Files Changed

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.
@Sameerlite

Copy link
Copy Markdown
Contributor

Thanks for the PR! Triggering Greptile for a code review:

@greptileai

@Sameerlite

Copy link
Copy Markdown
Contributor

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!

@Sameerlite Sameerlite closed this Jun 18, 2026
@laiweihwa laiweihwa mentioned this pull request Jun 27, 2026
9 of 13 tasks
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.

2 participants