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(responses): compare forwarded header names case-insensitively
milan7716e4751942
diff --git a/litellm/responses/utils.py b/litellm/responses/utils.pyindex 096103b3fae..25a355edbc1 100644--- a/litellm/responses/utils.py+++ b/litellm/responses/utils.py@@ -99,10 +99,17 @@ class ResponsesAPIRequestUtils:`forward_client_headers_to_llm_api` is enabled) into `extra_headers`.`extra_headers` wins on conflicts, since it is set explicitly by the caller.+ Header names are compared case-insensitively, as HTTP defines them."""if not client_headers:return extra_headers- return {**client_headers, **(extra_headers or {})}+ if not extra_headers:+ return dict(client_headers)+ explicit_names = frozenset(name.lower() for name in extra_headers)+ return {+ **{name: value for name, value in client_headers.items() if name.lower() not in explicit_names},+ **extra_headers,+ }@staticmethoddef _check_valid_arg(diff --git a/tests/test_litellm/responses/test_responses_api_request_body.py b/tests/test_litellm/responses/test_responses_api_request_body.pyindex 0d067a99b97..1c217d1a67f 100644--- a/tests/test_litellm/responses/test_responses_api_request_body.py+++ b/tests/test_litellm/responses/test_responses_api_request_body.py@@ -304,3 +304,18 @@ async def test_aresponses_merges_client_headers_with_extra_headers():assert request_headers["x-my-new-header"] == "hello-from-client"assert request_headers["x-explicit"] == "from-caller"assert request_headers["x-shared"] == "from-caller"+++async def test_aresponses_client_header_conflict_is_case_insensitive():+ """+ HTTP header names are case-insensitive, so a differently cased client header+ must not survive alongside the explicit `extra_headers` value.+ """+ request_headers = await _aresponses_and_get_request_headers(+ headers={"X-Shared": "from-client"},+ extra_headers={"x-shared": "from-caller"},+ )++ assert [name for name in request_headers if name.lower() == "x-shared"] == ["x-shared"]+ assert request_headers["x-shared"] == "from-caller"