mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-25 18:54:30 +00:00
Proxy: Add x-litellm-call-id
response header
This gives the value of `logging_obj.litellm_call_id` and one particular use of this is to correlate the HTTP response from a request with a trace in an LLM logging tool like Langfuse, Langsmith, etc. For example, if a user in my environment (w/ Langfuse) gets back this in the response headers: ``` x-litellm-call-id: ffcb49e7-bd6e-4e56-9c08-a7243802b26e ``` then they know that they can see the trace for this request in Langfuse by visiting https://langfuse.domain.com/trace/ffcb49e7-bd6e-4e56-9c08-a7243802b26e They can also use this ID to submit scores for this request to the Langfuse scoring API.
This commit is contained in:
parent
aace0b22a3
commit
3a2cb151aa
1 changed files with 6 additions and 0 deletions
|
@ -444,6 +444,7 @@ def _get_pydantic_json_dict(pydantic_obj: BaseModel) -> dict:
|
|||
def get_custom_headers(
|
||||
*,
|
||||
user_api_key_dict: UserAPIKeyAuth,
|
||||
call_id: Optional[str] = None,
|
||||
model_id: Optional[str] = None,
|
||||
cache_key: Optional[str] = None,
|
||||
api_base: Optional[str] = None,
|
||||
|
@ -455,6 +456,7 @@ def get_custom_headers(
|
|||
) -> dict:
|
||||
exclude_values = {"", None}
|
||||
headers = {
|
||||
"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,
|
||||
|
@ -2895,6 +2897,7 @@ async def chat_completion(
|
|||
): # use generate_responses to stream responses
|
||||
custom_headers = get_custom_headers(
|
||||
user_api_key_dict=user_api_key_dict,
|
||||
call_id=logging_obj.litellm_call_id,
|
||||
model_id=model_id,
|
||||
cache_key=cache_key,
|
||||
api_base=api_base,
|
||||
|
@ -2925,6 +2928,7 @@ async def chat_completion(
|
|||
fastapi_response.headers.update(
|
||||
get_custom_headers(
|
||||
user_api_key_dict=user_api_key_dict,
|
||||
call_id=logging_obj.litellm_call_id,
|
||||
model_id=model_id,
|
||||
cache_key=cache_key,
|
||||
api_base=api_base,
|
||||
|
@ -3138,6 +3142,7 @@ async def completion(
|
|||
): # use generate_responses to stream responses
|
||||
custom_headers = get_custom_headers(
|
||||
user_api_key_dict=user_api_key_dict,
|
||||
call_id=logging_obj.litellm_call_id,
|
||||
model_id=model_id,
|
||||
cache_key=cache_key,
|
||||
api_base=api_base,
|
||||
|
@ -3158,6 +3163,7 @@ async def completion(
|
|||
fastapi_response.headers.update(
|
||||
get_custom_headers(
|
||||
user_api_key_dict=user_api_key_dict,
|
||||
call_id=logging_obj.litellm_call_id,
|
||||
model_id=model_id,
|
||||
cache_key=cache_key,
|
||||
api_base=api_base,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue