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): return api base on pass-through exception

Krrish Dholakia532af66bbdb2
diff --git a/litellm/proxy/pass_through_endpoints/pass_through_endpoints.py b/litellm/proxy/pass_through_endpoints/pass_through_endpoints.py
index 63398e553ba..a13b0dc216e 100644
--- a/litellm/proxy/pass_through_endpoints/pass_through_endpoints.py
+++ b/litellm/proxy/pass_through_endpoints/pass_through_endpoints.py
@@ -1,6 +1,7 @@
import ast
import asyncio
import json
+import uuid
from base64 import b64encode
from datetime import datetime
from typing import Dict, List, Optional, Union
@@ -369,8 +370,9 @@ async def pass_through_request( # noqa: PLR0915
query_params: Optional[dict] = None,
stream: Optional[bool] = None,
):
+ litellm_call_id = str(uuid.uuid4())
+ url: Optional[httpx.URL] = None
try:
- import uuid
from litellm.litellm_core_utils.litellm_logging import Logging
from litellm.proxy.proxy_server import proxy_logging_obj
@@ -420,8 +422,6 @@ async def pass_through_request( # noqa: PLR0915
)
async_client = async_client_obj.client
- litellm_call_id = str(uuid.uuid4())
-
# create logging object
start_time = datetime.now()
logging_obj = Logging(
@@ -600,6 +600,7 @@ async def pass_through_request( # noqa: PLR0915
)
)
+ ## CUSTOM HEADERS - `x-litellm-*`
custom_headers = ProxyBaseLLMRequestProcessing.get_custom_headers(
user_api_key_dict=user_api_key_dict,
call_id=litellm_call_id,
@@ -617,6 +618,13 @@ async def pass_through_request( # noqa: PLR0915
),
)
except Exception as e:
+ 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) if url else None,
+ )
verbose_proxy_logger.exception(
"litellm.proxy.proxy_server.pass_through_endpoint(): Exception occured - {}".format(
str(e)
@@ -628,6 +636,7 @@ async def pass_through_request( # noqa: PLR0915
type=getattr(e, "type", "None"),
param=getattr(e, "param", "None"),
code=getattr(e, "status_code", status.HTTP_400_BAD_REQUEST),
+ headers=custom_headers,
)
else:
error_msg = f"{str(e)}"
@@ -636,6 +645,7 @@ async def pass_through_request( # noqa: PLR0915
type=getattr(e, "type", "None"),
param=getattr(e, "param", "None"),
code=getattr(e, "status_code", 500),
+ headers=custom_headers,
)