Skip to content

fix(count_tokens): return a 400 naming Anthropic blocks the OpenAI and Gemini count can't convert - #46772

Merged
mateo-berri merged 30 commits into
mainfrom
litellm_count_tokens_reject_unconvertible_blocks
Oct 16, 2026
Merged

mateo-berri merged 30 commits into
mainfrom
litellm_count_tokens_reject_unconvertible_blocks

Conversation

@mateo-berri

@mateo-berri mateo-berri commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

TLDR

Problem this solves:

  • /v1/messages/count_tokens skipped blocks it couldn't convert for OpenAI and Gemini, so counts came back low with a 200

How it solves it:

Intentional product change: these bodies now get a 400, with no setting to turn it off

User Flow

Before

  1. They POST https://litellm-domain/v1/messages/count_tokens with a text block, a text-source document and a search_result
  2. They get 200 with an input_tokens that only covers the text

After

  1. They send the same request
  2. They get 400 saying "count_tokens can't convert these content blocks for this model, so the count would leave them out: document with a text source, search_result"

Linear ticket

Resolves LIT-9586

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have added meaningful tests
  • The handful of test files covering my change pass locally, e.g. uv run pytest tests/unit/<your_test_file>.py -v. Leave the suites (make test-unit-*, make test-unit) to CI: it finishes in ~15 minutes where a laptop takes an hour or more
  • My PR passes all required CI/CD checks (e.g., lint, schema.d.ts sync check, etc.)
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • Every automated review on my PR's latest commit has finished, and I have addressed or replied to each of its findings before requesting a maintainer review

Delays in PR merge?

If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).

Design decisions

The ticket asks for a 400 as a new default with no opt-out. Tying it to drop_params would bring back the silent low count, so the 400 holds either way

The check runs after the history rewrites /v1/messages applies, so a replayed web search flattened to text passes. A block passes when both conversions send it: text, image, document and tool_result in user turns, plus text, tool_use, thinking and redacted_thinking in assistant turns. Inside a tool_result only text, image and document pass, so a nested search_result or tool_reference is named too. Unit tests check these lists against what both counters send. Only /v1/messages/count_tokens checks. Its errors now use the Anthropic shape /v1/messages returns, not {"detail": ...}, so a provider 429 there changes shape too

Screenshots / Proof of Fix

Both legs sent the same bodies with curl to a --num_workers 2 proxy on real gpt-6.1-sol and gemini-4-argon calls. Count is POST /v1/messages/count_tokens, and Billed is the usage of the same body on POST /v1/messages. Everything is in the gist

Deployment Case Before After Expected Billed
OpenAI unconvertible blocks 58 HTTP 400 HTTP 400 58
same body without those blocks 58 58 unchanged 58
same content as text blocks 463 463 unchanged 463
replayed web search 339 339 unchanged 339
Vertex unconvertible blocks 60 HTTP 400 HTTP 400 96
same body without those blocks 60 60 unchanged 96
same content as text blocks 466 466 unchanged 500
replayed web search 345 345 unchanged 376
AI Studio unconvertible blocks 96 HTTP 400 HTTP 400 96
same body without those blocks 96 96 unchanged 96
same content as text blocks 500 500 unchanged 500
replayed web search 377 377 unchanged 377

Before, the body with a search_result block and a text-source document block counted the same as that body with both blocks removed (58, 60, 96), so they added nothing, while the same content as text blocks counts 463, 466 and 500. After, each count answers 400 in Anthropic's error shape and names both blocks. The two controls and a replayed web search count the same as before, and so do the other 19 cases in the full runs

Deployments are openai/gpt-6.1-sol, vertex_ai/gemini-4-argon and gemini/gemini-4-argon. Each unconvertible.count.json holds a system string and a user turn with a text block, a text-source document block and a search_result block. Before ran at dba86be, this PR's merge base on main

Before (dba86be)

Vertex, unconvertible blocks

  1. Count the request

    $ curl -s -X POST http://localhost:$PORT/v1/messages/count_tokens -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' --data-binary @count-tokens-vertex-gemini.unconvertible.count.json
    {"input_tokens":60}
    [HTTP 200]
    
  2. Send the same body for real and read its usage

    $ curl -s -X POST http://localhost:$PORT/v1/messages -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' --data-binary @count-tokens-vertex-gemini.unconvertible.messages.json
    {"id":"uY_RauGOOKGN998P8OmF6As","type":"message","role":"assistant","model":"count-tokens-vertex-gemini","stop_sequence":null,"usage":{"input_tokens":96,"output_tokens":5},"content":[{"type":"text","text":"OK"}],"stop_reason":"end_turn","stop_details":null}
    [HTTP 200]
    
Other cases

OpenAI, unconvertible blocks

  1. Count the request

    $ curl -s -X POST http://localhost:$PORT/v1/messages/count_tokens -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' --data-binary @count-tokens-openai.unconvertible.count.json
    {"input_tokens":58}
    [HTTP 200]
    
  2. Send the same body for real and read its usage

    $ curl -s -X POST http://localhost:$PORT/v1/messages -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' --data-binary @count-tokens-openai.unconvertible.messages.json
    {"id":"resp_bGl0ZWxsbTpjdXN0b21fbGxtX3Byb3ZpZGVyOm9wZW5haTttb2RlbF9pZDowZDc0M2VmYTk3MmRhMzViMWQyMjQ2NGZhZmI3MjM1OWM1YTFkZmUxN2NkMjViZjMyODRlYmRiOWVlZmZkNDlmO3Jlc3BvbnNlX2lkOnJlc3BfMGI1ZjA1OWQ5ZjkxNGEzYzAwNmFkMThmOTVmNmE0ODdkMDlkMjc3MzIyMjZiNzA0MmU=","type":"message","role":"assistant","model":"count-tokens-openai","stop_sequence":null,"usage":{"input_tokens":58,"output_tokens":17},"content":[{"type":"redacted_thinking","data":"litellm_encrypted_reasoning:<trimmed>"},{"type":"text","text":"OK"}],"stop_reason":"end_turn","stop_details":null}
    [HTTP 200]
    

OpenAI, same body without those blocks

  1. Count the request

    $ curl -s -X POST http://localhost:$PORT/v1/messages/count_tokens -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' --data-binary @count-tokens-openai.unconvertible_removed.count.json
    {"input_tokens":58}
    [HTTP 200]
    
  2. Send the same body for real and read its usage

    $ curl -s -X POST http://localhost:$PORT/v1/messages -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' --data-binary @count-tokens-openai.unconvertible_removed.messages.json
    {"id":"resp_bGl0ZWxsbTpjdXN0b21fbGxtX3Byb3ZpZGVyOm9wZW5haTttb2RlbF9pZDowZDc0M2VmYTk3MmRhMzViMWQyMjQ2NGZhZmI3MjM1OWM1YTFkZmUxN2NkMjViZjMyODRlYmRiOWVlZmZkNDlmO3Jlc3BvbnNlX2lkOnJlc3BfMDA5NGJlZGMwNjczMGJjMzAwNmFkMThmOGZiYjQ4ODdkMGE1ZTRlNjM4YTUyYWFmYzU=","type":"message","role":"assistant","model":"count-tokens-openai","stop_sequence":null,"usage":{"input_tokens":58,"output_tokens":5},"content":[{"type":"text","text":"OK"}],"stop_reason":"end_turn","stop_details":null}
    [HTTP 200]
    

OpenAI, same content as text blocks

  1. Count the request

    $ curl -s -X POST http://localhost:$PORT/v1/messages/count_tokens -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' --data-binary @count-tokens-openai.unconvertible_as_text.count.json
    {"input_tokens":463}
    [HTTP 200]
    
  2. Send the same body for real and read its usage

    $ curl -s -X POST http://localhost:$PORT/v1/messages -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' --data-binary @count-tokens-openai.unconvertible_as_text.messages.json
    {"id":"resp_bGl0ZWxsbTpjdXN0b21fbGxtX3Byb3ZpZGVyOm9wZW5haTttb2RlbF9pZDowZDc0M2VmYTk3MmRhMzViMWQyMjQ2NGZhZmI3MjM1OWM1YTFkZmUxN2NkMjViZjMyODRlYmRiOWVlZmZkNDlmO3Jlc3BvbnNlX2lkOnJlc3BfMDgxNjBhMmUwNjgyZTMzZDAwNmFkMThmOTE3ZDE4ODdkMDlmMTNlNzlmNmYxOTViYjM=","type":"message","role":"assistant","model":"count-tokens-openai","stop_sequence":null,"usage":{"input_tokens":463,"output_tokens":5},"content":[{"type":"text","text":"OK"}],"stop_reason":"end_turn","stop_details":null}
    [HTTP 200]
    

OpenAI, replayed web search

  1. Count the request

    $ curl -s -X POST http://localhost:$PORT/v1/messages/count_tokens -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' --data-binary @count-tokens-openai.ws_history.count.json
    {"input_tokens":339}
    [HTTP 200]
    
  2. Send the same body for real and read its usage

    $ curl -s -X POST http://localhost:$PORT/v1/messages -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' --data-binary @count-tokens-openai.ws_history.messages.json
    {"id":"resp_bGl0ZWxsbTpjdXN0b21fbGxtX3Byb3ZpZGVyOm9wZW5haTttb2RlbF9pZDowZDc0M2VmYTk3MmRhMzViMWQyMjQ2NGZhZmI3MjM1OWM1YTFkZmUxN2NkMjViZjMyODRlYmRiOWVlZmZkNDlmO3Jlc3BvbnNlX2lkOnJlc3BfMDEwZDc3ZTI2ZDQxM2RkNzAwNmFkMThmOTNhZDU4ODdkMGE4MmU5YjUxZmI5MjVhMWQ=","type":"message","role":"assistant","model":"count-tokens-openai","stop_sequence":null,"usage":{"input_tokens":339,"output_tokens":5},"content":[{"type":"text","text":"OK"}],"stop_reason":"end_turn","stop_details":null}
    [HTTP 200]
    

Vertex, same body without those blocks

  1. Count the request

    $ curl -s -X POST http://localhost:$PORT/v1/messages/count_tokens -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' --data-binary @count-tokens-vertex-gemini.unconvertible_removed.count.json
    {"input_tokens":60}
    [HTTP 200]
    
  2. Send the same body for real and read its usage

    $ curl -s -X POST http://localhost:$PORT/v1/messages -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' --data-binary @count-tokens-vertex-gemini.unconvertible_removed.messages.json
    {"id":"sI_RarC5KsXf998P1Yr9sA8","type":"message","role":"assistant","model":"count-tokens-vertex-gemini","stop_sequence":null,"usage":{"input_tokens":96,"output_tokens":5},"content":[{"type":"text","text":"OK"}],"stop_reason":"end_turn","stop_details":null}
    [HTTP 200]
    

Vertex, same content as text blocks

  1. Count the request

    $ curl -s -X POST http://localhost:$PORT/v1/messages/count_tokens -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' --data-binary @count-tokens-vertex-gemini.unconvertible_as_text.count.json
    {"input_tokens":466}
    [HTTP 200]
    
  2. Send the same body for real and read its usage

    $ curl -s -X POST http://localhost:$PORT/v1/messages -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' --data-binary @count-tokens-vertex-gemini.unconvertible_as_text.messages.json
    {"id":"s4_RaruDIfW74_UPzpjrgAg","type":"message","role":"assistant","model":"count-tokens-vertex-gemini","stop_sequence":null,"usage":{"input_tokens":500,"output_tokens":5},"content":[{"type":"text","text":"OK"}],"stop_reason":"end_turn","stop_details":null}
    [HTTP 200]
    

Vertex, replayed web search

  1. Count the request

    $ curl -s -X POST http://localhost:$PORT/v1/messages/count_tokens -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' --data-binary @count-tokens-vertex-gemini.ws_history.count.json
    {"input_tokens":345}
    [HTTP 200]
    
  2. Send the same body for real and read its usage

    $ curl -s -X POST http://localhost:$PORT/v1/messages -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' --data-binary @count-tokens-vertex-gemini.ws_history.messages.json
    {"id":"to_RaujnOPW74_UPzpjrgAg","type":"message","role":"assistant","model":"count-tokens-vertex-gemini","stop_sequence":null,"usage":{"input_tokens":376,"output_tokens":5},"content":[{"type":"text","text":"OK"}],"stop_reason":"end_turn","stop_details":null}
    [HTTP 200]
    

AI Studio, unconvertible blocks

  1. Count the request

    $ curl -s -X POST http://localhost:$PORT/v1/messages/count_tokens -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' --data-binary @count-tokens-aistudio-gemini.unconvertible.count.json
    {"input_tokens":96}
    [HTTP 200]
    
  2. Send the same body for real and read its usage

    $ curl -s -X POST http://localhost:$PORT/v1/messages -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' --data-binary @count-tokens-aistudio-gemini.unconvertible.messages.json
    {"id":"ZJDRaqTgG5my1MkP7pGI8Ak","type":"message","role":"assistant","model":"count-tokens-aistudio-gemini","stop_sequence":null,"usage":{"input_tokens":96,"output_tokens":5},"content":[{"type":"text","text":"OK"}],"stop_reason":"end_turn","stop_details":null}
    [HTTP 200]
    

AI Studio, same body without those blocks

  1. Count the request

    $ curl -s -X POST http://localhost:$PORT/v1/messages/count_tokens -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' --data-binary @count-tokens-aistudio-gemini.unconvertible_removed.count.json
    {"input_tokens":96}
    [HTTP 200]
    
  2. Send the same body for real and read its usage

    $ curl -s -X POST http://localhost:$PORT/v1/messages -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' --data-binary @count-tokens-aistudio-gemini.unconvertible_removed.messages.json
    {"id":"94_Raqq1NcK1_PUPw72TQQ","type":"message","role":"assistant","model":"count-tokens-aistudio-gemini","stop_sequence":null,"usage":{"input_tokens":96,"output_tokens":5},"content":[{"type":"text","text":"OK"}],"stop_reason":"end_turn","stop_details":null}
    [HTTP 200]
    

AI Studio, same content as text blocks

  1. Count the request

    $ curl -s -X POST http://localhost:$PORT/v1/messages/count_tokens -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' --data-binary @count-tokens-aistudio-gemini.unconvertible_as_text.count.json
    {"input_tokens":500}
    [HTTP 200]
    
  2. Send the same body for real and read its usage

    $ curl -s -X POST http://localhost:$PORT/v1/messages -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' --data-binary @count-tokens-aistudio-gemini.unconvertible_as_text.messages.json
    {"id":"-Y_RavWINZLN_uMPzLWRmQw","type":"message","role":"assistant","model":"count-tokens-aistudio-gemini","stop_sequence":null,"usage":{"input_tokens":500,"output_tokens":5},"content":[{"type":"text","text":"OK"}],"stop_reason":"end_turn","stop_details":null}
    [HTTP 200]
    

AI Studio, replayed web search

  1. Count the request

    $ curl -s -X POST http://localhost:$PORT/v1/messages/count_tokens -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' --data-binary @count-tokens-aistudio-gemini.ws_history.count.json
    {"input_tokens":377}
    [HTTP 200]
    
  2. Send the same body for real and read its usage

    $ curl -s -X POST http://localhost:$PORT/v1/messages -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' --data-binary @count-tokens-aistudio-gemini.ws_history.messages.json
    {"id":"DJDRaszkMYek_uMP98TF4A4","type":"message","role":"assistant","model":"count-tokens-aistudio-gemini","stop_sequence":null,"usage":{"input_tokens":377,"output_tokens":5},"content":[{"type":"text","text":"OK"}],"stop_reason":"end_turn","stop_details":null}
    [HTTP 200]
    

After (610d0a7)

Vertex, unconvertible blocks

  1. Count the request

    $ curl -s -X POST http://localhost:$PORT/v1/messages/count_tokens -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' --data-binary @count-tokens-vertex-gemini.unconvertible.count.json
    {"type":"error","error":{"type":"invalid_request_error","message":"count_tokens can't convert these content blocks for this model, so the count would leave them out: document with a text source, search_result"}}
    [HTTP 400]
    
  2. Send the same body for real and read its usage

    $ curl -s -X POST http://localhost:$PORT/v1/messages -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' --data-binary @count-tokens-vertex-gemini.unconvertible.messages.json
    {"id":"4pTRapDCBriZ9LsPrvjQ8Aw","type":"message","role":"assistant","model":"count-tokens-vertex-gemini","stop_sequence":null,"usage":{"input_tokens":96,"output_tokens":5},"content":[{"type":"text","text":"OK"}],"stop_reason":"end_turn","stop_details":null}
    [HTTP 200]
    
Other cases

OpenAI, unconvertible blocks

  1. Count the request

    $ curl -s -X POST http://localhost:$PORT/v1/messages/count_tokens -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' --data-binary @count-tokens-openai.unconvertible.count.json
    {"type":"error","error":{"type":"invalid_request_error","message":"count_tokens can't convert these content blocks for this model, so the count would leave them out: document with a text source, search_result"}}
    [HTTP 400]
    
  2. Send the same body for real and read its usage

    $ curl -s -X POST http://localhost:$PORT/v1/messages -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' --data-binary @count-tokens-openai.unconvertible.messages.json
    {"id":"resp_bGl0ZWxsbTpjdXN0b21fbGxtX3Byb3ZpZGVyOm9wZW5haTttb2RlbF9pZDowZDc0M2VmYTk3MmRhMzViMWQyMjQ2NGZhZmI3MjM1OWM1YTFkZmUxN2NkMjViZjMyODRlYmRiOWVlZmZkNDlmO3Jlc3BvbnNlX2lkOnJlc3BfMDlmYTRhMDI5MTFlZGI4ODAwNmFkMTk0YzUyZGM0ODdkMGI1Yjk4NDA2NDQ4YjEwZjQ=","type":"message","role":"assistant","model":"count-tokens-openai","stop_sequence":null,"usage":{"input_tokens":58,"output_tokens":5},"content":[{"type":"text","text":"OK"}],"stop_reason":"end_turn","stop_details":null}
    [HTTP 200]
    

OpenAI, same body without those blocks

  1. Count the request

    $ curl -s -X POST http://localhost:$PORT/v1/messages/count_tokens -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' --data-binary @count-tokens-openai.unconvertible_removed.count.json
    {"input_tokens":58}
    [HTTP 200]
    
  2. Send the same body for real and read its usage

    $ curl -s -X POST http://localhost:$PORT/v1/messages -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' --data-binary @count-tokens-openai.unconvertible_removed.messages.json
    {"id":"resp_bGl0ZWxsbTpjdXN0b21fbGxtX3Byb3ZpZGVyOm9wZW5haTttb2RlbF9pZDowZDc0M2VmYTk3MmRhMzViMWQyMjQ2NGZhZmI3MjM1OWM1YTFkZmUxN2NkMjViZjMyODRlYmRiOWVlZmZkNDlmO3Jlc3BvbnNlX2lkOnJlc3BfMGNlYjVhNzcwNzFlMTAxNTAwNmFkMTk0YzAzNWEwODdkMGJlYjA1YjY3YzI2YWNlNWQ=","type":"message","role":"assistant","model":"count-tokens-openai","stop_sequence":null,"usage":{"input_tokens":58,"output_tokens":16},"content":[{"type":"redacted_thinking","data":"litellm_encrypted_reasoning:<trimmed>"},{"type":"text","text":"OK"}],"stop_reason":"end_turn","stop_details":null}
    [HTTP 200]
    

OpenAI, same content as text blocks

  1. Count the request

    $ curl -s -X POST http://localhost:$PORT/v1/messages/count_tokens -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' --data-binary @count-tokens-openai.unconvertible_as_text.count.json
    {"input_tokens":463}
    [HTTP 200]
    
  2. Send the same body for real and read its usage

    $ curl -s -X POST http://localhost:$PORT/v1/messages -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' --data-binary @count-tokens-openai.unconvertible_as_text.messages.json
    {"id":"resp_bGl0ZWxsbTpjdXN0b21fbGxtX3Byb3ZpZGVyOm9wZW5haTttb2RlbF9pZDowZDc0M2VmYTk3MmRhMzViMWQyMjQ2NGZhZmI3MjM1OWM1YTFkZmUxN2NkMjViZjMyODRlYmRiOWVlZmZkNDlmO3Jlc3BvbnNlX2lkOnJlc3BfMDFiOGI5NGMyMjVjOGNhZDAwNmFkMTk0YzFkZWZjODdkMGJjOWIyOWVmZjdmODkzZGM=","type":"message","role":"assistant","model":"count-tokens-openai","stop_sequence":null,"usage":{"input_tokens":463,"output_tokens":5},"content":[{"type":"text","text":"OK"}],"stop_reason":"end_turn","stop_details":null}
    [HTTP 200]
    

OpenAI, replayed web search

  1. Count the request

    $ curl -s -X POST http://localhost:$PORT/v1/messages/count_tokens -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' --data-binary @count-tokens-openai.ws_history.count.json
    {"input_tokens":339}
    [HTTP 200]
    
  2. Send the same body for real and read its usage

    $ curl -s -X POST http://localhost:$PORT/v1/messages -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' --data-binary @count-tokens-openai.ws_history.messages.json
    {"id":"resp_bGl0ZWxsbTpjdXN0b21fbGxtX3Byb3ZpZGVyOm9wZW5haTttb2RlbF9pZDowZDc0M2VmYTk3MmRhMzViMWQyMjQ2NGZhZmI3MjM1OWM1YTFkZmUxN2NkMjViZjMyODRlYmRiOWVlZmZkNDlmO3Jlc3BvbnNlX2lkOnJlc3BfMDNlZGZiNmE3MzcyNmE0ZTAwNmFkMTk0YzM5NzA0ODdkMGFkMGQ3OTA1ODBmMjM5ZmI=","type":"message","role":"assistant","model":"count-tokens-openai","stop_sequence":null,"usage":{"input_tokens":339,"output_tokens":5},"content":[{"type":"text","text":"OK"}],"stop_reason":"end_turn","stop_details":null}
    [HTTP 200]
    

Vertex, same body without those blocks

  1. Count the request

    $ curl -s -X POST http://localhost:$PORT/v1/messages/count_tokens -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' --data-binary @count-tokens-vertex-gemini.unconvertible_removed.count.json
    {"input_tokens":60}
    [HTTP 200]
    
  2. Send the same body for real and read its usage

    $ curl -s -X POST http://localhost:$PORT/v1/messages -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' --data-binary @count-tokens-vertex-gemini.unconvertible_removed.messages.json
    {"id":"2pTRaqjPB7WX9LsPvvOw2QM","type":"message","role":"assistant","model":"count-tokens-vertex-gemini","stop_sequence":null,"usage":{"input_tokens":96,"output_tokens":5},"content":[{"type":"text","text":"OK"}],"stop_reason":"end_turn","stop_details":null}
    [HTTP 200]
    

Vertex, same content as text blocks

  1. Count the request

    $ curl -s -X POST http://localhost:$PORT/v1/messages/count_tokens -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' --data-binary @count-tokens-vertex-gemini.unconvertible_as_text.count.json
    {"input_tokens":466}
    [HTTP 200]
    
  2. Send the same body for real and read its usage

    $ curl -s -X POST http://localhost:$PORT/v1/messages -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' --data-binary @count-tokens-vertex-gemini.unconvertible_as_text.messages.json
    {"id":"3JTRava0DdeW9LsP6KbXkQY","type":"message","role":"assistant","model":"count-tokens-vertex-gemini","stop_sequence":null,"usage":{"input_tokens":500,"output_tokens":5},"content":[{"type":"text","text":"OK"}],"stop_reason":"end_turn","stop_details":null}
    [HTTP 200]
    

Vertex, replayed web search

  1. Count the request

    $ curl -s -X POST http://localhost:$PORT/v1/messages/count_tokens -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' --data-binary @count-tokens-vertex-gemini.ws_history.count.json
    {"input_tokens":345}
    [HTTP 200]
    
  2. Send the same body for real and read its usage

    $ curl -s -X POST http://localhost:$PORT/v1/messages -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' --data-binary @count-tokens-vertex-gemini.ws_history.messages.json
    {"id":"35TRatqGL-yM9LsPvv_uyAM","type":"message","role":"assistant","model":"count-tokens-vertex-gemini","stop_sequence":null,"usage":{"input_tokens":376,"output_tokens":5},"content":[{"type":"text","text":"OK"}],"stop_reason":"end_turn","stop_details":null}
    [HTTP 200]
    

AI Studio, unconvertible blocks

  1. Count the request

    $ curl -s -X POST http://localhost:$PORT/v1/messages/count_tokens -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' --data-binary @count-tokens-aistudio-gemini.unconvertible.count.json
    {"type":"error","error":{"type":"invalid_request_error","message":"count_tokens can't convert these content blocks for this model, so the count would leave them out: document with a text source, search_result"}}
    [HTTP 400]
    
  2. Send the same body for real and read its usage

    $ curl -s -X POST http://localhost:$PORT/v1/messages -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' --data-binary @count-tokens-aistudio-gemini.unconvertible.messages.json
    {"id":"7ZXRaoWHN8ms1MkPkNbk0Ak","type":"message","role":"assistant","model":"count-tokens-aistudio-gemini","stop_sequence":null,"usage":{"input_tokens":96,"output_tokens":5},"content":[{"type":"text","text":"OK"}],"stop_reason":"end_turn","stop_details":null}
    [HTTP 200]
    

AI Studio, same body without those blocks

  1. Count the request

    $ curl -s -X POST http://localhost:$PORT/v1/messages/count_tokens -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' --data-binary @count-tokens-aistudio-gemini.unconvertible_removed.count.json
    {"input_tokens":96}
    [HTTP 200]
    
  2. Send the same body for real and read its usage

    $ curl -s -X POST http://localhost:$PORT/v1/messages -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' --data-binary @count-tokens-aistudio-gemini.unconvertible_removed.messages.json
    {"id":"zpXRau-vMcCw1MkP5_i76Ak","type":"message","role":"assistant","model":"count-tokens-aistudio-gemini","stop_sequence":null,"usage":{"input_tokens":96,"output_tokens":5},"content":[{"type":"text","text":"OK"}],"stop_reason":"end_turn","stop_details":null}
    [HTTP 200]
    

AI Studio, same content as text blocks

  1. Count the request

    $ curl -s -X POST http://localhost:$PORT/v1/messages/count_tokens -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' --data-binary @count-tokens-aistudio-gemini.unconvertible_as_text.count.json
    {"input_tokens":500}
    [HTTP 200]
    
  2. Send the same body for real and read its usage

    $ curl -s -X POST http://localhost:$PORT/v1/messages -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' --data-binary @count-tokens-aistudio-gemini.unconvertible_as_text.messages.json
    {"id":"3JXRaqrZAY2k1MkPiObM4QY","type":"message","role":"assistant","model":"count-tokens-aistudio-gemini","stop_sequence":null,"usage":{"input_tokens":500,"output_tokens":5},"content":[{"type":"text","text":"OK"}],"stop_reason":"end_turn","stop_details":null}
    [HTTP 200]
    

AI Studio, replayed web search

  1. Count the request

    $ curl -s -X POST http://localhost:$PORT/v1/messages/count_tokens -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' --data-binary @count-tokens-aistudio-gemini.ws_history.count.json
    {"input_tokens":377}
    [HTTP 200]
    
  2. Send the same body for real and read its usage

    $ curl -s -X POST http://localhost:$PORT/v1/messages -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' --data-binary @count-tokens-aistudio-gemini.ws_history.messages.json
    {"id":"65XRaoacJte01MkP_5vlsQo","type":"message","role":"assistant","model":"count-tokens-aistudio-gemini","stop_sequence":null,"usage":{"input_tokens":377,"output_tokens":5},"content":[{"type":"text","text":"OK"}],"stop_reason":"end_turn","stop_details":null}
    [HTTP 200]
    

What surprised the run

  • /v1/messages also bills these bodies without the two blocks, so inference drops them too

Type

🐛 Bug Fix

Caveats (if any)

Severe

  • Counts now 400 on bodies that /v1/messages serves and bills
    • Approved in LIT-9533's decisions, "Fail loudly by default, with no admin setting to bring back the old behavior"
    • LIT-9586 asks for it as a "New default, no opt-out setting"

Final Attestation

  • The tests check the right things, including the edge cases, and regressions in the respective real-world customer use-cases are not possible after this PR

Note

Medium Risk
Intentional breaking change: some bodies that still succeed on /v1/messages will get 400 on count_tokens, and count_tokens error shapes for provider failures now match Anthropic format.

Overview
/v1/messages/count_tokens no longer returns a low input_tokens when OpenAI or Gemini backends would drop Anthropic content blocks during conversion. Those requests now fail with HTTP 400 before any provider countTokens / input_tokens call, listing the blocks that would be omitted (e.g. search_result, document with a text source, nested blocks inside tool_result).

A new convertible_blocks helper walks normalized Anthropic messages and names blocks that neither the chat nor Responses conversion paths would send. OpenAI, Vertex Gemini, and Google AI Studio token counters call this (via unconvertible_messages_error) alongside existing malformed-message checks.

The Anthropic proxy count_tokens route now returns errors in the same Anthropic JSON error envelope as /v1/messages (via _anthropic_error_json_response) instead of raising FastAPI HTTPException with a detail object. Successful counts still return {"input_tokens": ...}.

Reviewed by Cursor Bugbot for commit 610d0a7. Bugbot is set up for automated code reviews on this repo. Configure here.

@mateo-berri

Copy link
Copy Markdown
Contributor Author

@litereview code-review

@litereview

litereview Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

✅ code-review

5/5 · Ready for human review

Scope: full · Full PR review.

No correctness findings.

Checks and execution details
  • Passed · Real testing evidence (required): The rule applies because the PR changes count-token translation under litellm/llms/**: anthropic/pass_through/convertible_blocks.py, openai/responses/count_tokens/token_counter.py, gemini/common_utils.py, vertex_ai/common_utils.py and vertex_ai/count_tokens/context.py.

Integration tests drive the real proxy through POST /v1/messages/count_tokens against owned local protocol peers:

  • test_openai_count_tokens_tools_wire.py::test_messages_count_tokens_rejects_blocks_it_cannot_convert
  • test_vertex_gemini_count_tokens_wire.py::test_count_tokens_rejects_blocks_it_cannot_convert[vertex_ai|gemini]

Both tests assert a 400, the named labels (including search_result inside a tool_result) and wire.drain() == (), which proves no provider call. The rejection happens before any upstream call, so no recorded provider response feeds this assertion. Existing tests in the same files keep the success path covered.

I ran INTEGRATION_WORKERS=2 uv run --frozen python tests/integration/run.py providers &lt;both files> against local Postgres and Redis, and it reported 36 passed.

The PR also links manual E2E evidence (gist) with real openai/gpt-6.1-sol, vertex_ai/gemini-4-argon and gemini/gemini-4-argon calls. Those runs show HTTP 400 after the change and unchanged counts for the control bodies.

  • Passed · Unit tests for changed modules (optional): I ran uv run --frozen pytest tests/unit/llms/anthropic/pass_through/test_convertible_blocks.py tests/unit/proxy/test_proxy_token_counter.py, and it reported 52 passed. These tests compare the convertible and dropped block lists against what the chat-completions adapter, the Responses adapter and gemini_count_contents actually send.

  • Passed · Prior finding history recheck (optional): Both earlier findings are already withdrawn and the head is unchanged.

  • a6c19097…:0 (nested search_result in a tool_result): _tool_result_labels still labels these blocks, and the wire tests assert search_result inside a tool_result.

  • 8d15851d…:0 (OpenAI compaction): the earlier decision was made on this same head, 0dbb5dce. No new code or evidence changes it.

  • Passed · Endpoint error-shape / caller trace (optional): count_request_tokens returns a TokenCountResponse, so token_response.total_tokens in the new else: branch is safe.

When a provider counter returns error=True, _try_provider_token_count raises ProxyException(code=400). The endpoint then renders it with _anthropic_error_json_response, the same envelope /v1/messages uses.

The PR description documents the error-shape change from {"detail": ...} to the Anthropic error shape as intentional.


View review · Reviewed 0dbb5dcea0eb

return f"{block_type} with an untyped source"


def _block_label(block: JsonValue, convertible: frozenset[str]) -> str | None:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Medium · Search results returned inside tool_result still get a silently low count

  1. A client runs a RAG tool and replays its output the usual Anthropic way: a user turn with a tool_result whose content holds a search_result block. The deployment is openai/..., vertex_ai/gemini-... or gemini/....
  2. The client calls POST /v1/messages/count_tokens for that body.
  3. _block_label sees only the top-level tool_result. That type is in the allowed set, so the new check returns no labels and the count proceeds.
  4. Both adapters reduce the nested search_result to an empty tool output ('output': '' for Responses, 'content': '' for chat). The count returns 200 without the search-result text, which is the undercount LIT-9586 asked to turn into a 400.

The PR description says the check reads only top-level blocks. That explains the gap but does not close it. To fix it, run the same labelling over list content inside tool_result blocks. Keep text, tool_reference, and image/document blocks with a valid base64 or url source.

Evidence

Reproducer (uv run python /tmp/r.py at head 856ba4d):

sr = {"type":"search_result","source":"https://example.com/notes","title":"Notes","content":[{"type":"text","text":"The notes say the launch is on Tuesday."}]}
msgs = [{"role":"assistant","content":[{"type":"tool_use","id":"toolu_01","name":"kb","input":{}}]},
        {"role":"user","content":[{"type":"tool_result","tool_use_id":"toolu_01","content":[sr]},{"type":"text","text":"When is launch?"}]}]

Output:

check: None
chat: [... {'role': 'tool', 'tool_call_id': 'toolu_01', 'content': ''}, ...]
resp: [... {'type': 'function_call_output', 'call_id': 'toolu_01', 'output': ''}, ...]

LiteLLMAnthropicMessagesAdapter._tool_result_part keeps only text, image/document and tool_reference parts and returns None for anything else (adapters/transformation.py ~L1324-1341).

translate_messages_to_responses_input keeps only nested text and document items from tool_result content (responses_adapters/transformation.py ~L369-395).

A document with a text source nested in tool_result hits the same gap: _translate_anthropic_document_block_to_file_part returns None for non-base64 and non-url sources.

Latest summary by code-review · View this review · Reviewed 856ba4dfca6f

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 3313dcd. A search_result or text-source document inside a tool_result now gets the 400, with unit and wire tests covering it

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Finding withdrawn

The fix is verified. _content_labels now chains _tool_result_labels, which labels any block inside a tool_result that both adapters would drop. A search_result or a text-source document nested in a tool_result now makes /v1/messages/count_tokens return a 400 instead of a low 200. Valid nested text, tool_reference and base64/url image or document blocks still pass. The OpenAI and Vertex Gemini wire tests now assert the nested label.

Evidence

litellm/llms/anthropic/pass_through/convertible_blocks.py: _TOOL_RESULT_BLOCK_TYPES = {text, image, document, tool_reference}. _tool_result_labels runs _block_label over list content and appends inside a tool_result. _content_labels chains it into each message's labels.

Reproducer output at head 3313dcd:

count_tokens can't convert these content blocks for this model, so the count would leave them out: search_result inside a tool_result
count_tokens can't convert these content blocks for this model, so the count would leave them out: document with a text source inside a tool_result
None   # nested text block
None   # string content

Tests: tests/unit/llms/anthropic/pass_through/test_convertible_blocks.py:108-110, tests/integration/providers/test_openai_count_tokens_tools_wire.py:312 and tests/integration/providers/test_vertex_gemini_count_tokens_wire.py:300 assert the ... inside a tool_result label.

GitHub does not allow this App to resolve this thread. A repository maintainer must do it manually.

Reviewed 3313dcd17d4c · View follow-up

@codecov

codecov Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.66667% with 7 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
.../llms/anthropic/pass_through/convertible_blocks.py 92.75% 5 Missing ⚠️
litellm/llms/gemini/common_utils.py 66.66% 1 Missing ⚠️
litellm/llms/vertex_ai/common_utils.py 66.66% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@mateo-berri

Copy link
Copy Markdown
Contributor Author

@litereview code-review

…nce sends them to OpenAI

Unwrap affinity-encoded reasoning, count the structured-output schema, flatten replayed web search results, join a list system prompt, and answer a message without a role with a 400 before calling OpenAI. messages_format is now internal to the Anthropic count route instead of a public /utils/token_counter field.
…//github.com/BerriAI/litellm into litellm_count_tokens_openai_anthropic_format

# Conflicts:
#	tests/unit/test_count_tokens_public_api.py
…ropic_format' into litellm_count_tokens_gemini_anthropic_format
…llm_count_tokens_reject_unconvertible_blocks
@mateo-berri

Copy link
Copy Markdown
Contributor Author

@litereview code-review

@mateo-berri

Copy link
Copy Markdown
Contributor Author

bugbot run

…ted Any

On Python 3.10 to 3.13 the annotation is evaluated at import, so the proxy failed to start with NameError
…ropic_format' into litellm_count_tokens_gemini_anthropic_format

@cursor cursor Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

@mateo-berri

Copy link
Copy Markdown
Contributor Author

@litereview code-review

@mateo-berri

Copy link
Copy Markdown
Contributor Author

@litereview code-review

else None
)
if malformed_error is not None:
request_error: Final = malformed_error or unconvertible_blocks_error(messages, messages_format)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Medium · OpenAI count_tokens rejects a compaction history that /v1/messages accepts and bills

  1. A client keeps a history with an assistant turn containing a replayed compaction block, for example {"type": "compaction", "content": "Summary of the earlier turns..."}. The model deployment is openai/....
  2. The client sends POST /v1/messages/count_tokens with that body.
  3. OpenAITokenCounter.count_tokens passes the raw messages to unconvertible_blocks_error. That function only applies normalize_native_messages, so the compaction block stays in the history. compaction is missing from the assistant allow-list, so the check labels it.
  4. The count returns 400 with ... would leave them out: compaction, and no provider call happens. /v1/messages serves the same body with a 200. The Responses adapter drops the block on that path too, so the earlier count matched the billed tokens (659 = 659 in the author's gist before this PR). The PR is meant to catch undercounts, and this case had no undercount.

The Gemini paths avoid this case because inference_request_view runs _client_compaction before the check. Only the OpenAI path breaks. The smallest fix is to stop labelling compaction on the OpenAI path, for example by adding it to the assistant set there. Alternatively, run the check on the same view the Responses inference builds.

Evidence

Reproducer at head 0dbb5dc, run in the local uv env with the gist body compaction.count-tokens-openai.count.json (user string / assistant [compaction] / user string):

unconvertible_blocks_error(messages, 'anthropic') -> "count_tokens can't convert these content blocks for this model, so the count would leave them out: compaction"
OpenAITokenCounter().count_tokens(..., messages_format='anthropic') -> status_code=400, same message (no HTTP call made)
inference_request_view(...) then unconvertible_messages_error(...) -> None   # Gemini path: client compaction strips the block first

Real-provider evidence from the author's gist, after_pr1_c6d410b039.txt (before this PR): count-tokens-openai compaction count {"input_tokens":659} [HTTP 200], /v1/messages usage input_tokens: 659. The after-PR runs (after_pr3_c9b14a6a94.txt) do not include the compaction case.

LiteLLMAnthropicToResponsesAPIAdapter._assistant_group_to_input_items returns () for non-thinking and non-tool_use blocks, so /v1/messages sends nothing for compaction on the Responses route (responses_adapters/transformation.py ~L280-296). messages/handler.py:608 routes to that path when no compaction kwarg is set.

_CONVERTIBLE_BLOCK_TYPES['assistant'] = {text, tool_use, thinking, redacted_thinking} in convertible_blocks.py:15 has no compaction entry.

Latest summary by code-review · View this review · Reviewed 0dbb5dcea0eb

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By design. The ticket asks for a 400 naming any block the conversion drops, and the Responses conversion drops compaction, so the count names it

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Finding withdrawn

The reply holds up against the code. My finding said the 400 was wrong because the count of 659 matched the billed 659, so nothing was undercounted. The PR doesn't use that test, though. Its own OpenAI unconvertible blocks row shows a count of 58, a bill of 58 and an intended HTTP 400. The PR rejects blocks whose content /v1/messages silently drops, even when count and bill agree.

compaction falls in that group on the OpenAI path:

  1. /v1/messages sends OpenAI models to LiteLLMMessagesToResponsesAPIHandler when no compaction kwarg is set. That handler never calls apply_client_compaction_block_history, so nothing moves the summary into system.
  2. _assistant_group_to_input_items returns () for a compaction block, so the provider never sees the summary text.
  3. The PR says the check runs after the history rewrites that /v1/messages applies. The Responses route applies no compaction rewrite, so the check correctly names the dropped block.

The Gemini path differs because its inference path does fold the summary into system, and inference_request_view mirrors that rewrite. The OpenAI 400 is consistent with the stated LIT-9586 requirement, so it isn't a defect.

Evidence

Ran at head 0dbb5dc in the local uv env, with history user hi / assistant [{type: compaction, content: 'SUMMARY TEXT'}] / user go on:

LiteLLMAnthropicToResponsesAPIAdapter().translate_messages_to_responses_input(m)
-> [{'type': 'message', 'role': 'user', 'content': [{'type': 'input_text', 'text': 'hi'}]}, {'type': 'message', 'role': 'user', 'content': [{'type': 'input_text', 'text': 'go on'}]}]
unconvertible_blocks_error(m, 'anthropic')
-> "count_tokens can't convert these content blocks for this model, so the count would leave them out: compaction"

The summary text never reaches the Responses input.

litellm/llms/anthropic/pass_through/messages/handler.py:608 routes OpenAI to LiteLLMMessagesToResponsesAPIHandler when kwargs.get("compaction") is None. grep compaction finds no match in responses_adapters/handler.py. apply_client_compaction_block_history is called only from adapters/handler.py (the chat-completions adapter) and from vertex_ai/count_tokens/context.py.

PR description, OpenAI row unconvertible blocks | Before 58 | After HTTP 400 | Expected HTTP 400 | Billed 58. Count and bill matched there, and the PR still rejects the body. The PR also says it 400s on "blocks the conversion drops", with no opt-out (LIT-9586).

GitHub does not allow this App to resolve this thread. A repository maintainer must do it manually.

Reviewed 0dbb5dcea0eb · View follow-up

@mateo-berri

Copy link
Copy Markdown
Contributor Author

@litereview code-review

@mateo-berri

Copy link
Copy Markdown
Contributor Author

bugbot run

@cursor cursor Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

@mateo-berri

Copy link
Copy Markdown
Contributor Author

@greptileai

@greptile-apps

greptile-apps Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no blocking issue was found.

Summary

/v1/messages/count_tokens now returns 400 when OpenAI or Gemini would leave unsupported Anthropic blocks out of the count.

  • OpenAI and Gemini counts name blocks they cannot convert.
  • Count-token failures now use Anthropic’s error shape.

Reviews (2) · Last reviewed commit: "Merge branch 'main' into litellm_count_t..." · Reviewed by Greptile

@mateo-berri

Copy link
Copy Markdown
Contributor Author

@litellm-stampbot

@litellm-stampbot

Copy link
Copy Markdown

litellm-stampbot: risk low

Approved at 0dbb5dc.

Rules (stampbot/risk_rules.yml):

  • low: no rule flagged it

Judge (gpt-6-luna): low, probability of high 0.09 (high at or above 0.75)

  • risk: low (probability of high 0.09)

Pushes do not re-run this check. Comment @litellm-stampbot again to re-check the new head.

@litellm-stampbot litellm-stampbot Bot added the risk:low Small, isolated, low-risk change label Oct 16, 2026

@kerry-berri kerry-berri left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Low risk by rule and by judgement at 0dbb5dc

Base automatically changed from litellm_count_tokens_gemini_anthropic_format to main October 16, 2026 02:32
…ocks

# Conflicts:
#	litellm/llms/gemini/common_utils.py
#	litellm/llms/openai/responses/count_tokens/token_counter.py
#	litellm/llms/vertex_ai/common_utils.py
#	tests/integration/providers/test_openai_count_tokens_tools_wire.py
#	tests/integration/providers/test_vertex_gemini_count_tokens_wire.py
@mateo-berri

Copy link
Copy Markdown
Contributor Author

@greptileai

@codspeed

codspeed Bot commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

⚠️ 1 benchmark spent significant time in system calls

System calls cannot be consistently instrumented, so they are not included in the measure, which understates the real cost. Please switch to the Walltime instrument to accurately measure system calls.

Measurement and system calls

✅ 31 untouched benchmarks


Comparing litellm_count_tokens_reject_unconvertible_blocks (610d0a7) with main (dba86be)

Open in CodSpeed

@mateo-berri

Copy link
Copy Markdown
Contributor Author

bugbot run

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 610d0a7. Configure here.

@mateo-berri
mateo-berri merged commit 79ca820 into main Oct 16, 2026
150 of 152 checks passed
@mateo-berri
mateo-berri deleted the litellm_count_tokens_reject_unconvertible_blocks branch October 16, 2026 03:20
mateo-berri added a commit that referenced this pull request Oct 16, 2026
…overloaded_error

count_tokens errors now use main's top-level Anthropic envelope from #46772, still mapped 503 to 529, and its tests read that envelope
mateo-berri added a commit that referenced this pull request Oct 19, 2026
Keep #43900, #45301, #46121, #46784, #46759, #46767, #46772, #46815, #47057 and #46777. Port only the Gemini prerequisites from #46430.

Remove the deferred Bedrock Mantle behavior and unrelated picks from the final tree. Restore the PDF test provider fixture and deployment, and retain required test imports.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk:low Small, isolated, low-risk change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants