Skip to content

fix(messages): answer 400 for a non-string user or system text block and keep count_tokens in step with inference (lts/1.108.x) - #54227

Merged
mateo-berri merged 9 commits into
BerriAI:lts/1.108.xfrom
edvinsq:litellm_messages_non_string_text_400_lts
Nov 25, 2026
Merged

mateo-berri merged 9 commits into
BerriAI:lts/1.108.xfrom
edvinsq:litellm_messages_non_string_text_400_lts

Conversation

@edvinsq

@edvinsq edvinsq commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Handwritten 1-3 sentence description

Backport of #54165 to lts/1.108.x. A null or numeric text block in a user turn or the system prompt used to be dropped silently, sent to the provider, or crash with a 500, and count_tokens disagreed with inference. Now both routes answer a 400 naming the field, or drop the block when drop params is on

Details

TLDR

Problem this solves:

  • /v1/messages silently drops null or numeric user text and answers 200
  • count_tokens answers 400 for that body, so the routes disagree
  • A null-only body with drop_params gets an error naming the wrong cause
  • A null system text gets a 500 on MiniMax and DeepSeek and reaches others as sent
  • Found with a scripted body, not a customer report

How it solves it:

  • Both routes answer 400 naming the field unless drop_params is on
  • drop_params drops the block on both routes
  • Empty text blocks are still stripped for Claude Code
  • Covers every provider, before any provider call

Intentional product change: a non-string user or system text block now answers 400 instead of being dropped unless drop_params is on, as Anthropic's API does. count_tokens now counts the messages inference sends, so it answers 200 for empty text blocks it refused

Every commit of #54165 but the Rust-test-only 8d5be2b938e maps to a commit here.

Pick mapping
Main commit LTS commit How it applied
f34fe32a7c9 f1dd70600d6 adapted to the pass_through layout
ebf299d4ef4 f1dd70600d6 folded
10de3e17325 f1dd70600d6 folded
8f458da80a4 f1dd70600d6 folded
913580c35f9 f1dd70600d6 folded
a24a385e78e 95112076e8d a bypass in the dispatcher, since the line has no detectors module
eb16928919c 95112076e8d folded, since these requests stay on Python
db6801bc74f 95112076e8d folded, since these requests stay on Python
74ccdd8540c 95112076e8d folded, since these requests stay on Python
0b4cc980a9d 95112076e8d folded, since these requests stay on Python
6012bc29fcf 95112076e8d folded, since these requests stay on Python
5f60fd84d0d 63938d8b6f4 tests only, the line already behaves this way
c53d9472110 9df5d100259 adapted, the system text and Rust halves have no code here
49bf95c0420 821deb88a7a adapted to the pass_through layout, and the dispatcher keeps a body with a non-string system text on Python
f5084e46ac4 6c353fd21c1 tests only, without the Rust test, whose shaping option this line's Rust handler lacks

8d5be2b938e only moves that Rust test to #[rstest], so the pair block records it as main only

User Flow

Before: a user text block with "text": null is silently dropped on inference, while count_tokens refuses the same body

  1. They send POST https://litellm-domain/v1/messages to an anthropic/claude-haiku-5-5 deployment with blocks {"type":"text","text":"Say hi"} and {"type":"text","text":null}
  2. It answers 200 with no sign of the drop, on OpenAI, Gemini, MiniMax and DeepSeek too, and for "text": 123
  3. They send the same body to POST https://litellm-domain/v1/messages/count_tokens and get 400 messages.0.content.1.text.text: Input should be a valid string
  4. A body with only the null block gets 400 messages: at least one message is required, the wrong cause
  5. A system prompt block with "text": null answers 500 on MiniMax and DeepSeek and 200 on OpenAI and Gemini

After: both routes refuse the bad block the same way, and drop_params drops it on both

  1. The same POST https://litellm-domain/v1/messages answers 400 messages.0.content.1.text: Input should be a valid string on every provider
  2. POST https://litellm-domain/v1/messages/count_tokens answers 400 with the same field message
  3. With drop_params: true on the deployment or in the request, both routes drop the block and answer 200
  4. A body with nothing left after the drop answers 400 messages: no message has content left after dropping empty or non-string text blocks
  5. The same system block answers 400 system.1.text: Input should be a valid string on every provider, and drop_params drops it

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).

Decisions

Choices made and the alternatives

On this line LITELLM_RUST=true sends /v1/messages to Rust, whose handler strips a null text as blank. The dispatcher keeps a body with a non-string user or system text on Python, which answers the 400 or drops the block, so only those malformed bodies leave Rust. The alternative was porting #54165's Rust change, which builds on a shaping option this line's Rust handler lacks. The standalone Rust gateway crate keeps stripping, since no workflow builds it and the shipped gateway image runs the Python proxy

Without drop_params, every provider answers a local 400 before any provider call, with the field path the OpenAI and Gemini adapters already used.

A malformed text inside a tool_result keeps the line's behavior, so rewriting and masking guardrails keep working on it. The rule only covers user turns and the system prompt, so a null text in a replayed assistant turn is still stripped and answers 200

Empty and whitespace-only text blocks keep being stripped on both routes, since Claude Code sends them. count_tokens on the Anthropic route now counts the messages inference sends, so it strips them too unless all are blank, rewrites tool_use ids Anthropic would refuse and flattens unencrypted web search results. The alternative was stripping only empty blocks, which kept count_tokens refusing bodies that inference sends fine

The 400 counts blocks in the client's own body, before empty text blocks are stripped, so the index points at the block the client sent. When drop_params drops a non-string user text and nothing is left, both routes answer a local 400 that says so

A non-string system text gets the same rule, with the message Anthropic's own API gives for that body (direct-anthropic-system-null.txt in the gist). With drop_params the block is dropped, and system is left out when no block is left. When the system prompt and a user turn are both bad, the 400 names the user field, as Anthropic's API does (direct-anthropic-both-bad.txt)

A user text block with no text key is still stripped, as this line already did and #54165 does, since it reads as empty text. Anthropic's API answers 400 for it. A system block with no text is sent as is, so the provider answers its own 400

A null text in a role: "system" entry inside messages is still dropped, at the start or mid-conversation, as on this line's base and on main after #54165, while Anthropic's API answers 400 (lts-system-role-null.txt in the gist). This PR only ports #54165, so that fix goes to main first and then gets picked here

The check adds passes over the messages, about 2 ms more prep CPU at 500 turns and 8 ms at 2,000, the same passes #54165 added on main. With LITELLM_RUST=true the dispatcher's own scan adds 1.3 ms at 500 turns and up to 8 ms at 2,000. Folding them into one pass is a follow-up for both lines

Screenshots / Proof of Fix

Both legs ran 28 curl cases and one Claude Code task on real provider APIs, plus 14 with LITELLM_RUST=true, 16 on Bedrock and Vertex AI Claude, and 11 for numeric text and MiniMax and DeepSeek user text. 1aaabcce03f only changes a test, so this proof carries to it

The 14 cases with LITELLM_RUST=true

Full output is in before and after, from cases-lts-rust-on.sh run as bash cases-lts-rust-on.sh <port> against the config above. Every model is a litellm-qa-null-text-* deployment, and "Rust" means the answer carried x-litellm-rust: true

Case Before (e552bff) After (6c353fd)
plain request, anthropic 200, Rust 200, Rust
null user text, anthropic 200, Rust 400
same body, count_tokens 400 .text.text 400 .text
null user text, openai 200 400
null user text, drop deployment 200, Rust 200
request drop_params: true 200, Rust 200
request drop_params: false 200, Rust 400
stream: true 200 stream, Rust 400
stream: true, drop deployment 200 stream, Rust 200 stream
null system text, anthropic 400 from Anthropic 400 local
null system text, minimax, request drop_params 500 200
null system text, deepseek, request drop_params 422 200
empty text beside a real one 200, Rust 200, Rust
same body, count_tokens 400 200
claude_platform, and Gemini count_tokens

Full output is in before and after, from #54165's cases-claude-platform-gemini.sh and config. The rig has no AWS key for the one subscribed claude_platform account

Case Before (e552bff) After (6c353fd)
claude_platform null user text 500 no AWS credentials 400 local
claude_platform null system text 500 no AWS credentials 400 local
same, count_tokens 500 no AWS credentials 400 local
claude_platform drop, both bad 500 no AWS credentials 500 no AWS credentials
Gemini clean count_tokens 200, 3 tokens 200, 3 tokens
Gemini null system, count_tokens 400, other text 400 local
Gemini drop, null system, count_tokens 400 200, 7 tokens
Gemini drop, both bad, count_tokens 400 200, 7 tokens
Bedrock and Vertex AI Claude

Both providers answered every case alike. Full output is in before and after, from cases-lts-bedrock-vertex.sh and config

Case Before (e552bff) After (6c353fd)
Clean prompt 200 200
Null beside real text 200, block dropped 400 messages.0.content.1.text
same, count_tokens 400 .text.text 400 messages.0.content.1.text
Null-only user turn 400 from provider 400 messages.0.content.0.text
Null system text 500 400 system.1.text
drop, null beside real text 200 200
drop, null-only user turn 400 from provider 400 local, nothing left
drop, null system text 500 200
Numeric text, and MiniMax and DeepSeek user text

Full output is in before and after, from cases-lts-numeric-minimax-deepseek.sh on the main cases' config

Case Before (e552bff) After (6c353fd)
"text": 123 user text, Anthropic 200 400 messages.0.content.1.text
same, OpenAI, Gemini, MiniMax 200 400 messages.0.content.1.text
same, Anthropic count_tokens 400 .text.text 400 messages.0.content.1.text
same, Anthropic with drop_params 200 200
"text": 123 system text, Anthropic 400 from Anthropic 400 local system.1.text
null user text, MiniMax and DeepSeek 200 400 messages.0.content.1.text
same, count_tokens 200, local estimate 400 messages.0.content.1.text
Setup to rerun every case

Each leg ran one proxy with 2 uvicorn workers and no database, booted from its own tree with the command below. Before ran at the line's tip e552bffcaf7 and After at 6c353fd21c1

Env var names: ANTHROPIC_API_KEY, OPENAI_API_KEY, GEMINI_API_KEY, MINIMAX_API_KEY, DEEPSEEK_API_KEY

env -u DATABASE_URL LITELLM_DANGEROUSLY_PERMIT_WEAK_OR_UNSET_MASTER_KEY=true PROXY_BASE_URL=http://127.0.0.1:<port> .venv/bin/python litellm/proxy/proxy_cli.py --config config.yaml --port <port> --num_workers 2

The config is config-lts.yaml, and each case comes from cases-lts.sh or system-lts.sh, run as bash <script> <port>, which print each curl they run

Before (e552bff)

litellm-qa-null-text-anthropic null text beside a prompt, messages

  1. Send the request and read the answer
$ curl -s -w '\nHTTP %{http_code}\n' localhost:28448/v1/messages -H 'Authorization: Bearer sk-1234' -H 'content-type: application/json' -d '{"model":"litellm-qa-null-text-anthropic","max_tokens":32,"messages":[{"role":"user","content":[{"type":"text","text":"Say hi in one word"},{"type":"text","text":null}]}]}'
{"model":"litellm-qa-null-text-anthropic","id":"msg_011ChNa5XfabaKh1uMmhHe1a","type":"message","role":"assistant","content":[{"type":"text","text":"Hi!"}],"container":null,"stop_reason":"end_turn","stop_sequence":null,"stop_details":null,"usage":{"input_tokens":15,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":6,"output_tokens_details":{"thinking_tokens":0},"service_tier":"standard","inference_geo":"global","speed":"standard"},"diagnostics":null}
HTTP 200
The other 27 cases

litellm-qa-null-text-minimax null system text, messages

  1. Send the request and read the answer
$ curl -s -w '\nHTTP %{http_code}\n' localhost:28448/v1/messages -H 'Authorization: Bearer sk-1234' -H 'content-type: application/json' -d '{"model":"litellm-qa-null-text-minimax","max_tokens":32,"system":[{"type":"text","text":"Answer in one word"},{"type":"text","text":null}],"messages":[{"role":"user","content":[{"type":"text","text":"Say hi in one word"}]}]}'
{"type":"error","error":{"type":"api_error","message":"'NoneType' object has no attribute 'startswith'"}}
HTTP 500

litellm-qa-null-text-anthropic null text beside a prompt, count_tokens

  1. Send the request and read the answer
$ curl -s -w '\nHTTP %{http_code}\n' localhost:28448/v1/messages/count_tokens -H 'Authorization: Bearer sk-1234' -H 'content-type: application/json' -d '{"model":"litellm-qa-null-text-anthropic","max_tokens":32,"messages":[{"role":"user","content":[{"type":"text","text":"Say hi in one word"},{"type":"text","text":null}]}]}'
{"type":"error","error":{"type":"invalid_request_error","message":"messages.0.content.1.text.text: Input should be a valid string"},"request_id":"req_011ChNa5pGiNodHw3tiNXqZp"}
HTTP 400

litellm-qa-null-text-openai null text beside a prompt, messages

  1. Send the request and read the answer
$ curl -s -w '\nHTTP %{http_code}\n' localhost:28448/v1/messages -H 'Authorization: Bearer sk-1234' -H 'content-type: application/json' -d '{"model":"litellm-qa-null-text-openai","max_tokens":32,"messages":[{"role":"user","content":[{"type":"text","text":"Say hi in one word"},{"type":"text","text":null}]}]}'
{"id":"resp_bGl0ZWxsbTpjdXN0b21fbGxtX3Byb3ZpZGVyOm9wZW5haTttb2RlbF9pZDpjZWNlNjZhMmMwMTBhODUzODg4ZjVmOWRiYzA2Nzg3MTIzNzU4M2FjM2IzYTE2MWZkYjAxNTI1YWE1ZmNmNDczO3Jlc3BvbnNlX2lkOnJlc3BfMGU2NTgzYTVkMzhiYTc3ZDAwNmIwNjE0YmM0ZjMwODdkMDk0MzMzYzcwZjkyMmYxNjc=","type":"message","role":"assistant","model":"litellm-qa-null-text-openai","stop_sequence":null,"usage":{"input_tokens":11,"output_tokens":5},"content":[{"type":"text","text":"Hi"}],"stop_reason":"end_turn","stop_details":null}
HTTP 200

litellm-qa-null-text-gemini null text beside a prompt, messages

  1. Send the request and read the answer
$ curl -s -w '\nHTTP %{http_code}\n' localhost:28448/v1/messages -H 'Authorization: Bearer sk-1234' -H 'content-type: application/json' -d '{"model":"litellm-qa-null-text-gemini","max_tokens":32,"messages":[{"role":"user","content":[{"type":"text","text":"Say hi in one word"},{"type":"text","text":null}]}]}'
{"id":"vRQGa9nyKNuUvMcPztrPgA8","type":"message","role":"assistant","model":"litellm-qa-null-text-gemini","stop_sequence":null,"usage":{"input_tokens":6,"output_tokens":28},"content":[],"stop_reason":"max_tokens","stop_details":null}
HTTP 200

litellm-qa-null-text-anthropic-drop null text beside a prompt with drop_params, messages

  1. Send the request and read the answer
$ curl -s -w '\nHTTP %{http_code}\n' localhost:28448/v1/messages -H 'Authorization: Bearer sk-1234' -H 'content-type: application/json' -d '{"model":"litellm-qa-null-text-anthropic-drop","max_tokens":32,"messages":[{"role":"user","content":[{"type":"text","text":"Say hi in one word"},{"type":"text","text":null}]}]}'
{"model":"litellm-qa-null-text-anthropic-drop","id":"msg_011ChNa5q5aMVo5YPoy1KSJQ","type":"message","role":"assistant","content":[{"type":"text","text":"Hi!"}],"container":null,"stop_reason":"end_turn","stop_sequence":null,"stop_details":null,"usage":{"input_tokens":15,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":6,"output_tokens_details":{"thinking_tokens":0},"service_tier":"standard","inference_geo":"global","speed":"standard"},"diagnostics":null}
HTTP 200

litellm-qa-null-text-openai-drop null text beside a prompt with drop_params, messages

  1. Send the request and read the answer
$ curl -s -w '\nHTTP %{http_code}\n' localhost:28448/v1/messages -H 'Authorization: Bearer sk-1234' -H 'content-type: application/json' -d '{"model":"litellm-qa-null-text-openai-drop","max_tokens":32,"messages":[{"role":"user","content":[{"type":"text","text":"Say hi in one word"},{"type":"text","text":null}]}]}'
{"id":"resp_bGl0ZWxsbTpjdXN0b21fbGxtX3Byb3ZpZGVyOm9wZW5haTttb2RlbF9pZDplYWFkYjBmOWIwZTVlZjFkNTc3ZGFlZWEwMDM2ZTY5Y2UwYzM2NmZjNGI1YzdkZDIwZWNkN2VhMDMzMWM3YWJjO3Jlc3BvbnNlX2lkOnJlc3BfMGFmOTZhNGNhNGYyZDliMzAwNmIwNjE0YzA2OGZjODdkMGE5NGIwODNjOWE4NDg2N2M=","type":"message","role":"assistant","model":"litellm-qa-null-text-openai-drop","stop_sequence":null,"usage":{"input_tokens":11,"output_tokens":6},"content":[{"type":"text","text":"Hi!"}],"stop_reason":"end_turn","stop_details":null}
HTTP 200

litellm-qa-null-text-gemini-drop null text beside a prompt with drop_params, messages

  1. Send the request and read the answer
$ curl -s -w '\nHTTP %{http_code}\n' localhost:28448/v1/messages -H 'Authorization: Bearer sk-1234' -H 'content-type: application/json' -d '{"model":"litellm-qa-null-text-gemini-drop","max_tokens":32,"messages":[{"role":"user","content":[{"type":"text","text":"Say hi in one word"},{"type":"text","text":null}]}]}'
{"id":"wRQGa8n1IN3xkPIPhMf-sAo","type":"message","role":"assistant","model":"litellm-qa-null-text-gemini-drop","stop_sequence":null,"usage":{"input_tokens":6,"output_tokens":28},"content":[{"type":"text","text":"Hello"}],"stop_reason":"max_tokens","stop_details":null}
HTTP 200

litellm-qa-null-text-anthropic-drop only a null text with drop_params, messages

  1. Send the request and read the answer
$ curl -s -w '\nHTTP %{http_code}\n' localhost:28448/v1/messages -H 'Authorization: Bearer sk-1234' -H 'content-type: application/json' -d '{"model":"litellm-qa-null-text-anthropic-drop","max_tokens":32,"messages":[{"role":"user","content":[{"type":"text","text":null}]}]}'
{"type":"error","error":{"type":"invalid_request_error","message":"litellm.BadRequestError: AnthropicException - {\"type\":\"error\",\"error\":{\"type\":\"invalid_request_error\",\"message\":\"messages: at least one message is required\"},\"request_id\":\"req_011ChNa65JLH1Qvzan4pryKZ\"}\n\nLiteLLM: model group 'litellm-qa-null-text-anthropic-drop' failed with the error above. No fallback was attempted."}}
HTTP 400

litellm-qa-null-text-gemini blank-only body, messages

  1. Send the request and read the answer
$ curl -s -w '\nHTTP %{http_code}\n' localhost:28448/v1/messages -H 'Authorization: Bearer sk-1234' -H 'content-type: application/json' -d '{"model":"litellm-qa-null-text-gemini","max_tokens":32,"messages":[{"role":"user","content":[{"type":"text","text":""},{"type":"text","text":" "}]}]}'
{"id":"wxQGa4GIHN--odAPha6mgAw","type":"message","role":"assistant","model":"litellm-qa-null-text-gemini","stop_sequence":null,"usage":{"input_tokens":2,"output_tokens":28},"content":[{"type":"text","text":"Hello"}],"stop_reason":"max_tokens","stop_details":null}
HTTP 200

litellm-qa-null-text-anthropic blank-only body, count_tokens

  1. Send the request and read the answer
$ curl -s -w '\nHTTP %{http_code}\n' localhost:28448/v1/messages/count_tokens -H 'Authorization: Bearer sk-1234' -H 'content-type: application/json' -d '{"model":"litellm-qa-null-text-anthropic","max_tokens":32,"messages":[{"role":"user","content":[{"type":"text","text":""},{"type":"text","text":" "}]}]}'
{"type":"error","error":{"type":"invalid_request_error","message":"messages: text content blocks must be non-empty"},"request_id":"req_011ChNa6FZUiPoxf92oBJG6H"}
HTTP 400

litellm-qa-null-text-anthropic null system text, messages

  1. Send the request and read the answer
$ curl -s -w '\nHTTP %{http_code}\n' localhost:28448/v1/messages -H 'Authorization: Bearer sk-1234' -H 'content-type: application/json' -d '{"model":"litellm-qa-null-text-anthropic","max_tokens":32,"system":[{"type":"text","text":"Answer in one word"},{"type":"text","text":null}],"messages":[{"role":"user","content":[{"type":"text","text":"Say hi in one word"}]}]}'
{"type":"error","error":{"type":"invalid_request_error","message":"litellm.BadRequestError: AnthropicException - {\"type\":\"error\",\"error\":{\"type\":\"invalid_request_error\",\"message\":\"system.1.text: Input should be a valid string\"},\"request_id\":\"req_011ChNa2rckvXRNraJvUpLpE\"}\n\nLiteLLM: model group 'litellm-qa-null-text-anthropic' failed with the error above. No fallback was attempted."}}
HTTP 400

litellm-qa-null-text-openai null system text, messages

  1. Send the request and read the answer
$ curl -s -w '\nHTTP %{http_code}\n' localhost:28448/v1/messages -H 'Authorization: Bearer sk-1234' -H 'content-type: application/json' -d '{"model":"litellm-qa-null-text-openai","max_tokens":32,"system":[{"type":"text","text":"Answer in one word"},{"type":"text","text":null}],"messages":[{"role":"user","content":[{"type":"text","text":"Say hi in one word"}]}]}'
{"id":"resp_bGl0ZWxsbTpjdXN0b21fbGxtX3Byb3ZpZGVyOm9wZW5haTttb2RlbF9pZDpjZWNlNjZhMmMwMTBhODUzODg4ZjVmOWRiYzA2Nzg3MTIzNzU4M2FjM2IzYTE2MWZkYjAxNTI1YWE1ZmNmNDczO3Jlc3BvbnNlX2lkOnJlc3BfMGY1M2YxYjZhMTgxMzc2YTAwNmIwNjE0OTgyYzk4ODdkMDgyM2IxMDRkOTcyZTdhYTk=","type":"message","role":"assistant","model":"litellm-qa-null-text-openai","stop_sequence":null,"usage":{"input_tokens":19,"output_tokens":5},"content":[{"type":"text","text":"Hi"}],"stop_reason":"end_turn","stop_details":null}
HTTP 200

litellm-qa-null-text-gemini null system text, messages

  1. Send the request and read the answer
$ curl -s -w '\nHTTP %{http_code}\n' localhost:28448/v1/messages -H 'Authorization: Bearer sk-1234' -H 'content-type: application/json' -d '{"model":"litellm-qa-null-text-gemini","max_tokens":32,"system":[{"type":"text","text":"Answer in one word"},{"type":"text","text":null}],"messages":[{"role":"user","content":[{"type":"text","text":"Say hi in one word"}]}]}'
{"id":"mRQGa9eSM82iur8Pp7Hp-Qg","type":"message","role":"assistant","model":"litellm-qa-null-text-gemini","stop_sequence":null,"usage":{"input_tokens":10,"output_tokens":28},"content":[{"type":"text","text":"Hello"}],"stop_reason":"max_tokens","stop_details":null}
HTTP 200

litellm-qa-null-text-deepseek null system text, messages

  1. Send the request and read the answer
$ curl -s -w '\nHTTP %{http_code}\n' localhost:28448/v1/messages -H 'Authorization: Bearer sk-1234' -H 'content-type: application/json' -d '{"model":"litellm-qa-null-text-deepseek","max_tokens":32,"system":[{"type":"text","text":"Answer in one word"},{"type":"text","text":null}],"messages":[{"role":"user","content":[{"type":"text","text":"Say hi in one word"}]}]}'
{"type":"error","error":{"type":"api_error","message":"'NoneType' object has no attribute 'startswith'"}}
HTTP 500

litellm-qa-null-text-anthropic null system text, count_tokens

  1. Send the request and read the answer
$ curl -s -w '\nHTTP %{http_code}\n' localhost:28448/v1/messages/count_tokens -H 'Authorization: Bearer sk-1234' -H 'content-type: application/json' -d '{"model":"litellm-qa-null-text-anthropic","max_tokens":32,"system":[{"type":"text","text":"Answer in one word"},{"type":"text","text":null}],"messages":[{"role":"user","content":[{"type":"text","text":"Say hi in one word"}]}]}'
{"type":"error","error":{"type":"invalid_request_error","message":"system.1.text: Input should be a valid string"},"request_id":"req_011ChNa3rWbXNot8h8q4ysnW"}
HTTP 400

litellm-qa-null-text-openai null system text, count_tokens

  1. Send the request and read the answer
$ curl -s -w '\nHTTP %{http_code}\n' localhost:28448/v1/messages/count_tokens -H 'Authorization: Bearer sk-1234' -H 'content-type: application/json' -d '{"model":"litellm-qa-null-text-openai","max_tokens":32,"system":[{"type":"text","text":"Answer in one word"},{"type":"text","text":null}],"messages":[{"role":"user","content":[{"type":"text","text":"Say hi in one word"}]}]}'
{"input_tokens":19,"litellm_count_source":"provider"}
HTTP 200

litellm-qa-null-text-minimax null system text, count_tokens

  1. Send the request and read the answer
$ curl -s -w '\nHTTP %{http_code}\n' localhost:28448/v1/messages/count_tokens -H 'Authorization: Bearer sk-1234' -H 'content-type: application/json' -d '{"model":"litellm-qa-null-text-minimax","max_tokens":32,"system":[{"type":"text","text":"Answer in one word"},{"type":"text","text":null}],"messages":[{"role":"user","content":[{"type":"text","text":"Say hi in one word"}]}]}'
{"input_tokens":21,"litellm_count_source":"local_estimate"}
HTTP 200

litellm-qa-null-text-deepseek null system text, count_tokens

  1. Send the request and read the answer
$ curl -s -w '\nHTTP %{http_code}\n' localhost:28448/v1/messages/count_tokens -H 'Authorization: Bearer sk-1234' -H 'content-type: application/json' -d '{"model":"litellm-qa-null-text-deepseek","max_tokens":32,"system":[{"type":"text","text":"Answer in one word"},{"type":"text","text":null}],"messages":[{"role":"user","content":[{"type":"text","text":"Say hi in one word"}]}]}'
{"input_tokens":44,"litellm_count_source":"local_estimate"}
HTTP 200

litellm-qa-null-text-anthropic-drop null system text with drop_params, messages

  1. Send the request and read the answer
$ curl -s -w '\nHTTP %{http_code}\n' localhost:28448/v1/messages -H 'Authorization: Bearer sk-1234' -H 'content-type: application/json' -d '{"model":"litellm-qa-null-text-anthropic-drop","max_tokens":32,"system":[{"type":"text","text":"Answer in one word"},{"type":"text","text":null}],"messages":[{"role":"user","content":[{"type":"text","text":"Say hi in one word"}]}]}'
{"type":"error","error":{"type":"invalid_request_error","message":"litellm.BadRequestError: AnthropicException - {\"type\":\"error\",\"error\":{\"type\":\"invalid_request_error\",\"message\":\"system.1.text: Input should be a valid string\"},\"request_id\":\"req_011ChNa3up2uJ9jb5hrP9srk\"}\n\nLiteLLM: model group 'litellm-qa-null-text-anthropic-drop' failed with the error above. No fallback was attempted."}}
HTTP 400

litellm-qa-null-text-openai-drop null system text with drop_params, messages

  1. Send the request and read the answer
$ curl -s -w '\nHTTP %{http_code}\n' localhost:28448/v1/messages -H 'Authorization: Bearer sk-1234' -H 'content-type: application/json' -d '{"model":"litellm-qa-null-text-openai-drop","max_tokens":32,"system":[{"type":"text","text":"Answer in one word"},{"type":"text","text":null}],"messages":[{"role":"user","content":[{"type":"text","text":"Say hi in one word"}]}]}'
{"id":"resp_bGl0ZWxsbTpjdXN0b21fbGxtX3Byb3ZpZGVyOm9wZW5haTttb2RlbF9pZDplYWFkYjBmOWIwZTVlZjFkNTc3ZGFlZWEwMDM2ZTY5Y2UwYzM2NmZjNGI1YzdkZDIwZWNkN2VhMDMzMWM3YWJjO3Jlc3BvbnNlX2lkOnJlc3BfMDJhNDNlYTc5ZTFkZDk1MjAwNmIwNjE0YTYxYjEwODdkMDhkYTQwZjY1NDYzMjk5ZGI=","type":"message","role":"assistant","model":"litellm-qa-null-text-openai-drop","stop_sequence":null,"usage":{"input_tokens":19,"output_tokens":5},"content":[{"type":"text","text":"Hi"}],"stop_reason":"end_turn","stop_details":null}
HTTP 200

litellm-qa-null-text-gemini-drop null system text with drop_params, messages

  1. Send the request and read the answer
$ curl -s -w '\nHTTP %{http_code}\n' localhost:28448/v1/messages -H 'Authorization: Bearer sk-1234' -H 'content-type: application/json' -d '{"model":"litellm-qa-null-text-gemini-drop","max_tokens":32,"system":[{"type":"text","text":"Answer in one word"},{"type":"text","text":null}],"messages":[{"role":"user","content":[{"type":"text","text":"Say hi in one word"}]}]}'
{"id":"pxQGa7KHDf-NzLEPorqN4AY","type":"message","role":"assistant","model":"litellm-qa-null-text-gemini-drop","stop_sequence":null,"usage":{"input_tokens":10,"output_tokens":29},"content":[],"stop_reason":"max_tokens","stop_details":null}
HTTP 200

litellm-qa-null-text-anthropic-drop null system text with drop_params, count_tokens

  1. Send the request and read the answer
$ curl -s -w '\nHTTP %{http_code}\n' localhost:28448/v1/messages/count_tokens -H 'Authorization: Bearer sk-1234' -H 'content-type: application/json' -d '{"model":"litellm-qa-null-text-anthropic-drop","max_tokens":32,"system":[{"type":"text","text":"Answer in one word"},{"type":"text","text":null}],"messages":[{"role":"user","content":[{"type":"text","text":"Say hi in one word"}]}]}'
{"type":"error","error":{"type":"invalid_request_error","message":"system.1.text: Input should be a valid string"},"request_id":"req_011ChNa49NbwwZ1gyzdNjDXc"}
HTTP 400

litellm-qa-null-text-anthropic-drop only a null system text with drop_params, messages

  1. Send the request and read the answer
$ curl -s -w '\nHTTP %{http_code}\n' localhost:28448/v1/messages -H 'Authorization: Bearer sk-1234' -H 'content-type: application/json' -d '{"model":"litellm-qa-null-text-anthropic-drop","max_tokens":32,"system":[{"type":"text","text":null}],"messages":[{"role":"user","content":[{"type":"text","text":"Say hi in one word"}]}]}'
{"type":"error","error":{"type":"invalid_request_error","message":"litellm.BadRequestError: AnthropicException - {\"type\":\"error\",\"error\":{\"type\":\"invalid_request_error\",\"message\":\"system.0.text: Input should be a valid string\"},\"request_id\":\"req_011ChNa4A3naAAhQoCM9KgxE\"}\n\nLiteLLM: model group 'litellm-qa-null-text-anthropic-drop' failed with the error above. No fallback was attempted."}}
HTTP 400

litellm-qa-null-text-anthropic null system text and null user text, messages

  1. Send the request and read the answer
$ curl -s -w '\nHTTP %{http_code}\n' localhost:28448/v1/messages -H 'Authorization: Bearer sk-1234' -H 'content-type: application/json' -d '{"model":"litellm-qa-null-text-anthropic","max_tokens":32,"system":[{"type":"text","text":"Answer in one word"},{"type":"text","text":null}],"messages":[{"role":"user","content":[{"type":"text","text":"Say hi"},{"type":"text","text":null}]}]}'
{"type":"error","error":{"type":"invalid_request_error","message":"litellm.BadRequestError: AnthropicException - {\"type\":\"error\",\"error\":{\"type\":\"invalid_request_error\",\"message\":\"system.1.text: Input should be a valid string\"},\"request_id\":\"req_011ChNa4AxMtP17SK858vkfS\"}\n\nLiteLLM: model group 'litellm-qa-null-text-anthropic' failed with the error above. No fallback was attempted."}}
HTTP 400

litellm-qa-null-text-anthropic null system text and null user text, count_tokens

  1. Send the request and read the answer
$ curl -s -w '\nHTTP %{http_code}\n' localhost:28448/v1/messages/count_tokens -H 'Authorization: Bearer sk-1234' -H 'content-type: application/json' -d '{"model":"litellm-qa-null-text-anthropic","max_tokens":32,"system":[{"type":"text","text":"Answer in one word"},{"type":"text","text":null}],"messages":[{"role":"user","content":[{"type":"text","text":"Say hi"},{"type":"text","text":null}]}]}'
{"type":"error","error":{"type":"invalid_request_error","message":"messages.0.content.1.text.text: Input should be a valid string"},"request_id":"req_011ChNa4BjjFD7KqLWBvmRLb"}
HTTP 400

litellm-qa-null-text-openai null system text and null user text, messages

  1. Send the request and read the answer
$ curl -s -w '\nHTTP %{http_code}\n' localhost:28448/v1/messages -H 'Authorization: Bearer sk-1234' -H 'content-type: application/json' -d '{"model":"litellm-qa-null-text-openai","max_tokens":32,"system":[{"type":"text","text":"Answer in one word"},{"type":"text","text":null}],"messages":[{"role":"user","content":[{"type":"text","text":"Say hi"},{"type":"text","text":null}]}]}'
{"id":"resp_bGl0ZWxsbTpjdXN0b21fbGxtX3Byb3ZpZGVyOm9wZW5haTttb2RlbF9pZDpjZWNlNjZhMmMwMTBhODUzODg4ZjVmOWRiYzA2Nzg3MTIzNzU4M2FjM2IzYTE2MWZkYjAxNTI1YWE1ZmNmNDczO3Jlc3BvbnNlX2lkOnJlc3BfMDY5ZTg3ODNmMGVhMjdmNjAwNmIwNjE0YTljZTZjODdkMDgwNTFiNGQ2MDQzZTJhOTc=","type":"message","role":"assistant","model":"litellm-qa-null-text-openai","stop_sequence":null,"usage":{"input_tokens":16,"output_tokens":5},"content":[{"type":"text","text":"Hi"}],"stop_reason":"end_turn","stop_details":null}
HTTP 200

litellm-qa-null-text-openai null system text and null user text, count_tokens

  1. Send the request and read the answer
$ curl -s -w '\nHTTP %{http_code}\n' localhost:28448/v1/messages/count_tokens -H 'Authorization: Bearer sk-1234' -H 'content-type: application/json' -d '{"model":"litellm-qa-null-text-openai","max_tokens":32,"system":[{"type":"text","text":"Answer in one word"},{"type":"text","text":null}],"messages":[{"role":"user","content":[{"type":"text","text":"Say hi"},{"type":"text","text":null}]}]}'
{"input_tokens":16,"litellm_count_source":"provider"}
HTTP 200

Claude Code

  1. Ask Claude Code to write hello.txt and read it back
Claude Code pane
❯ Create a file named hello.txt containing the word hi, then read it back and tell me what it says
● Bash(printf 'hi' > /private/tmp/claude-501/-Users-mateo-Development-litellm/b40bfb9b-3e6f-4534-bacb-a1267dc9d404/scratchpad/work-2
  e2a77f0/qa/lts2-before/cc/hello.txt && cat /private/tmp/claude-501/-Users-mateo-Development-litellm/b40bfb9b-3e6f-4534-bacb-a1267d
  c9d404/scratchpad/work-2e2a77f0/qa/lts2-before/cc/hello.txt)
  ⎿  hi
                                                                                     10:51 PM litellm-qa-null-text-anthropic
● I created hello.txt in the working directory with the word hi, and reading it back shows it says: hi
✻ Brewed for 2s · done 10:51 PM

After (6c353fd)

litellm-qa-null-text-anthropic null text beside a prompt, messages

  1. Send the request and read the answer
$ curl -s -w '\nHTTP %{http_code}\n' localhost:30048/v1/messages -H 'Authorization: Bearer sk-1234' -H 'content-type: application/json' -d '{"model":"litellm-qa-null-text-anthropic","max_tokens":32,"messages":[{"role":"user","content":[{"type":"text","text":"Say hi in one word"},{"type":"text","text":null}]}]}'
{"type":"error","error":{"type":"invalid_request_error","message":"litellm.BadRequestError: messages.0.content.1.text: Input should be a valid string\n\nLiteLLM: model group 'litellm-qa-null-text-anthropic' failed with the error above. No fallback was attempted."}}
HTTP 400
The other 27 cases

litellm-qa-null-text-minimax null system text, messages

  1. Send the request and read the answer
$ curl -s -w '\nHTTP %{http_code}\n' localhost:30048/v1/messages -H 'Authorization: Bearer sk-1234' -H 'content-type: application/json' -d '{"model":"litellm-qa-null-text-minimax","max_tokens":32,"system":[{"type":"text","text":"Answer in one word"},{"type":"text","text":null}],"messages":[{"role":"user","content":[{"type":"text","text":"Say hi in one word"}]}]}'
{"type":"error","error":{"type":"invalid_request_error","message":"litellm.BadRequestError: system.1.text: Input should be a valid string\n\nLiteLLM: model group 'litellm-qa-null-text-minimax' failed with the error above. No fallback was attempted."}}
HTTP 400

litellm-qa-null-text-anthropic null text beside a prompt, count_tokens

  1. Send the request and read the answer
$ curl -s -w '\nHTTP %{http_code}\n' localhost:30048/v1/messages/count_tokens -H 'Authorization: Bearer sk-1234' -H 'content-type: application/json' -d '{"model":"litellm-qa-null-text-anthropic","max_tokens":32,"messages":[{"role":"user","content":[{"type":"text","text":"Say hi in one word"},{"type":"text","text":null}]}]}'
{"type":"error","error":{"type":"invalid_request_error","message":"messages.0.content.1.text: Input should be a valid string"}}
HTTP 400

litellm-qa-null-text-openai null text beside a prompt, messages

  1. Send the request and read the answer
$ curl -s -w '\nHTTP %{http_code}\n' localhost:30048/v1/messages -H 'Authorization: Bearer sk-1234' -H 'content-type: application/json' -d '{"model":"litellm-qa-null-text-openai","max_tokens":32,"messages":[{"role":"user","content":[{"type":"text","text":"Say hi in one word"},{"type":"text","text":null}]}]}'
{"type":"error","error":{"type":"invalid_request_error","message":"litellm.BadRequestError: messages.0.content.1.text: Input should be a valid string\n\nLiteLLM: model group 'litellm-qa-null-text-openai' failed with the error above. No fallback was attempted."}}
HTTP 400

litellm-qa-null-text-gemini null text beside a prompt, messages

  1. Send the request and read the answer
$ curl -s -w '\nHTTP %{http_code}\n' localhost:30048/v1/messages -H 'Authorization: Bearer sk-1234' -H 'content-type: application/json' -d '{"model":"litellm-qa-null-text-gemini","max_tokens":32,"messages":[{"role":"user","content":[{"type":"text","text":"Say hi in one word"},{"type":"text","text":null}]}]}'
{"type":"error","error":{"type":"invalid_request_error","message":"litellm.BadRequestError: messages.0.content.1.text: Input should be a valid string\n\nLiteLLM: model group 'litellm-qa-null-text-gemini' failed with the error above. No fallback was attempted."}}
HTTP 400

litellm-qa-null-text-anthropic-drop null text beside a prompt with drop_params, messages

  1. Send the request and read the answer
$ curl -s -w '\nHTTP %{http_code}\n' localhost:30048/v1/messages -H 'Authorization: Bearer sk-1234' -H 'content-type: application/json' -d '{"model":"litellm-qa-null-text-anthropic-drop","max_tokens":32,"messages":[{"role":"user","content":[{"type":"text","text":"Say hi in one word"},{"type":"text","text":null}]}]}'
{"model":"litellm-qa-null-text-anthropic-drop","id":"msg_011ChNa5Y5czQNr44sFj48hu","type":"message","role":"assistant","content":[{"type":"text","text":"Hi"}],"container":null,"stop_reason":"end_turn","stop_sequence":null,"stop_details":null,"usage":{"input_tokens":15,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":5,"output_tokens_details":{"thinking_tokens":0},"service_tier":"standard","inference_geo":"global","speed":"standard"},"diagnostics":null}
HTTP 200

litellm-qa-null-text-openai-drop null text beside a prompt with drop_params, messages

  1. Send the request and read the answer
$ curl -s -w '\nHTTP %{http_code}\n' localhost:30048/v1/messages -H 'Authorization: Bearer sk-1234' -H 'content-type: application/json' -d '{"model":"litellm-qa-null-text-openai-drop","max_tokens":32,"messages":[{"role":"user","content":[{"type":"text","text":"Say hi in one word"},{"type":"text","text":null}]}]}'
{"id":"resp_bGl0ZWxsbTpjdXN0b21fbGxtX3Byb3ZpZGVyOm9wZW5haTttb2RlbF9pZDplYWFkYjBmOWIwZTVlZjFkNTc3ZGFlZWEwMDM2ZTY5Y2UwYzM2NmZjNGI1YzdkZDIwZWNkN2VhMDMzMWM3YWJjO3Jlc3BvbnNlX2lkOnJlc3BfMGUxM2FjNjc3NzY2YmQwMTAwNmIwNjE0YmM3MmYwODdkMDlhMjMyOWZhYThhZmZmZmY=","type":"message","role":"assistant","model":"litellm-qa-null-text-openai-drop","stop_sequence":null,"usage":{"input_tokens":11,"output_tokens":5},"content":[{"type":"text","text":"Hi"}],"stop_reason":"end_turn","stop_details":null}
HTTP 200

litellm-qa-null-text-gemini-drop null text beside a prompt with drop_params, messages

  1. Send the request and read the answer
$ curl -s -w '\nHTTP %{http_code}\n' localhost:30048/v1/messages -H 'Authorization: Bearer sk-1234' -H 'content-type: application/json' -d '{"model":"litellm-qa-null-text-gemini-drop","max_tokens":32,"messages":[{"role":"user","content":[{"type":"text","text":"Say hi in one word"},{"type":"text","text":null}]}]}'
{"id":"vRQGa_T5Mdiaur8P77OF6Ao","type":"message","role":"assistant","model":"litellm-qa-null-text-gemini-drop","stop_sequence":null,"usage":{"input_tokens":6,"output_tokens":28},"content":[{"type":"text","text":"Constraint:"}],"stop_reason":"max_tokens","stop_details":null}
HTTP 200

litellm-qa-null-text-anthropic-drop only a null text with drop_params, messages

  1. Send the request and read the answer
$ curl -s -w '\nHTTP %{http_code}\n' localhost:30048/v1/messages -H 'Authorization: Bearer sk-1234' -H 'content-type: application/json' -d '{"model":"litellm-qa-null-text-anthropic-drop","max_tokens":32,"messages":[{"role":"user","content":[{"type":"text","text":null}]}]}'
{"type":"error","error":{"type":"invalid_request_error","message":"litellm.BadRequestError: messages: no message has content left after dropping empty or non-string text blocks\n\nLiteLLM: model group 'litellm-qa-null-text-anthropic-drop' failed with the error above. No fallback was attempted."}}
HTTP 400

litellm-qa-null-text-gemini blank-only body, messages

  1. Send the request and read the answer
$ curl -s -w '\nHTTP %{http_code}\n' localhost:30048/v1/messages -H 'Authorization: Bearer sk-1234' -H 'content-type: application/json' -d '{"model":"litellm-qa-null-text-gemini","max_tokens":32,"messages":[{"role":"user","content":[{"type":"text","text":""},{"type":"text","text":" "}]}]}'
{"id":"wBQGa5jUCpqMkPIP56Tm2QM","type":"message","role":"assistant","model":"litellm-qa-null-text-gemini","stop_sequence":null,"usage":{"input_tokens":2,"output_tokens":28},"content":[{"type":"text","text":"Hello! How can"}],"stop_reason":"max_tokens","stop_details":null}
HTTP 200

litellm-qa-null-text-anthropic blank-only body, count_tokens

  1. Send the request and read the answer
$ curl -s -w '\nHTTP %{http_code}\n' localhost:30048/v1/messages/count_tokens -H 'Authorization: Bearer sk-1234' -H 'content-type: application/json' -d '{"model":"litellm-qa-null-text-anthropic","max_tokens":32,"messages":[{"role":"user","content":[{"type":"text","text":""},{"type":"text","text":" "}]}]}'
{"type":"error","error":{"type":"invalid_request_error","message":"messages: text content blocks must be non-empty"},"request_id":"req_011ChNa5zQALVU9DjsRm83S9"}
HTTP 400

litellm-qa-null-text-anthropic null system text, messages

  1. Send the request and read the answer
$ curl -s -w '\nHTTP %{http_code}\n' localhost:30048/v1/messages -H 'Authorization: Bearer sk-1234' -H 'content-type: application/json' -d '{"model":"litellm-qa-null-text-anthropic","max_tokens":32,"system":[{"type":"text","text":"Answer in one word"},{"type":"text","text":null}],"messages":[{"role":"user","content":[{"type":"text","text":"Say hi in one word"}]}]}'
{"type":"error","error":{"type":"invalid_request_error","message":"litellm.BadRequestError: system.1.text: Input should be a valid string\n\nLiteLLM: model group 'litellm-qa-null-text-anthropic' failed with the error above. No fallback was attempted."}}
HTTP 400

litellm-qa-null-text-openai null system text, messages

  1. Send the request and read the answer
$ curl -s -w '\nHTTP %{http_code}\n' localhost:30048/v1/messages -H 'Authorization: Bearer sk-1234' -H 'content-type: application/json' -d '{"model":"litellm-qa-null-text-openai","max_tokens":32,"system":[{"type":"text","text":"Answer in one word"},{"type":"text","text":null}],"messages":[{"role":"user","content":[{"type":"text","text":"Say hi in one word"}]}]}'
{"type":"error","error":{"type":"invalid_request_error","message":"litellm.BadRequestError: system.1.text: Input should be a valid string\n\nLiteLLM: model group 'litellm-qa-null-text-openai' failed with the error above. No fallback was attempted."}}
HTTP 400

litellm-qa-null-text-gemini null system text, messages

  1. Send the request and read the answer
$ curl -s -w '\nHTTP %{http_code}\n' localhost:30048/v1/messages -H 'Authorization: Bearer sk-1234' -H 'content-type: application/json' -d '{"model":"litellm-qa-null-text-gemini","max_tokens":32,"system":[{"type":"text","text":"Answer in one word"},{"type":"text","text":null}],"messages":[{"role":"user","content":[{"type":"text","text":"Say hi in one word"}]}]}'
{"type":"error","error":{"type":"invalid_request_error","message":"litellm.BadRequestError: system.1.text: Input should be a valid string\n\nLiteLLM: model group 'litellm-qa-null-text-gemini' failed with the error above. No fallback was attempted."}}
HTTP 400

litellm-qa-null-text-deepseek null system text, messages

  1. Send the request and read the answer
$ curl -s -w '\nHTTP %{http_code}\n' localhost:30048/v1/messages -H 'Authorization: Bearer sk-1234' -H 'content-type: application/json' -d '{"model":"litellm-qa-null-text-deepseek","max_tokens":32,"system":[{"type":"text","text":"Answer in one word"},{"type":"text","text":null}],"messages":[{"role":"user","content":[{"type":"text","text":"Say hi in one word"}]}]}'
{"type":"error","error":{"type":"invalid_request_error","message":"litellm.BadRequestError: system.1.text: Input should be a valid string\n\nLiteLLM: model group 'litellm-qa-null-text-deepseek' failed with the error above. No fallback was attempted."}}
HTTP 400

litellm-qa-null-text-anthropic null system text, count_tokens

  1. Send the request and read the answer
$ curl -s -w '\nHTTP %{http_code}\n' localhost:30048/v1/messages/count_tokens -H 'Authorization: Bearer sk-1234' -H 'content-type: application/json' -d '{"model":"litellm-qa-null-text-anthropic","max_tokens":32,"system":[{"type":"text","text":"Answer in one word"},{"type":"text","text":null}],"messages":[{"role":"user","content":[{"type":"text","text":"Say hi in one word"}]}]}'
{"type":"error","error":{"type":"invalid_request_error","message":"system.1.text: Input should be a valid string"}}
HTTP 400

litellm-qa-null-text-openai null system text, count_tokens

  1. Send the request and read the answer
$ curl -s -w '\nHTTP %{http_code}\n' localhost:30048/v1/messages/count_tokens -H 'Authorization: Bearer sk-1234' -H 'content-type: application/json' -d '{"model":"litellm-qa-null-text-openai","max_tokens":32,"system":[{"type":"text","text":"Answer in one word"},{"type":"text","text":null}],"messages":[{"role":"user","content":[{"type":"text","text":"Say hi in one word"}]}]}'
{"type":"error","error":{"type":"invalid_request_error","message":"system.1.text: Input should be a valid string"}}
HTTP 400

litellm-qa-null-text-minimax null system text, count_tokens

  1. Send the request and read the answer
$ curl -s -w '\nHTTP %{http_code}\n' localhost:30048/v1/messages/count_tokens -H 'Authorization: Bearer sk-1234' -H 'content-type: application/json' -d '{"model":"litellm-qa-null-text-minimax","max_tokens":32,"system":[{"type":"text","text":"Answer in one word"},{"type":"text","text":null}],"messages":[{"role":"user","content":[{"type":"text","text":"Say hi in one word"}]}]}'
{"type":"error","error":{"type":"invalid_request_error","message":"system.1.text: Input should be a valid string"}}
HTTP 400

litellm-qa-null-text-deepseek null system text, count_tokens

  1. Send the request and read the answer
$ curl -s -w '\nHTTP %{http_code}\n' localhost:30048/v1/messages/count_tokens -H 'Authorization: Bearer sk-1234' -H 'content-type: application/json' -d '{"model":"litellm-qa-null-text-deepseek","max_tokens":32,"system":[{"type":"text","text":"Answer in one word"},{"type":"text","text":null}],"messages":[{"role":"user","content":[{"type":"text","text":"Say hi in one word"}]}]}'
{"type":"error","error":{"type":"invalid_request_error","message":"system.1.text: Input should be a valid string"}}
HTTP 400

litellm-qa-null-text-anthropic-drop null system text with drop_params, messages

  1. Send the request and read the answer
$ curl -s -w '\nHTTP %{http_code}\n' localhost:30048/v1/messages -H 'Authorization: Bearer sk-1234' -H 'content-type: application/json' -d '{"model":"litellm-qa-null-text-anthropic-drop","max_tokens":32,"system":[{"type":"text","text":"Answer in one word"},{"type":"text","text":null}],"messages":[{"role":"user","content":[{"type":"text","text":"Say hi in one word"}]}]}'
{"model":"litellm-qa-null-text-anthropic-drop","id":"msg_011ChNa2u1P8yEDVV5RWKHzt","type":"message","role":"assistant","content":[{"type":"text","text":"Hi"}],"container":null,"stop_reason":"end_turn","stop_sequence":null,"stop_details":null,"usage":{"input_tokens":22,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":5,"output_tokens_details":{"thinking_tokens":0},"service_tier":"standard","inference_geo":"global","speed":"standard"},"diagnostics":null}
HTTP 200

litellm-qa-null-text-openai-drop null system text with drop_params, messages

  1. Send the request and read the answer
$ curl -s -w '\nHTTP %{http_code}\n' localhost:30048/v1/messages -H 'Authorization: Bearer sk-1234' -H 'content-type: application/json' -d '{"model":"litellm-qa-null-text-openai-drop","max_tokens":32,"system":[{"type":"text","text":"Answer in one word"},{"type":"text","text":null}],"messages":[{"role":"user","content":[{"type":"text","text":"Say hi in one word"}]}]}'
{"id":"resp_bGl0ZWxsbTpjdXN0b21fbGxtX3Byb3ZpZGVyOm9wZW5haTttb2RlbF9pZDplYWFkYjBmOWIwZTVlZjFkNTc3ZGFlZWEwMDM2ZTY5Y2UwYzM2NmZjNGI1YzdkZDIwZWNkN2VhMDMzMWM3YWJjO3Jlc3BvbnNlX2lkOnJlc3BfMDJlYjk4YzdkYTJhNjgxMzAwNmIwNjE0OThhZmI4ODdkMDkwZGUxM2UxNjM1ZWNhMzQ=","type":"message","role":"assistant","model":"litellm-qa-null-text-openai-drop","stop_sequence":null,"usage":{"input_tokens":19,"output_tokens":5},"content":[{"type":"text","text":"Hi"}],"stop_reason":"end_turn","stop_details":null}
HTTP 200

litellm-qa-null-text-gemini-drop null system text with drop_params, messages

  1. Send the request and read the answer
$ curl -s -w '\nHTTP %{http_code}\n' localhost:30048/v1/messages -H 'Authorization: Bearer sk-1234' -H 'content-type: application/json' -d '{"model":"litellm-qa-null-text-gemini-drop","max_tokens":32,"system":[{"type":"text","text":"Answer in one word"},{"type":"text","text":null}],"messages":[{"role":"user","content":[{"type":"text","text":"Say hi in one word"}]}]}'
{"id":"mhQGa52MEq-tvMcPmYeksQ8","type":"message","role":"assistant","model":"litellm-qa-null-text-gemini-drop","stop_sequence":null,"usage":{"input_tokens":10,"output_tokens":29},"content":[],"stop_reason":"max_tokens","stop_details":null}
HTTP 200

litellm-qa-null-text-anthropic-drop null system text with drop_params, count_tokens

  1. Send the request and read the answer
$ curl -s -w '\nHTTP %{http_code}\n' localhost:30048/v1/messages/count_tokens -H 'Authorization: Bearer sk-1234' -H 'content-type: application/json' -d '{"model":"litellm-qa-null-text-anthropic-drop","max_tokens":32,"system":[{"type":"text","text":"Answer in one word"},{"type":"text","text":null}],"messages":[{"role":"user","content":[{"type":"text","text":"Say hi in one word"}]}]}'
{"input_tokens":22,"litellm_count_source":"provider"}
HTTP 200

litellm-qa-null-text-anthropic-drop only a null system text with drop_params, messages

  1. Send the request and read the answer
$ curl -s -w '\nHTTP %{http_code}\n' localhost:30048/v1/messages -H 'Authorization: Bearer sk-1234' -H 'content-type: application/json' -d '{"model":"litellm-qa-null-text-anthropic-drop","max_tokens":32,"system":[{"type":"text","text":null}],"messages":[{"role":"user","content":[{"type":"text","text":"Say hi in one word"}]}]}'
{"model":"litellm-qa-null-text-anthropic-drop","id":"msg_011ChNa3CemganNXLM6fkyHM","type":"message","role":"assistant","content":[{"type":"text","text":"Hi!"}],"container":null,"stop_reason":"end_turn","stop_sequence":null,"stop_details":null,"usage":{"input_tokens":15,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":6,"output_tokens_details":{"thinking_tokens":0},"service_tier":"standard","inference_geo":"global","speed":"standard"},"diagnostics":null}
HTTP 200

litellm-qa-null-text-anthropic null system text and null user text, messages

  1. Send the request and read the answer
$ curl -s -w '\nHTTP %{http_code}\n' localhost:30048/v1/messages -H 'Authorization: Bearer sk-1234' -H 'content-type: application/json' -d '{"model":"litellm-qa-null-text-anthropic","max_tokens":32,"system":[{"type":"text","text":"Answer in one word"},{"type":"text","text":null}],"messages":[{"role":"user","content":[{"type":"text","text":"Say hi"},{"type":"text","text":null}]}]}'
{"type":"error","error":{"type":"invalid_request_error","message":"litellm.BadRequestError: messages.0.content.1.text: Input should be a valid string\n\nLiteLLM: model group 'litellm-qa-null-text-anthropic' failed with the error above. No fallback was attempted."}}
HTTP 400

litellm-qa-null-text-anthropic null system text and null user text, count_tokens

  1. Send the request and read the answer
$ curl -s -w '\nHTTP %{http_code}\n' localhost:30048/v1/messages/count_tokens -H 'Authorization: Bearer sk-1234' -H 'content-type: application/json' -d '{"model":"litellm-qa-null-text-anthropic","max_tokens":32,"system":[{"type":"text","text":"Answer in one word"},{"type":"text","text":null}],"messages":[{"role":"user","content":[{"type":"text","text":"Say hi"},{"type":"text","text":null}]}]}'
{"type":"error","error":{"type":"invalid_request_error","message":"messages.0.content.1.text: Input should be a valid string"}}
HTTP 400

litellm-qa-null-text-openai null system text and null user text, messages

  1. Send the request and read the answer
$ curl -s -w '\nHTTP %{http_code}\n' localhost:30048/v1/messages -H 'Authorization: Bearer sk-1234' -H 'content-type: application/json' -d '{"model":"litellm-qa-null-text-openai","max_tokens":32,"system":[{"type":"text","text":"Answer in one word"},{"type":"text","text":null}],"messages":[{"role":"user","content":[{"type":"text","text":"Say hi"},{"type":"text","text":null}]}]}'
{"type":"error","error":{"type":"invalid_request_error","message":"litellm.BadRequestError: messages.0.content.1.text: Input should be a valid string\n\nLiteLLM: model group 'litellm-qa-null-text-openai' failed with the error above. No fallback was attempted."}}
HTTP 400

litellm-qa-null-text-openai null system text and null user text, count_tokens

  1. Send the request and read the answer
$ curl -s -w '\nHTTP %{http_code}\n' localhost:30048/v1/messages/count_tokens -H 'Authorization: Bearer sk-1234' -H 'content-type: application/json' -d '{"model":"litellm-qa-null-text-openai","max_tokens":32,"system":[{"type":"text","text":"Answer in one word"},{"type":"text","text":null}],"messages":[{"role":"user","content":[{"type":"text","text":"Say hi"},{"type":"text","text":null}]}]}'
{"type":"error","error":{"type":"invalid_request_error","message":"messages.0.content.1.text: Input should be a valid string"}}
HTTP 400

Claude Code

  1. Ask Claude Code to write hello.txt and read it back
Claude Code pane
❯ Create a file named hello.txt containing the word hi, then read it back and tell me what it says
● Bash(printf 'hi' > /private/tmp/claude-501/-Users-mateo-Development-litellm/b40bfb9b-3e6f-4534-bacb-a1267dc9d404/scratchpad/work-2
  e2a77f0/qa/lts2-after/cc/hello.txt && cat /private/tmp/claude-501/-Users-mateo-Development-litellm/b40bfb9b-3e6f-4534-bacb-a1267dc
  9d404/scratchpad/work-2e2a77f0/qa/lts2-after/cc/hello.txt)
  ⎿  hi
                                                                                     10:51 PM litellm-qa-null-text-anthropic
● I created hello.txt in the working directory with the contents hi, and reading it back shows it says "hi".
✻ Brewed for 2s · done 10:51 PM

Type

🐛 Bug Fix

Caveats (if any)

Medium

  • Null or numeric user or system text some providers answered 200 for now answers 400 without drop_params, on Python and Rust alike, as Anthropic's API does
  • claude_platform's drop_params cell never reached the provider, since its one subscribed AWS account has no key here. Its 400 cells ran live
  • Each /v1/messages request pays about 2 ms more prep CPU at 500 turns and 8 ms at 2,000, more with LITELLM_RUST=true
  • A user text block with no text key is still dropped and answers 200, where Anthropic's API answers 400
  • A null text in a role: "system" message is still dropped with a 200, as on main, where Anthropic's API answers 400

Low

  • drop_params drops a user turn left with no blocks, as for empty text
  • The 400 path ends in .text, not Anthropic's .text.text
  • A null tool_result text keeps the line's behavior and stays 200 where providers accept it
  • With LITELLM_RUST=true a body with a non-string text is served by Python
  • The standalone Rust gateway crate, which nothing builds or ships, still strips a null text
  • With drop_params on Gemini, a last user turn of only numeric text is removed, while a null-only one comes back empty. This was already so
  • An all-blank text body still answers 400 on count_tokens, as on the base and main

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
Bugbot summary

[!NOTE]
Medium Risk
Changes request validation behavior across all providers on /v1/messages and count_tokens; clients that relied on silent drops now get 400 unless drop_params is enabled.

Overview
Backport of validation fixes for Anthropic-native /v1/messages and count_tokens: user or system text blocks that are null, numeric, or otherwise not strings are no longer stripped silently and sent upstream. Without drop_params, both routes now fail locally with 400 and a field path (messages.N.content.M.text or system.N.text); with drop_params, those blocks are dropped, and if nothing remains the request gets a clear emptied messages error.

Empty-block stripping in strip_empty_content_blocks_from_anthropic_messages is refactored so non-string user text is preserved for validation/dropping while assistant non-string text is still stripped. New helpers in convertible_blocks implement detection, optional dropping, and BadRequestError raising; prepare_native_messages runs cleaned_native_messages / cleaned_native_system before cache injection. The messages dispatcher keeps requests with malformed user/system text on Python (not Rust). The proxy token-count path applies the same normalization and drop_params precedence as inference.

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

…nd count_tokens unless drop_params

(cherry picked from commit f34fe32)

Folds the follow-up commits of the same change, adapted to lts/1.108.x:
ebf299d (400 when dropping leaves no message),
10de3e1 (keep empty text in place so the 400 names the client index),
8f458da (answer the 400 locally on every provider, inference and count_tokens),
913580c (tool_result text keeps its existing path).

LTS adaptations: the user text rule lives in
litellm/llms/anthropic/pass_through/convertible_blocks.py and runs in
prepare_native_messages, which on this line runs before every backend
(native, Responses bridge, chat bridge, websearch), so main's adapter,
responses adapter, websearch and provider count edits are not needed here.
count_request_tokens applies the same rule before any provider count,
taking drop_params from the request, then the router defaults, then the
deployment, as inference does.
The tool_result non-string text rule is not on this line, so tool_result
handling is unchanged.
With Rust opted in, a null or non-string user text block went to the
Rust handler, which strips it and answers 200. Python answers 400 for
it unless drop_params drops it, so route those requests to Python.

(cherry picked from commit a24a385)

LTS adaptation: this line has no route feature catalog or detectors
module, so the rule is a bypass in litellm/messages/dispatch.py
_python_serves. Because every such request now stays on Python, the
native Rust and rust_bridge host follow-ups of the same change are folded
here and not carried: eb16928, db6801b, 74ccdd8,
0b4cc98, 6012bc2.
…e a non-string tool_result text

A non-string text inside a tool_result skipped the empty-block strip for the whole request on Python-path providers, and turned off the web search short-circuit. Both now run as on main, and only a top-level user text skips the short-circuit, since the route rejects or drops it

(cherry picked from commit 5f60fd8)

LTS adaptation: the source half is already this line's behavior, since
native_messages_to_send here never had the unstripped branch and the web
search handler here never gained the guard, so only the three tests are
ported, onto the pass_through paths.
The emptied-messages 400 now fires only when the client sent a non-string user text and nothing is left after the cleanup, so a blank-only body reaches Gemini as its blank user turn and count_tokens counts the client's body

(cherry picked from commit c53d947)

LTS adaptation: the source's checks live in pass_through/convertible_blocks.py here and read
non_string_user_text_error. The non-string system text and Rust handler halves have no code
on this line (no billing-header filter, no litellm/rust), so only the count_tokens, router and
Gemini adapter tests are ported.
@edvinsq
edvinsq requested a review from a team November 24, 2026 19:48
@veria-ai

veria-ai Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

PR overview

No security issues were found in this pull request.

Reviews

@codecov

codecov Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 99.28058% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
litellm/proxy/proxy_server.py 95.83% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@mateo-berri mateo-berri changed the title fix(messages): answer 400 for a non-string user text block and keep count_tokens in step with inference (lts/1.108.x) fix(messages): answer 400 for a non-string user or system text block and keep count_tokens in step with inference (lts/1.108.x) Nov 24, 2026
@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@greptile-apps

greptile-apps Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge, with the previous test coverage issue fixed and no new findings

Summary

This PR rejects non-string user and system text with a 400, or drops those blocks when drop_params is on. Token counting shares the message cleanup used for inference. The latest change replaces the mocked body reader with real request bytes and addresses the previous finding. No new issues were found

  • Messages reject non-string user and system text unless dropping is enabled.
  • Malformed message bodies now stay on Python for validation.
  • Token counting prepares Anthropic messages the same way as inference.

Reviews (2) · Last reviewed commit: "test(proxy): send real request bytes thr..." · Reviewed by Greptile

@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor

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 1aaabcc. Configure here.

@mateo-berri mateo-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.

LGTM

@mateo-berri
mateo-berri merged commit 0944742 into BerriAI:lts/1.108.x Nov 25, 2026
63 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants