mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-14 09:03:16 +00:00
fix(bedrock): let explicit AWS keys win over the env bearer token on native Chat Completions
Some checks failed
Cost map pins recheck / rerun-cost-map-guard (push) Has been cancelled
LiteLLM Rust DB / db-queries (push) Has been cancelled
LiteLLM Rust / rust-lint (push) Has been cancelled
LiteLLM Rust / rust-test (push) Has been cancelled
LiteLLM Rust / rust-wheel (push) Has been cancelled
Terraform Modules / fmt, validate, test (aws) (push) Has been cancelled
Terraform Modules / fmt, validate, test (gcp) (push) Has been cancelled
Terraform Provider / gofmt, vet, build, test (push) Has been cancelled
Terraform Provider / Provider endpoints vs proxy OpenAPI schema (push) Has been cancelled
Some checks failed
Cost map pins recheck / rerun-cost-map-guard (push) Has been cancelled
LiteLLM Rust DB / db-queries (push) Has been cancelled
LiteLLM Rust / rust-lint (push) Has been cancelled
LiteLLM Rust / rust-test (push) Has been cancelled
LiteLLM Rust / rust-wheel (push) Has been cancelled
Terraform Modules / fmt, validate, test (aws) (push) Has been cancelled
Terraform Modules / fmt, validate, test (gcp) (push) Has been cancelled
Terraform Provider / gofmt, vet, build, test (push) Has been cancelled
Terraform Provider / Provider endpoints vs proxy OpenAPI schema (push) Has been cancelled
This commit is contained in:
parent
2a40f78acc
commit
33196c985b
2 changed files with 32 additions and 1 deletions
|
|
@ -47,6 +47,7 @@ from litellm.llms.bedrock.common_utils import (
|
|||
)
|
||||
from litellm.llms.openai.chat.gpt_transformation import OpenAIChatCompletionStreamingHandler
|
||||
from litellm.llms.openai_like.chat.transformation import OpenAILikeChatConfig
|
||||
from litellm.types.llms.bedrock import AwsAuthParams
|
||||
from litellm.types.llms.openai import AllMessageValues
|
||||
from litellm.types.utils import Choices, ModelResponse, ModelResponseStream
|
||||
|
||||
|
|
@ -355,7 +356,7 @@ class AmazonBedrockRuntimeChatCompletionsConfig(OpenAILikeChatConfig):
|
|||
messages=messages,
|
||||
optional_params=optional_params,
|
||||
litellm_params=litellm_params,
|
||||
api_key=bedrock_bearer_token(api_key),
|
||||
api_key=bedrock_bearer_token(api_key, AwsAuthParams.model_validate(optional_params)),
|
||||
api_base=api_base,
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -550,6 +550,36 @@ def test_bearer_api_key_is_sent_as_the_authorization_header(monkeypatch):
|
|||
assert headers["Authorization"] == "Bearer bedrock-api-key"
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"auth_kwargs, authorization_prefix",
|
||||
[
|
||||
(
|
||||
{
|
||||
"aws_access_key_id": SIGV4_PARAMS["aws_access_key_id"],
|
||||
"aws_secret_access_key": SIGV4_PARAMS["aws_secret_access_key"],
|
||||
},
|
||||
f"AWS4-HMAC-SHA256 Credential={SIGV4_PARAMS['aws_access_key_id']}/",
|
||||
),
|
||||
({}, "Bearer env-bedrock-token"),
|
||||
],
|
||||
ids=["explicit-keys-sign-sigv4", "no-keys-use-env-token"],
|
||||
)
|
||||
def test_explicit_aws_keys_win_over_the_env_bearer_token(
|
||||
local_cost_map, fake_aws_env, monkeypatch, auth_kwargs, authorization_prefix
|
||||
):
|
||||
monkeypatch.setenv("AWS_BEARER_TOKEN_BEDROCK", "env-bedrock-token")
|
||||
requests, client = _recording_client(json=_chat_completion_json("ok", "us.xai.grok-4.6"))
|
||||
litellm.completion(
|
||||
model="bedrock/chat_completions/us.xai.grok-4.6",
|
||||
messages=[{"role": "user", "content": "hello"}],
|
||||
client=client,
|
||||
**auth_kwargs,
|
||||
)
|
||||
|
||||
assert len(requests) == 1
|
||||
assert requests[0].headers["Authorization"].startswith(authorization_prefix), requests[0].headers
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"request_params, expected_route",
|
||||
[
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue