From 4bafb26c12f090e2190c9246e4f18a108caa277a Mon Sep 17 00:00:00 2001 From: Ishaan Jaffer Date: Wed, 21 Jan 2026 19:03:26 -0800 Subject: [PATCH] fix utils --- litellm/constants.py | 5 +++++ litellm/passthrough/utils.py | 16 +++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/litellm/constants.py b/litellm/constants.py index 13a26c6d0ea..5da0cf1489f 100644 --- a/litellm/constants.py +++ b/litellm/constants.py @@ -1131,6 +1131,11 @@ ALLOWED_VERTEX_AI_PASSTHROUGH_HEADERS = { "content-type", # Required for request body parsing } +# Prefix for headers that should be forwarded to the provider with the prefix stripped +# e.g., 'x-pass-anthropic-beta: value' becomes 'anthropic-beta: value' +# Works for all LLM pass-through endpoints (Vertex AI, Anthropic, Bedrock, etc.) +PASS_THROUGH_HEADER_PREFIX = "x-pass-" + BASE_MCP_ROUTE = "/mcp" BATCH_STATUS_POLL_INTERVAL_SECONDS = int( diff --git a/litellm/passthrough/utils.py b/litellm/passthrough/utils.py index 4bf66d49881..fbbf9cd2581 100644 --- a/litellm/passthrough/utils.py +++ b/litellm/passthrough/utils.py @@ -3,6 +3,8 @@ from urllib.parse import parse_qs import httpx +from litellm.constants import PASS_THROUGH_HEADER_PREFIX + class BasePassthroughUtils: @staticmethod @@ -27,7 +29,11 @@ class BasePassthroughUtils: forward_headers: Optional[bool] = False, ): """ - Helper to forward headers from original request + Helper to forward headers from original request. + + Also handles 'x-pass-' prefixed headers which are always forwarded + with the prefix stripped, regardless of forward_headers setting. + e.g., 'x-pass-anthropic-beta: value' becomes 'anthropic-beta: value' """ if forward_headers is True: # Header We Should NOT forward @@ -36,6 +42,14 @@ class BasePassthroughUtils: # Combine request headers with custom headers headers = {**request_headers, **headers} + + # Always process x-pass- prefixed headers (strip prefix and forward) + for header_name, header_value in request_headers.items(): + if header_name.lower().startswith(PASS_THROUGH_HEADER_PREFIX): + # Strip the 'x-pass-' prefix to get the actual header name + actual_header_name = header_name[len(PASS_THROUGH_HEADER_PREFIX) :] + headers[actual_header_name] = header_value + return headers class CommonUtils: