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
fix(auth_utils): make header comparison case-insensitive (#12950)
sings-to-bees-on-wednesdayseb96fb78bc27
diff --git a/litellm/proxy/auth/auth_utils.py b/litellm/proxy/auth/auth_utils.pyindex 4bef5e0a208..3261d158899 100644--- a/litellm/proxy/auth/auth_utils.py+++ b/litellm/proxy/auth/auth_utils.py@@ -490,9 +490,11 @@ def get_end_user_id_from_request_body(custom_header_name_to_check = general_settings.get(user_id_header_config_key)if custom_header_name_to_check and isinstance(custom_header_name_to_check, str):- user_id_from_header = request_headers.get(custom_header_name_to_check)- if user_id_from_header is not None and user_id_from_header.strip():- return str(user_id_from_header)+ for header_name, header_value in request_headers.items():+ if header_name.lower() == custom_header_name_to_check.lower():+ user_id_from_header = header_value+ if user_id_from_header.strip():+ return str(user_id_from_header)# Check 2: 'user' field in request_body (commonly OpenAI)if "user" in request_body and request_body["user"] is not None:diff --git a/tests/local_testing/test_auth_utils.py b/tests/local_testing/test_auth_utils.pyindex e2ddbca6032..b696eb2199e 100644--- a/tests/local_testing/test_auth_utils.py+++ b/tests/local_testing/test_auth_utils.py@@ -169,6 +169,13 @@ def test_get_end_user_id_from_request_body_always_returns_str():},"header-priority"),+ # Test 12: user_header_name is matched case-insensitively+ (+ {"x-user-id": "lowercase-header-user"},+ {"user_header_name": "X-User-ID"},+ {"user": "body-user-456"},+ "lowercase-header-user"+ ),])def test_get_end_user_id_from_request_body_with_user_header_name(