fix bedrock embeddings - validate env

This commit is contained in:
Ishaan Jaffer 2025-12-13 16:16:30 -08:00
parent 92b72fc759
commit d9794f0811

View file

@ -21,14 +21,18 @@ from .v1_transformation import CohereEmbeddingConfig
def validate_environment(api_key, headers: dict):
headers.update(
{
"Request-Source": "unspecified:litellm",
"accept": "application/json",
"content-type": "application/json",
}
)
if api_key:
# Create a lowercase key lookup to avoid duplicate headers with different cases
# This is important when headers come from AWS signed requests (which use Title-Case)
existing_keys_lower = {k.lower(): k for k in headers.keys()}
# Only add headers if they don't already exist (case-insensitive check)
if "request-source" not in existing_keys_lower:
headers["Request-Source"] = "unspecified:litellm"
if "accept" not in existing_keys_lower:
headers["accept"] = "application/json"
if "content-type" not in existing_keys_lower:
headers["content-type"] = "application/json"
if api_key and "authorization" not in existing_keys_lower:
headers["Authorization"] = f"Bearer {api_key}"
return headers