mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-08 22:21:35 +00:00
fix utils
This commit is contained in:
parent
b125f944eb
commit
4bafb26c12
2 changed files with 20 additions and 1 deletions
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue