litellm/tests/unit/llms
zoveki 315c9d0d0e
fix(proxy): count a contents-only body on /utils/token_counter (#50710)
* fix(proxy): count a contents-only body on /utils/token_counter

The route now fills messages from Google-style contents when the caller sent none, using the same translation as the Google countTokens route, so the local count and the framed fallback can read the conversation instead of answering 500

* test(proxy): pin that a prompt sent with contents drops like one sent with messages

* test(integration): expect the Vertex partner custom_tokenizer to count a contents-only body

* fix(proxy): count Google bodies on /utils/token_counter like the countTokens route and reject unreadable contents

The route now maps systemInstruction and Google functionDeclarations tools through
the countTokens route's own translation, keeping the caller's system and OpenAI or
Anthropic tools. A contents entry without a parts list, or an unreadable
systemInstruction, answers 400 naming the field on both count routes instead of 500.
Same-name function calls in one turn get numbered ids that their responses answer,
so Claude no longer rejects them as duplicate tool results

* fix(google_genai): pair each function response with its call by id or order across turns

A function response now answers the call that carries its id, else the
oldest unanswered call of the same name, even when the responses come in a
later turn. Calls without an id get call_<name>, then numbered ids that skip
any id the conversation already uses, so search and search_1 no longer clash.
The pairing sorts once instead of scanning every earlier call.

An unreadable systemInstruction now answers 400 with the JSON path of the bad
field and the kind of value it expected.

* fix(google_genai): keep tool call ids short and stable and skip system media on /utils

Caller ids now only pair each function response with its call. They are no
longer sent upstream, so a long caller id no longer gets OpenAI's 64 character
400. A null or non-string id is read as no id instead of dropping the part.

The first call of each name keeps call_<name>, and a later call of the same
name gets call<n> from its position in the conversation. Ids no longer grow
with the name, and an earlier turn keeps its ids when later turns add calls.

/utils/token_counter counts the text of a systemInstruction and skips a part
with only media, instead of answering 400 for a body Google accepts.

* fix(google_genai): pair a tool response with the latest call before it and count entries without parts

A function response without a matching caller id now pairs with the earliest
unanswered call of the same name in the latest model turn before it, so a call
the user skipped stays unanswered and the later call keeps its result.

A contents entry without parts counts as an empty turn on both count routes,
the way Google's own countTokens and the generateContent route read it, and
/utils/token_counter names the exact field when parts or an entry has the
wrong type.

* fix(gemini): count a contents entry without parts instead of answering 500

The Gemini count handler read parts off every entry, so a contents entry
without parts, which Google counts as an empty turn, answered 500 on both
count routes. It now sends that entry to Google as the caller wrote it.

* fix(google_genai): pair reused caller ids and answer skipped calls

A function response now pairs with the latest unanswered call that has its
caller id, so ids reused across turns or restarted per turn pair with the call
they were sent for. A call a later turn left unanswered gets the same skipped
result modify_params adds, so OpenAI and Bedrock Converse accept the
conversation. /utils/token_counter keeps an OpenAI tool sent without type

* fix(google_genai): list skipped results after the answers to their turn

A model reads parallel tool results in order, so a skipped result listed before
the caller's answers made GPT give Paris the skipped result and Rome the Paris
forecast. A skipped result now follows the answers the next turn sent, which
is the order the modify_params filler uses

* fix(google_genai): list skipped results after every answer to their turn

When the caller split the answers to one model turn across two user turns, the
skipped result went between them and GPT read it as the second answer. A
skipped result now follows the last user turn that answers its model turn

* fix(google_genai): keep skipped results after answers split by empty or text turns

A skipped result now goes after the last answer before the next model turn. An empty or text-only user turn between split answers used to end the search early, so GPT read the later answer as the skipped call's result

* revert(google_genai): leave Google tool call pairing out of the token counter fix

Repeated function call pairing in GoogleGenAIAdapter is a separate translation bug that also affects
countTokens and generateContent, so it moves to its own change. This restores the adapter, the shared
skipped tool result helper, and their tests to the merge base.

---------

Co-authored-by: mateo-berri <277851410+mateo-berri@users.noreply.github.com>
2026-11-26 01:21:21 +00:00
..
a2a refactor(typing): clear about 1,100 basedpyright Any errors across 303 files (#49986) 2026-11-06 13:31:15 -08:00
aiml
aiohttp_openai fix(aiohttp_openai): forward service_tier in transform_response (#47263) 2026-10-28 13:14:44 -07:00
anthropic fix(anthropic): map /v1/messages fields onto OpenAI Responses equivalents or reject them (#54173) 2026-11-25 19:30:01 +00:00
apiserpent
aws_polly fix(aws_polly): read the engine from the bare model name (#47963) 2026-10-23 18:10:51 -07:00
azure fix(azure): send the deployment's api_version on async audio transcriptions (#53400) 2026-11-26 01:19:16 +00:00
azure_ai fix(responses): reject an unresolvable previous_response_id on the chat completions bridge (#53766) 2026-11-25 13:32:42 +00:00
base_llm fix(streaming): keep streamed usage when SSE lines without data precede the usage event (#54052) 2026-11-25 20:31:21 +00:00
baseten fix(aiand)!: show ai&'s name and logo, and sync ai&'s model list (#49158) 2026-10-30 10:55:26 -07:00
bedrock fix(embeddings): send request-shaped extra_body fields at the provider's documented path (#54273) 2026-11-25 13:29:52 -08:00
bedrock_mantle fix(bedrock_mantle): drop the JSON Schema keywords gemma-4 rejects from tool and response schemas (#54214) 2026-11-25 07:04:08 +00:00
bigmodel fix(responses): preserve incomplete status in synthetic streams (#52489) 2026-11-19 22:24:50 -08:00
black_forest_labs
brave
bytez
cerebras
chat
chatgpt refactor(typing): clear 1146 basedpyright Any errors across 365 files (#52768) 2026-11-21 04:25:33 +00:00
clarifai
claude_code
clf_ai_gateway refactor(router): route the router family through RoutingContext and close the outside surface (#49118) 2026-10-30 19:18:54 -07:00
cloudflare fix(streaming): keep merged think tags balanced and split SSE lines only on CR/LF (#48755) 2026-10-28 17:00:29 -07:00
codestral fix(streaming): keep merged think tags balanced and split SSE lines only on CR/LF (#48755) 2026-10-28 17:00:29 -07:00
codex
cohere fix(cohere)!: map tool_choice, reasoning_effort and json_schema response_format on the v2 chat route (#50834) 2026-11-17 18:10:37 +00:00
cometapi
compactifai refactor(typing): clear 1181 basedpyright Any errors across 431 files (#47789) 2026-10-24 11:31:09 -07:00
crusoe
custom_httpx fix(router,files,batches)!: never resend a file or batch create the provider may already have (#51315) 2026-11-25 07:20:51 +00:00
dashscope refactor(cost): price generic_cost_per_token with the native calculate (#52816) 2026-11-23 22:00:27 +00:00
databricks fix(streaming): keep streamed usage when SSE lines without data precede the usage event (#54052) 2026-11-25 20:31:21 +00:00
dataforseo refactor(typing): clear about 1,100 basedpyright Any errors across 303 files (#49986) 2026-11-06 13:31:15 -08:00
datarobot
deepagents
deepgram fix(audio-transcription): keep transcripts out of transcription error messages (#50137) 2026-11-05 18:07:15 -08:00
deepinfra chore(cost-map): add Soniox v6 and date Soniox, Bedrock Claude and Azure Whisper retirements (#51620) 2026-11-13 12:37:12 -08:00
deepseek fix(token_counter): count an Anthropic fallback block as zero on every count route (#54006) 2026-11-24 03:32:34 -08:00
docker_model_runner
duckduckgo
e2b
edenai feat(videos): add first-class OpenRouter video request fields (#50319) 2026-11-06 16:50:48 -08:00
elevenlabs feat(elevenlabs): add scribe_v2_realtime realtime transcription (#48984) 2026-11-25 03:15:34 +00:00
empiriolabs feat(decisions): add EmpirioLabs AI as a decisions provider (#49977) 2026-11-04 10:41:16 -08:00
exa_ai fix(exa): return highlights, highlight scores, score and the response envelope from Exa search (#47423) 2026-10-19 15:45:56 -07:00
fal_ai fix(cost-map): price eight-second Pixverse clips (#52107) 2026-11-16 12:49:55 -08:00
fastcrw
featherless_ai
firecrawl
fireworks_ai fix(llms): send later system messages as user turns for models declared system-first (#54347) 2026-11-25 11:48:27 +00:00
friendliai fix(friendliai): drop litellm-internal message fields before sending (#45092) 2026-10-20 01:22:07 +00:00
gdc
gemini fix(proxy): count a contents-only body on /utils/token_counter (#50710) 2026-11-26 01:21:21 +00:00
gigachat refactor(typing): clear about 1,100 basedpyright Any errors across 303 files (#49986) 2026-11-06 13:31:15 -08:00
github_copilot fix(github_copilot): look up a GHE.com shared login's Copilot API on its own tenant (#54366) 2026-11-25 08:30:23 +00:00
gnani feat(gnani): add Prisma v2.5 and v3.0 realtime transcription (#53828) 2026-11-25 10:51:59 +00:00
google_pse
gradient_ai
gradium feat(gradium): add text-to-speech support for /v1/audio/speech (#46427) 2026-11-21 23:51:27 +00:00
groq fix(groq): default service_tier when the reply omits it (#52431) 2026-11-18 13:17:14 -08:00
heroku
hosted_vllm fix(llms): send later system messages as user turns for models declared system-first (#54347) 2026-11-25 11:48:27 +00:00
huggingface fix(huggingface): honor HUGGINGFACE_API_BASE and env endpoints for chat (#51449) 2026-11-13 10:35:34 -08:00
hyperbolic
inception
infinity
jina_ai fix(rerank): preserve provider usage and reported costs (#53893) 2026-11-23 19:59:34 -08:00
lambda_ai
langflow
langgraph fix(streaming)!: fail a stream that ends without a finish reason (#47665) 2026-10-31 11:29:26 -07:00
laya
lemonade fix(ollama): send model-info lookups to the call's api_base with its key and retry failed ones (#53830) 2026-11-24 08:51:25 -08:00
linkup
litellm_proxy refactor(typing): clear about 1,100 basedpyright Any errors across 303 files (#49986) 2026-11-06 13:31:15 -08:00
llamafile
lm_studio
manus
meta
meta_llama
microsoft_365_copilot refactor(router): route the router family through RoutingContext and close the outside surface (#49118) 2026-10-30 19:18:54 -07:00
milvus
minimax feat(minimax): add MiniMax-H3-Image generation and edit support (#50881) 2026-11-24 05:54:43 +00:00
mistral fix(mistral): drop message fields Mistral rejects when drop_params is on (#53962) 2026-11-24 02:33:58 +00:00
modelscope
mongodb fix(exceptions): keep the provider error body on e.response for SDK callers (#53587) 2026-11-23 07:23:53 +00:00
moonshot feat(moonshot): add Kimi K3 and Together AI Inkling model support (#33922) 2026-11-18 16:26:14 +00:00
morph feat(morph): support open models and cached input pricing (#48676) 2026-10-27 18:06:14 -07:00
nadir
nebius
neosantara
nimble
nlp_cloud refactor(typing): clear 1141 basedpyright Any errors across 182 files (#50711) 2026-11-11 22:11:47 +00:00
novita
nscale
nvidia_nim fix(nvidia_nim): forward logprobs and top_logprobs to NIM models that serve them (#54008) 2026-11-23 22:18:59 -08:00
nvidia_riva fix(nvidia_riva): send the api key exactly once by calling riva over grpc directly (#50140) 2026-11-04 18:07:31 -08:00
oci fix(mcp): drop hosted MCP tool_choice under drop_params and honor drop_params in Bedrock batch rows (#53697) 2026-11-23 08:51:59 -08:00
ocr
ollama fix(ollama): send model-info lookups to the call's api_base with its key and retry failed ones (#53830) 2026-11-24 08:51:25 -08:00
oobabooga fix(streaming): keep merged think tags balanced and split SSE lines only on CR/LF (#48755) 2026-10-28 17:00:29 -07:00
openai fix(anthropic): map /v1/messages fields onto OpenAI Responses equivalents or reject them (#54173) 2026-11-25 19:30:01 +00:00
openai_like feat(huawei_maas): add Huawei Cloud MaaS provider and cost map rows (#54225) 2026-11-24 18:24:05 -08:00
opencode fix(anthropic)!: send extra_body fields at the top level of the Messages request (#48373) 2026-11-20 06:52:56 -08:00
openrouter fix(openrouter): report the context window and output cap from OpenRouter's catalog (#54046) 2026-11-24 04:37:30 -08:00
opensandbox
opensearch feat(opensearch): map vector store search filters to k-NN filters and add hybrid search (#51131) 2026-11-14 03:30:55 +00:00
ovhcloud fix(audio-transcription): keep transcripts out of transcription error messages (#50137) 2026-11-05 18:07:15 -08:00
parallel_ai refactor(rust_bridge): route every Rust-to-Python call through host modules (#50822) 2026-11-11 01:57:54 +00:00
parasail
pass_through fix(guardrails): exclude litellm_metadata from pass-through guardrail scan text (#48276) 2026-10-26 12:07:58 -07:00
perplexity fix(perplexity): let every Agent API model take chat tools unless the cost map says no (#54047) 2026-11-24 05:46:28 +00:00
pg_vector
pi fix(harness): surface Pi context compaction events (#52655) 2026-11-18 13:52:03 -08:00
publicai
ragflow
recraft refactor(typing): clear about 1,100 basedpyright Any errors across 303 files (#49986) 2026-11-06 13:31:15 -08:00
reducto fix(ollama): send model-info lookups to the call's api_base with its key and retry failed ones (#53830) 2026-11-24 08:51:25 -08:00
replicate refactor: share Replicate HTTP client factories and declare PagerDuty type alias (#51594) 2026-11-17 02:32:54 +00:00
runwayml feat(videos): add first-class OpenRouter video request fields (#50319) 2026-11-06 16:50:48 -08:00
s3_vectors refactor(router): move router callers onto the entry points and invert the proxy imports (#48847) 2026-10-29 17:26:33 +00:00
sagemaker fix(embeddings): send request-shaped extra_body fields at the provider's documented path (#54273) 2026-11-25 13:29:52 -08:00
sail test(router_strategy): keep foreign asyncio task noise out of the budget limiter caplog asserts (#43375) 2026-10-29 06:22:06 -07:00
sambanova
sap fix(sap): token cache (#49260) 2026-11-23 06:03:52 +00:00
scaledown
scaleway fix(rerank): preserve provider usage and reported costs (#53893) 2026-11-23 19:59:34 -08:00
searchapi
searxng
serper
snowflake fix(anthropic): skip a stream data line that is not a JSON object (#53393) 2026-11-22 22:54:02 +00:00
soniox chore(cost-map): add Soniox v6 and date Soniox, Bedrock Claude and Azure Whisper retirements (#51620) 2026-11-13 12:37:12 -08:00
stability
strands_decider
tavily fix(tavily): return raw_content, score, favicon and the response envelope from Tavily search (#48684) 2026-10-27 18:52:06 -07:00
tencent fix(logging): warn when drop_params drops a requested reasoning level on the remaining paths (#48933) 2026-10-30 08:48:43 -07:00
tinyfish
together_ai fix(together_ai): declare reasoning_effort_levels on Kimi-K3.1-Pro so max is not sent as high (#52294) 2026-11-17 08:20:41 -08:00
tool_loop
topaz
triton fix(streaming): keep merged think tags balanced and split SSE lines only on CR/LF (#48755) 2026-10-28 17:00:29 -07:00
v0
valkey
vercel_ai_gateway
vertex_ai fix(embeddings): send request-shaped extra_body fields at the provider's documented path (#54273) 2026-11-25 13:29:52 -08:00
vllm fix(vllm): list hosted_vllm wildcard models when the server has no api key (#40066) 2026-11-03 04:13:28 +00:00
volcengine fix(proxy): forward limit, order, after, before and include on GET /v1/responses/{id}/input_items (#51259) 2026-11-20 07:54:26 -08:00
voyage fix(voyage): honor VOYAGE_API_BASE for embeddings (#52645) 2026-11-18 14:38:57 -08:00
wandb
watsonx fix(openai_like): honor the deployment timeout and stream_timeout on async streams (#53442) 2026-11-22 21:52:59 +00:00
webiq feat(search): add Microsoft Web IQ provider (#50883) 2026-11-10 22:43:36 +00:00
xai fix(xai): honor deployment image pixel pricing (#50490) 2026-11-07 02:17:16 +00:00
xinference
you_com
zai fix(zai): accept reasoning_effort so /v1/messages thinking reaches GLM models (#54279) 2026-11-25 04:56:45 +00:00
__init__.py
test_api_base_trailing_slash_routes.py fix(llms): join api_base and route with one shared helper (#47535) 2026-10-21 06:59:32 +00:00
test_cache_control_and_reasoning.py fix(minimax): forward reasoning_effort instead of dropping it (#49583) 2026-11-09 14:03:50 -08:00
test_custom_llm.py refactor(rust_bridge): route every Rust-to-Python call through host modules (#50822) 2026-11-11 01:57:54 +00:00
test_file_content_block.py fix(prompt_templates): keep moved private helpers importable from common_utils (#50721) 2026-11-09 20:52:52 +00:00
test_file_search_responses.py refactor(prompt_templates): move JSON schema helpers out of common_utils into json_schema_utils (#50241) 2026-11-05 17:25:53 -08:00
test_get_complete_url_trailing_slash.py feat(elevenlabs): add scribe_v2_realtime realtime transcription (#48984) 2026-11-25 03:15:34 +00:00
test_lifecycle_fix.py
test_oss_decision.py
test_polling_url_origin_match.py
test_predibase_transformation.py fix(streaming): keep merged think tags balanced and split SSE lines only on CR/LF (#48755) 2026-10-28 17:00:29 -07:00
test_subscription_accounts.py feat(usage): show subscription-covered providers and account fees separately (#44772) 2026-10-30 03:58:36 -07:00