The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
refactor(bedrock): freeze the SSE-KMS header and key-source collections
mateo-berri6b2ac7cc5b79
diff --git a/litellm/llms/bedrock/common_utils.py b/litellm/llms/bedrock/common_utils.pyindex c5ef78b44f3..d18cb7d8734 100644--- a/litellm/llms/bedrock/common_utils.py+++ b/litellm/llms/bedrock/common_utils.py@@ -1314,11 +1314,11 @@ def resolve_s3_encryption_key_id(Precedence: `s3_encryption_key_id` in litellm_params, then optional_params(client-side / request params), then the AWS_S3_ENCRYPTION_KEY_ID env var."""- for source in (litellm_params, optional_params or {}):- value = source.get("s3_encryption_key_id")- if isinstance(value, str) and value:- return value- return get_secret_str("AWS_S3_ENCRYPTION_KEY_ID")+ candidates: Final = tuple(+ source.get("s3_encryption_key_id") for source in (litellm_params, optional_params) if source is not None+ )+ explicit: Final = next((value for value in candidates if isinstance(value, str) and value), None)+ return explicit or get_secret_str("AWS_S3_ENCRYPTION_KEY_ID")class CommonBatchFilesUtils:diff --git a/litellm/llms/bedrock/files/transformation.py b/litellm/llms/bedrock/files/transformation.pyindex b4c4a270bd7..728fd02f001 100644--- a/litellm/llms/bedrock/files/transformation.py+++ b/litellm/llms/bedrock/files/transformation.py@@ -788,20 +788,24 @@ class BedrockFilesConfig(BaseAWSLLM, BaseFilesConfig):# Prepare headers with required S3 headers (same as s3_v2.py)sse_headers: Final = (+ MappingProxyType(+ {+ "x-amz-server-side-encryption": "aws:kms",+ "x-amz-server-side-encryption-aws-kms-key-id": s3_encryption_key_id,+ }+ )+ if s3_encryption_key_id+ else MappingProxyType({})+ )+ request_headers: Final = MappingProxyType({- "x-amz-server-side-encryption": "aws:kms",- "x-amz-server-side-encryption-aws-kms-key-id": s3_encryption_key_id,+ "Content-Type": "application/json", # JSONL files are JSON content+ "x-amz-content-sha256": content_hash, # REQUIRED by S3+ "Content-Language": "en",+ "Cache-Control": "private, immutable, max-age=31536000, s-maxage=0",+ **sse_headers,}- if s3_encryption_key_id- else {})- request_headers: Final = {- "Content-Type": "application/json", # JSONL files are JSON content- "x-amz-content-sha256": content_hash, # REQUIRED by S3- "Content-Language": "en",- "Cache-Control": "private, immutable, max-age=31536000, s-maxage=0",- **sse_headers,- }# Use requests.Request to prepare the request (same pattern as s3_v2.py)req: Final = requests.Request("PUT", api_base, data=content, headers=request_headers)