Skip to content

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]

fix(proxy): forward extra_headers in chat

naaa7600cb6b5876802
diff --git a/litellm/completion_extras/litellm_responses_transformation/transformation.py b/litellm/completion_extras/litellm_responses_transformation/transformation.py
index 57bd05124aa..753a94295b3 100644
--- a/litellm/completion_extras/litellm_responses_transformation/transformation.py
+++ b/litellm/completion_extras/litellm_responses_transformation/transformation.py
@@ -329,6 +329,9 @@ class LiteLLMResponsesTransformationHandler(CompletionTransformationBridge):
else:
request_data[key] = value
+ if headers:
+ request_data["extra_headers"] = headers
+
return request_data
@staticmethod
diff --git a/tests/test_litellm/completion_extras/test_litellm_responses_transformation_transformation.py b/tests/test_litellm/completion_extras/test_litellm_responses_transformation_transformation.py
index adbaf219079..57352eafaf1 100644
--- a/tests/test_litellm/completion_extras/test_litellm_responses_transformation_transformation.py
+++ b/tests/test_litellm/completion_extras/test_litellm_responses_transformation_transformation.py
@@ -134,3 +134,25 @@ def test_transform_request_with_response_format():
assert result["text"]["format"]["type"] == "json_schema"
assert result["text"]["format"]["name"] == "person_schema"
assert "schema" in result["text"]["format"]
+
+
+def test_transform_request_includes_extra_headers():
+ """Test that transform_request forwards headers as extra_headers for upstream call."""
+ handler = LiteLLMResponsesTransformationHandler()
+ messages = [{"role": "user", "content": "Hello"}]
+ optional_params = {}
+ litellm_params = {}
+
+ class MockLoggingObj:
+ pass
+
+ headers = {"cf-aig-authorization": "secret-token"}
+ result = handler.transform_request(
+ model="gpt-5-pro",
+ messages=messages,
+ optional_params=optional_params,
+ litellm_params=litellm_params,
+ headers=headers,
+ litellm_logging_obj=MockLoggingObj(),
+ )
+ assert result.get("extra_headers") == headers