litellm/tests/unit/llms
hcl 8fb724f7da
fix(gemini): return an error instead of an empty 200 when a Gemini image request gets no image (#29125)
* fix(gemini): surface finishReason on image-gen safety blocks

Image-gen transforms iterated candidates[].content.parts[] for inlineData
and ignored finishReason, so an IMAGE_SAFETY / IMAGE_PROHIBITED_CONTENT
block returned an empty ImageResponse with no exception. The chat path
already surfaces these (get_flagged_finish_reasons + ContentPolicyViolationError);
mirror that for image gen by raising on a flagged finishReason when no image
data was produced. Covers gemini/ and vertex_ai/ via one shared helper.

Fixes #28989

* fix(gemini): also surface blocked prompts and image-edit safety blocks

promptFeedback.blockReason with no candidates now raises
ContentPolicyViolationError like a flagged finishReason, and the gemini/
and vertex_ai/ image-edit transforms use the same check when they return
no image.

* fix(gemini): return an error instead of an empty 200 when a Gemini image request gets no image

A refused image or a blocked prompt answers 400 content_policy_violation with
Gemini's finishReason and finishMessage, or its blockReason. Any other answer
without an image answers 422 with the model's text. Both cover AI Studio and
Vertex on image generations and image edits, and neither is billed or retried

* fix(gemini): bill a no-image answer's tokens and keep model text out of the 422

A Gemini or Vertex image answer without an image and without a refusal still bills its tokens on the failure log, as main billed the empty 200. Refusals and blocked prompts stay at $0. The 422 message names only the finishReason, so model output never reaches the exception text or logs

* fix(gemini): bill images served beside a failed answer when n is above 1

A refused or image-less answer in a fan-out no longer drops the cost of the
images its siblings returned. OTHER and LANGUAGE now answer 422 like
IMAGE_OTHER, and the 422 no longer carries the model's text in its response

* fix(gemini): bill Gemini image refusals Google charges for and keep token details on failure logs

Google charges for an image refusal that comes back as HTTP 200, except IMAGE_RECITATION, whose answer says the request is not charged. Those refusals now bill their tokens on the failure log, as a blocked prompt does. Billed failure rows keep reasoning, cached and image token details

* fix(images): report a billed failure's cost header and keep refused image health probes healthy

A failed image request that bills tokens now answers with an
x-litellm-response-cost header that matches its failure spend row. The
generations route sent no cost header on errors, and errors that went
through the shared error handler reported 0 unless the logging object
had a finalized cost

The image_generation health probe now counts a refusal or a Gemini
answer without an image as healthy, like the image_edit probe already
did for refusals, so a refused probe prompt does not mark the
deployment unhealthy

* fix(images): return served images when another of n answers has no image

With n above 1, an answer Gemini refused or answered without an image no
longer fails the whole request when another answer served an image. The
served images come back and the refusals Google charges for are billed
with them. The request fails only when no answer served an image

* fix(proxy): record what a refused image health probe billed

A health probe that the provider billed but that ends in an image error now writes a failure spend row under the internal health check key in both spend modes, and the text-only Vertex integration cases expect 422 with the same spend

* fix(images): bill a failed Gemini image attempt when a fallback serves the request

A billed text-only or blocked answer was dropped from spend once a fallback returned the image. The cost header, spend row and key spend now include it

* fix(images): keep the failed attempt charge on unpriced fallbacks and collector rows

* fix(images): keep billing, alerts, and errors correct when Gemini answers without an image

* fix(gemini): count billed image refusals in budgets once and never as deployment failures

A billed refusal or no-image answer now counts once toward deployment,
provider, tag, key model and session budgets, and a served fallback's
success counts only its own cost there. Only these errors opt the budget
hooks into per-attempt failure events. They no longer count toward a
deployment's failure rate, and a failure row after an already logged
success lifts only the attempts that success did not bill, so Prometheus
counts a served image's spend once.

* fix(gemini): bill image refusals once across stream headers, Prometheus and token columns, and ignore request params named after billing fields

* fix(prometheus): keep a deployment that answered an image prompt without an image marked healthy

A refusal or an answer without an image skipped the deployment state update, so a deployment that only refused had no litellm_deployment_state sample. It now writes 0, as a served answer does on main

* fix(prometheus): count an image prompt answered without an image as a deployment success

A refusal or an answer without an image added to litellm_deployment_total_requests but to neither the success nor the failure counter, so a refusing deployment's success rate dropped. It now counts as a success, as it did when these answers were 200s

* fix(router): return a fallback's image refusal after an earlier failure

A 5xx followed by a fallback refusal raised the 5xx, so the OpenAI SDK
retried and billed the whole chain 3 times. Refused and empty image
answers also keep the request's custom Prometheus metadata labels, and a
no-log refusal no longer adds to the spend and token counters.

* fix(proxy): log a fallback's image refusal on the deployment that answered

When the client gets a fallback's refusal or 422 after an earlier model
failed another way, its failure row, Prometheus spend and request labels
now go on that fallback's deployment instead of the first one. Prometheus
also counts that attempt in the fallback deployment's success and total
counters, and the billed spend metrics label requested_model with the
group that answered.

* fix(router): count an image answer without an image toward deployment tpm limits, return the first refusal in a fallback chain, and keep refusals out of the Slack failed-request report

* fix(router): count an image refusal toward deployment tpm limits on sync calls and on fallback attempts

* fix(router): store an attempt's answered tokens as a 32-bit count so rust-lint passes

The answered_tokens field 20fadb7 added made the router's attempt error
large enough for clippy's result_large_err lint. A 32-bit count fits the
error's existing padding and holds any token count Gemini reports.

* fix(proxy): count a billed image refusal toward key, team and user tpm limits even with no output tokens

* fix(router): store an attempt's exception classes as a boxed slice so rust-lint passes after merging main

* fix(proxy): count every billed image refusal of a fallback chain toward token limits

* test(proxy): annotate the refusal-after-settlement test bindings as Final

* fix(images): bill every refused answer of an n>1 image request toward the router's model group usage

A refusing multi-image request raised its first unserved answer with only that
answer's billing, so the router's model group usage missed the sibling answers'
tokens. The raised error now carries the summed billing of every answer.

Also waits for the sync success log in the usage-based-routing-v2 sync fallback
test, which raced the logging thread.

* fix(prometheus): keep custom metadata labels off a no-log image refusal's request counters

* fix(rate limits): count a billed image refusal like a served answer in the limiter, and give back an unbilled recitation's reservation

A billed refusal now settles in the Rust limiter the way a served answer does, so its
tokens count toward the key, team and user tpm limits also with token reservation off,
and toward the model limit on the key of the fallback that refused. A recitation bills
nothing, so it takes the plain failure path and gives back its tpm and otpm reservation
instead of being settled as a billed answer with no tokens.

* fix(rate limits): count a billed refusal's input tokens toward project itpm on every fallback attempt under an output token limit

* test(rate limits): assert project itpm after each refused fallback attempt instead of looping

* test(rust router): build call_loop exception classes as a boxed slice

---------

Co-authored-by: mateo-berri <277851410+mateo-berri@users.noreply.github.com>
2026-11-25 20:55:23 +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 chore(typing): clear 670 basedpyright Any errors by validating provider payloads at the boundary (#45388) 2026-10-13 15:35:23 -07:00
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(router,files,batches)!: never resend a file or batch create the provider may already have (#51315) 2026-11-25 07:20:51 +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(bedrock): bill Nova audio and video embeddings by clip length when the deployment sets only a token price (#54304) 2026-11-25 19:57:58 +00: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 chore(typing): clear 670 basedpyright Any errors by validating provider payloads at the boundary (#45388) 2026-10-13 15:35:23 -07:00
bytez
cerebras
chat fix(router): read the first stream chunk before returning so a failure before any token runs through the retry and fallback budget (#46493) 2026-10-14 14:19:25 -07:00
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 chore(typing): clear 670 basedpyright Any errors by validating provider payloads at the boundary (#45388) 2026-10-13 15:35:23 -07:00
compactifai refactor(typing): clear 1181 basedpyright Any errors across 431 files (#47789) 2026-10-24 11:31:09 -07:00
crusoe fix(crusoe): update base URL to current endpoint (#33121) 2026-10-15 19:10:58 -07:00
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 chore(typing): clear 670 basedpyright Any errors by validating provider payloads at the boundary (#45388) 2026-10-13 15:35:23 -07:00
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 fix(llms): sanitize trailing slashes in provider get_complete_url (#42887) 2026-10-15 02:59:46 -07:00
featherless_ai
firecrawl fix(llms): sanitize trailing slashes in provider get_complete_url (#42887) 2026-10-15 02:59:46 -07:00
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(gemini): return an error instead of an empty 200 when a Gemini image request gets no image (#29125) 2026-11-25 20:55:23 +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 chore(typing): clear 670 basedpyright Any errors by validating provider payloads at the boundary (#45388) 2026-10-13 15:35:23 -07:00
gradient_ai fix(llms): sanitize trailing slashes in provider get_complete_url (#42887) 2026-10-15 02:59:46 -07:00
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 fix(llms): sanitize trailing slashes in provider get_complete_url (#42887) 2026-10-15 02:59:46 -07:00
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 chore(typing): clear 670 basedpyright Any errors by validating provider payloads at the boundary (#45388) 2026-10-13 15:35:23 -07:00
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 fix(llms): sanitize trailing slashes in provider get_complete_url (#42887) 2026-10-15 02:59:46 -07:00
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 test: migrate SDK and proxy-booting legacy CircleCI tests to their tiers (#45758) 2026-10-11 00:17:21 -07:00
meta fix(realtime)!: keep turn_detection.type when a transcript guardrail disables auto-response (#44939) 2026-10-16 15:24:40 +00:00
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 test: migrate legacy unit dirs and unrun folders into tests/unit, tests/integration and tests/e2e (#45940) 2026-10-11 06:24:57 -07:00
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 fix(llms): sanitize trailing slashes in provider get_complete_url (#42887) 2026-10-15 02:59:46 -07:00
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 chore(typing): clear 670 basedpyright Any errors by validating provider payloads at the boundary (#45388) 2026-10-13 15:35:23 -07:00
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 test: migrate tests/llm_translation into unit, integration and e2e tiers (#45759) 2026-10-11 07:58:53 +00:00
ragflow test: migrate legacy unit dirs and unrun folders into tests/unit, tests/integration and tests/e2e (#45940) 2026-10-11 06:24:57 -07:00
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(sagemaker,bedrock): answer 502 when a 200 AWS event stream decodes to no events or ends mid-frame (#53482) 2026-11-22 23:59:32 +00: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 chore(typing): clear 670 basedpyright Any errors by validating provider payloads at the boundary (#45388) 2026-10-13 15:35:23 -07:00
sap fix(sap): token cache (#49260) 2026-11-23 06:03:52 +00:00
scaledown feat(scaledown): add native text provider support (#44168) 2026-10-10 14:01:17 -07:00
scaleway fix(rerank): preserve provider usage and reported costs (#53893) 2026-11-23 19:59:34 -08:00
searchapi chore(typing): clear 670 basedpyright Any errors by validating provider payloads at the boundary (#45388) 2026-10-13 15:35:23 -07:00
searxng chore(typing): clear 670 basedpyright Any errors by validating provider payloads at the boundary (#45388) 2026-10-13 15:35:23 -07:00
serper chore(typing): clear 670 basedpyright Any errors by validating provider payloads at the boundary (#45388) 2026-10-13 15:35:23 -07:00
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 feat(strands_decider): call a Strands Decider on an AgentCore runtime ARN (#45678) 2026-10-09 22:51:19 -07:00
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 fix(llms): sanitize trailing slashes in provider get_complete_url (#42887) 2026-10-15 02:59:46 -07:00
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(gemini): return an error instead of an empty 200 when a Gemini image request gets no image (#29125) 2026-11-25 20:55:23 +00: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 feat(decisions): add Laya and Bespoke providers to the Add Model form (#45260) 2026-10-14 08:11:11 -07:00
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