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]

feat(pass_through_endpoints.py): support returning api-base on pass-through endpoints

Krrish Dholakia943e03685135
diff --git a/litellm/proxy/common_request_processing.py b/litellm/proxy/common_request_processing.py
index 7f131efb043..fcc13509ceb 100644
--- a/litellm/proxy/common_request_processing.py
+++ b/litellm/proxy/common_request_processing.py
@@ -57,7 +57,9 @@ class ProxyBaseLLMRequestProcessing:
"x-litellm-call-id": call_id,
"x-litellm-model-id": model_id,
"x-litellm-cache-key": cache_key,
- "x-litellm-model-api-base": api_base,
+ "x-litellm-model-api-base": (
+ api_base.split("?")[0] if api_base else None
+ ), # don't include query params, risk of leaking sensitive info
"x-litellm-version": version,
"x-litellm-model-region": model_region,
"x-litellm-response-cost": str(response_cost),
diff --git a/litellm/proxy/pass_through_endpoints/pass_through_endpoints.py b/litellm/proxy/pass_through_endpoints/pass_through_endpoints.py
index b13d614678a..63398e553ba 100644
--- a/litellm/proxy/pass_through_endpoints/pass_through_endpoints.py
+++ b/litellm/proxy/pass_through_endpoints/pass_through_endpoints.py
@@ -284,7 +284,9 @@ class HttpPassThroughEndpointHelpers:
@staticmethod
def get_response_headers(
- headers: httpx.Headers, litellm_call_id: Optional[str] = None
+ headers: httpx.Headers,
+ litellm_call_id: Optional[str] = None,
+ custom_headers: Optional[dict] = None,
) -> dict:
excluded_headers = {"transfer-encoding", "content-encoding"}
@@ -295,6 +297,8 @@ class HttpPassThroughEndpointHelpers:
}
if litellm_call_id:
return_headers["x-litellm-call-id"] = litellm_call_id
+ if custom_headers:
+ return_headers.update(custom_headers)
return return_headers
@@ -596,12 +600,20 @@ async def pass_through_request( # noqa: PLR0915
)
)
+ custom_headers = ProxyBaseLLMRequestProcessing.get_custom_headers(
+ user_api_key_dict=user_api_key_dict,
+ call_id=litellm_call_id,
+ model_id=None,
+ cache_key=None,
+ api_base=str(url._uri_reference),
+ )
+
return Response(
content=content,
status_code=response.status_code,
headers=HttpPassThroughEndpointHelpers.get_response_headers(
headers=response.headers,
- litellm_call_id=litellm_call_id,
+ custom_headers=custom_headers,
),
)
except Exception as e: