litellm - 💡(How to fix) Fix [Bug]: Bug Report: Anthropic passthrough response `id` (`msg_...`) mismatches spend log `request_id` [2 pull requests]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Root Cause

  1. Result: No records found, because spend logs store request_id=ffcb49e7-bd6e-4e56-9c08-a7243802b26a.

Fix Action

Fixed

Code Example

curl -X POST "http://localhost:4000/anthropic/v1/messages" \
    -H "Authorization: Bearer sk-1234" \
    -H "Content-Type: application/json" \
    -H "Anthropic-Version: 2023-06-01" \
    -d '{
      "model": "claude-sonnet-4-5-20250929",
      "max_tokens": 10,
      "messages": [{"role": "user", "content": "Hello"}]
    }'

  2. Observe the response body contains "id": "msg_01AbCdEfGhIjKlMnOpQrStUv" (Anthropic's original ID).
  3. The response header contains x-litellm-call-id: ffcb49e7-bd6e-4e56-9c08-a7243802b26a (LiteLLM-generated UUID).
  4. Query spend logs with the response body ID:

  curl "http://localhost:4000/spend/logs?request_id=msg_01AbCdEfGhIjKlMnOpQrStUv"

  5. Result: No records found, because spend logs store request_id=ffcb49e7-bd6e-4e56-9c08-a7243802b26a.

  Expected behavior

  There should be a straightforward way for a client to correlate an Anthropic passthrough response with its spend log entry without relying on reading x-litellm-call-id from response headers.

  Actual behavior

  The id in the response body (msg_...) does not match the request_id in spend logs (UUID), and there is no configuration or mechanism to align them.

  Root cause analysis

  Looking at the code:

  1. litellm/proxy/pass_through_endpoints/pass_through_endpoints.py:699:
  litellm_call_id = str(uuid.uuid4())
  1. litellm_call_id is always auto-generated and ignores any client-provided trace ID.
  2. litellm/proxy/pass_through_endpoints/llm_provider_handlers/anthropic_passthrough_logging_handler.py:167:
  litellm_model_response.id = logging_obj.litellm_call_id
  2. Spend logs are populated with the UUID, not Anthropic's msg_....
  3. The passthrough endpoint does not read x-litellm-call-id from the request headers (unlike the native /chat/completions endpoint which does at common_request_processing.py:906).

  Proposed fix

  Allow clients to pass a custom trace/call ID via the x-litellm-call-id request header on passthrough endpoints, matching the behavior of native endpoints:

  # In litellm/proxy/pass_through_endpoints/pass_through_endpoints.py:699
  litellm_call_id = request.headers.get("x-litellm-call-id", str(uuid.uuid4()))

  This is a minimal, backward-compatible change. If the client does not provide the header, behavior remains unchanged. If provided, the client can correlate the response (via the x-litellm-call-id response header) with the spend log entry.

  Additional context

  - Native /chat/completions already supports reading x-litellm-call-id from request headers (common_request_processing.py:906), so passthrough endpoints are inconsistent.
  - This issue affects any client that logs only the response body id (e.g., standard Anthropic SDK behavior) and later attempts to query spend logs.


### Relevant log output
RAW_BUFFERClick to expand / collapse

Check for existing issues

  • I have searched the existing issues and checked that my issue is not a duplicate.

What happened?

Describe the bug

When calling the Anthropic passthrough endpoint (/anthropic/v1/messages), the response body contains Anthropic's native msg_... ID in the id field. However, the request_id stored in the LiteLLM spend logs is a UUID (litellm_call_id). This makes it impossible for clients to correlate a response with its spend log entry using the response body alone.

Steps to Reproduce

To Reproduce

  1. Send a request to the Anthropic passthrough endpoint:
curl -X POST "http://localhost:4000/anthropic/v1/messages" \
  -H "Authorization: Bearer sk-1234" \
  -H "Content-Type: application/json" \
  -H "Anthropic-Version: 2023-06-01" \
  -d '{
    "model": "claude-sonnet-4-5-20250929",
    "max_tokens": 10,
    "messages": [{"role": "user", "content": "Hello"}]
  }'

2. Observe the response body contains "id": "msg_01AbCdEfGhIjKlMnOpQrStUv" (Anthropic's original ID).
3. The response header contains x-litellm-call-id: ffcb49e7-bd6e-4e56-9c08-a7243802b26a (LiteLLM-generated UUID).
4. Query spend logs with the response body ID:

curl "http://localhost:4000/spend/logs?request_id=msg_01AbCdEfGhIjKlMnOpQrStUv"

5. Result: No records found, because spend logs store request_id=ffcb49e7-bd6e-4e56-9c08-a7243802b26a.

Expected behavior

There should be a straightforward way for a client to correlate an Anthropic passthrough response with its spend log entry without relying on reading x-litellm-call-id from response headers.

Actual behavior

The id in the response body (msg_...) does not match the request_id in spend logs (UUID), and there is no configuration or mechanism to align them.

Root cause analysis

Looking at the code:

1. litellm/proxy/pass_through_endpoints/pass_through_endpoints.py:699:
litellm_call_id = str(uuid.uuid4())
1. litellm_call_id is always auto-generated and ignores any client-provided trace ID.
2. litellm/proxy/pass_through_endpoints/llm_provider_handlers/anthropic_passthrough_logging_handler.py:167:
litellm_model_response.id = logging_obj.litellm_call_id
2. Spend logs are populated with the UUID, not Anthropic's msg_....
3. The passthrough endpoint does not read x-litellm-call-id from the request headers (unlike the native /chat/completions endpoint which does at common_request_processing.py:906).

Proposed fix

Allow clients to pass a custom trace/call ID via the x-litellm-call-id request header on passthrough endpoints, matching the behavior of native endpoints:

# In litellm/proxy/pass_through_endpoints/pass_through_endpoints.py:699
litellm_call_id = request.headers.get("x-litellm-call-id", str(uuid.uuid4()))

This is a minimal, backward-compatible change. If the client does not provide the header, behavior remains unchanged. If provided, the client can correlate the response (via the x-litellm-call-id response header) with the spend log entry.

Additional context

- Native /chat/completions already supports reading x-litellm-call-id from request headers (common_request_processing.py:906), so passthrough endpoints are inconsistent.
- This issue affects any client that logs only the response body id (e.g., standard Anthropic SDK behavior) and later attempts to query spend logs.


### Relevant log output

```shell

What part of LiteLLM is this about?

Proxy

What LiteLLM version are you on ?

v1.84.0,v1.85.0,,,,

Twitter / LinkedIn details

No response

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

litellm - 💡(How to fix) Fix [Bug]: Bug Report: Anthropic passthrough response `id` (`msg_...`) mismatches spend log `request_id` [2 pull requests]