mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-27 03:34:10 +00:00
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
This commit is contained in:
parent
bc71407c83
commit
45a65d71f3
2 changed files with 17 additions and 3 deletions
|
@ -57,7 +57,9 @@ class ProxyBaseLLMRequestProcessing:
|
||||||
"x-litellm-call-id": call_id,
|
"x-litellm-call-id": call_id,
|
||||||
"x-litellm-model-id": model_id,
|
"x-litellm-model-id": model_id,
|
||||||
"x-litellm-cache-key": cache_key,
|
"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-version": version,
|
||||||
"x-litellm-model-region": model_region,
|
"x-litellm-model-region": model_region,
|
||||||
"x-litellm-response-cost": str(response_cost),
|
"x-litellm-response-cost": str(response_cost),
|
||||||
|
|
|
@ -284,7 +284,9 @@ class HttpPassThroughEndpointHelpers:
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_response_headers(
|
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:
|
) -> dict:
|
||||||
excluded_headers = {"transfer-encoding", "content-encoding"}
|
excluded_headers = {"transfer-encoding", "content-encoding"}
|
||||||
|
|
||||||
|
@ -295,6 +297,8 @@ class HttpPassThroughEndpointHelpers:
|
||||||
}
|
}
|
||||||
if litellm_call_id:
|
if litellm_call_id:
|
||||||
return_headers["x-litellm-call-id"] = litellm_call_id
|
return_headers["x-litellm-call-id"] = litellm_call_id
|
||||||
|
if custom_headers:
|
||||||
|
return_headers.update(custom_headers)
|
||||||
|
|
||||||
return return_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(
|
return Response(
|
||||||
content=content,
|
content=content,
|
||||||
status_code=response.status_code,
|
status_code=response.status_code,
|
||||||
headers=HttpPassThroughEndpointHelpers.get_response_headers(
|
headers=HttpPassThroughEndpointHelpers.get_response_headers(
|
||||||
headers=response.headers,
|
headers=response.headers,
|
||||||
litellm_call_id=litellm_call_id,
|
custom_headers=custom_headers,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue