litellm/litellm/proxy/google_endpoints
tavren27 36c7f10c84
fix(proxy): answer x-litellm-call-id on every token count response (#51037)
* fix(proxy): answer x-litellm-call-id on every token count response

The token count log line names a litellm_call_id, but count responses
never carried it, so a client that sent no id of its own could not find
its count's log line. Every count route (Anthropic Messages, Responses
input_tokens, Gemini countTokens, Bedrock count-tokens, and
/utils/token_counter) now answers the id on success and on errors, and
a crash answers the JSON 500 the Anthropic and Gemini routes already used.

* fix(proxy): keep the gateway's crash answers on count routes and stamp Responses opt-in bodies

A crash on /utils/token_counter or /v1/responses/input_tokens goes back to the
gateway's generic 500, or 503 when the database is down, now with the
x-litellm-call-id header. Responses count rejections carry error.litellm_call_id
when include_call_id_in_error_body is on

* test(proxy): count through count_request_tokens in the token counter loop tests

The token_counter route now also takes the response it sets x-litellm-call-id on, so these tests call the shared count function they exercise

* fix(proxy): keep a count crash's own exception and log pre-count Responses failures

The call id now reaches the crash handler through request.state instead of a wrapper exception, so logs and Sentry see the error the count raised. A Responses count that fails before counting writes its count line for any error, so its header names a line

* fix(proxy): keep the token counter's injected args out of its API docs

Tests the opt-in error body id on an Anthropic count the proxy rejects before counting

* fix(proxy): keep a count route's own HTTP error when adding the call id

The wrapper raised a new HTTPException with the same status, detail and headers, so a subclass lost its type and error tracking saw a new exception. It now adds the header to the original and raises it again

---------

Co-authored-by: mateo-berri <277851410+mateo-berri@users.noreply.github.com>
2026-11-11 22:26:47 +00:00
..
agents_endpoints.py fix(gemini)!: accept Google's current Managed Agents fields on create and interactions (#48750) 2026-10-28 12:37:59 -07:00
endpoints.py fix(proxy): answer x-litellm-call-id on every token count response (#51037) 2026-11-11 22:26:47 +00:00