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]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
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.pyindex 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 astimport asyncioimport json+import uuidfrom base64 import b64encodefrom datetime import datetimefrom typing import Dict, List, Optional, Union@@ -369,8 +370,9 @@ async def pass_through_request( # noqa: PLR0915query_params: Optional[dict] = None,stream: Optional[bool] = None,):+ litellm_call_id = str(uuid.uuid4())+ url: Optional[httpx.URL] = Nonetry:- import uuidfrom litellm.litellm_core_utils.litellm_logging import Loggingfrom 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 objectstart_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: PLR0915type=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: PLR0915type=getattr(e, "type", "None"),param=getattr(e, "param", "None"),code=getattr(e, "status_code", 500),+ headers=custom_headers,)