From 45a65d71f33140888927f1f9f59107bb5ceaa1ce Mon Sep 17 00:00:00 2001 From: Krrish Dholakia Date: Thu, 20 Mar 2025 20:11:49 -0700 Subject: [PATCH] feat(pass_through_endpoints.py): support returning api-base on pass-through endpoints Make it easier to debug what the api base sent to provider was --- litellm/proxy/common_request_processing.py | 4 +++- .../pass_through_endpoints.py | 16 ++++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/litellm/proxy/common_request_processing.py b/litellm/proxy/common_request_processing.py index 7f131efb04..fcc13509ce 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 b13d614678..63398e553b 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: