mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-26 11:14:04 +00:00
feat(pass_through_endpoints.py): return api base on pass-through exception
enables easy debugging on backend api errors
This commit is contained in:
parent
943e036851
commit
532af66bbd
1 changed files with 13 additions and 3 deletions
|
@ -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,
|
||||
)
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue