fix(bedrock_mantle): wrap all botocore credential errors with both-paths guidance

This commit is contained in:
Kent 2026-06-06 00:06:46 +08:00
parent 2a9f649414
commit f24740d1a4
2 changed files with 33 additions and 2 deletions

View file

@ -16,7 +16,7 @@ BaseAWSLLM._sign_request after the request body is finalized.
import re
from typing import Optional, Tuple
from botocore.exceptions import NoCredentialsError
from botocore.exceptions import BotoCoreError
from litellm.llms.bedrock.base_aws_llm import BaseAWSLLM
from litellm.llms.openai.responses.transformation import OpenAIResponsesAPIConfig
@ -152,7 +152,7 @@ class BedrockMantleResponsesAPIConfig(OpenAIResponsesAPIConfig):
stream=stream,
fake_stream=fake_stream,
)
except NoCredentialsError as e:
except BotoCoreError as e:
raise ValueError(
"Bedrock Mantle auth failed: no Bearer token and no usable AWS "
"credentials. Set BEDROCK_MANTLE_API_KEY (or AWS_BEARER_TOKEN_BEDROCK) "

View file

@ -12,6 +12,7 @@ import sys
sys.path.insert(0, os.path.abspath("../../../../.."))
import pytest
from botocore.exceptions import PartialCredentialsError, ProfileNotFound
import litellm
from litellm.llms.bedrock_mantle.responses.transformation import (
@ -578,6 +579,36 @@ class TestBedrockMantleResponsesSigV4:
assert "Bearer" in msg
assert "SigV4" in msg or "IAM" in msg
@pytest.mark.parametrize(
"cred_error",
[
PartialCredentialsError(provider="env", cred_var="aws_secret_access_key"),
ProfileNotFound(profile="missing-profile"),
],
)
def test_partial_credentials_raises_both_paths(self, monkeypatch, cred_error):
from unittest.mock import MagicMock
from litellm.llms.bedrock.base_aws_llm import BaseAWSLLM
monkeypatch.delenv("BEDROCK_MANTLE_API_KEY", raising=False)
monkeypatch.delenv("AWS_BEARER_TOKEN_BEDROCK", raising=False)
signer = BaseAWSLLM()
signer.get_credentials = MagicMock(side_effect=cred_error)
cfg = BedrockMantleResponsesAPIConfig(aws_signer=signer)
with pytest.raises(ValueError) as exc:
cfg.sign_request(
headers={},
optional_params={"aws_region_name": "us-east-2"},
request_data={"input": "hi"},
api_base="https://bedrock-mantle.us-east-2.api.aws/openai/v1/responses",
api_key=None,
)
msg = str(exc.value)
assert "Bearer" in msg
assert "SigV4" in msg or "IAM" in msg
class TestBedrockMantleResponsesPricing:
def test_gpt_5_5_pricing_and_mode(self, local_cost_map):