litellm/tests/llm_translation
Tim Ren dd4a41951f
fix(utils): allowed_openai_params must not forward unset params as None (#25777)
* feat(proxy): add NO_OPENAPI env var to disable /openapi.json endpoint (#25696)

* feat(proxy): add NO_OPENAPI env var to disable /openapi.json endpoint - Fixes #25538

* test(proxy): add tests for _get_openapi_url

---------

Co-authored-by: Progressive-engg <lov.kumari55@gmail.com>

* feat(prometheus): add api_provider label to spend metric (#25693)

* feat(prometheus): add api_provider label to spend metric

Add `api_provider` to `litellm_spend_metric` labels so users can
build Grafana dashboards that break down spend by cloud provider
(e.g. bedrock, anthropic, openai, azure, vertex_ai).

The `api_provider` label already exists in UserAPIKeyLabelValues and
is populated from `standard_logging_payload["custom_llm_provider"]`,
but was not included in the spend metric's label list.

* add api_provider to requests metric + add test

Address review feedback:
- Add api_provider to litellm_requests_metric too (same call-site as
  spend metric, keeps label sets in sync)
- Add test_api_provider_in_spend_and_requests_metrics following the
  existing pattern in test_prometheus_labels.py

* fix: ensure `litellm_metadata` is attached to `pre_call` guardrail to align with `post_call` guardrail (#25641)

* fix: ensure `litellm_metadata` is attached to pre_call to align with post_call

* refactor: remove unused BaseTranslation._ensure_litellm_metadata

* refactor: module level imports for ensure_litellm_metadata and CodeQL

* fix: update based off of Codex comment

* revert: undo usage of `_guardrail_litellm_metadata`

* feat: add pricing entry for openrouter/google/gemini-3.1-flash-lite-preview (#25610)

* fix(bedrock): skip synthetic tool injection for json_object with no schema (#25740)

When response_format={"type": "json_object"} is sent without a JSON
schema, _create_json_tool_call_for_response_format builds a tool with an
empty schema (properties: {}). The model follows the empty schema and
returns {} instead of the actual JSON the caller asked for.

This patch:
- Skips synthetic json_tool_call injection when no schema is provided.
  The model already returns JSON when the prompt asks for it.
- Fixes finish_reason: after _filter_json_mode_tools strips all
  synthetic tool calls, finish_reason stays "tool_calls" instead of
  "stop". Callers (like the OpenAI SDK) misinterpret this as a pending
  tool invocation.

json_schema requests with an explicit schema are unchanged.

Co-authored-by: Claude <noreply@anthropic.com>

* fix(utils): allowed_openai_params must not forward unset params as None

`_apply_openai_param_overrides` iterated `allowed_openai_params` and
unconditionally wrote `optional_params[param] = non_default_params.pop(param, None)`
for each entry. If the caller listed a param name but did not actually
send that param in the request, the pop returned `None` and `None` was
still written to `optional_params`. The openai SDK then rejected it as
a top-level kwarg:

    AsyncCompletions.create() got an unexpected keyword argument 'enable_thinking'

Reproducer (from #25697):

    allowed_openai_params = ["chat_template_kwargs", "enable_thinking"]
    body = {"chat_template_kwargs": {"enable_thinking": False}}

Here `enable_thinking` is only present nested inside
`chat_template_kwargs`, so the helper should forward
`chat_template_kwargs` and leave `enable_thinking` alone. Instead it
wrote `optional_params["enable_thinking"] = None`.

Fix: only forward a param if it was actually present in
`non_default_params`. Behavior is unchanged for the happy path (param
sent → still forwarded), and the explicit `None` leakage is gone.

Adds a regression test exercising the helper in isolation so the test
does not depend on any provider-specific `map_openai_params` plumbing.

Fixes #25697

---------

Co-authored-by: lovek629 <59618812+lovek629@users.noreply.github.com>
Co-authored-by: Progressive-engg <lov.kumari55@gmail.com>
Co-authored-by: Ori Kotek <ori.k@codium.ai>
Co-authored-by: Alexander Grattan <51346343+agrattan0820@users.noreply.github.com>
Co-authored-by: Mohana Siddhartha Chivukula <103447836+iamsiddhu3007@users.noreply.github.com>
Co-authored-by: Amiram Mizne <amiramm@users.noreply.github.com>
Co-authored-by: Claude <noreply@anthropic.com>
2026-04-16 19:04:26 +05:30
..
fixtures
realtime build: migrate packaging, CI, and Docker from Poetry to uv (#25007) 2026-04-09 11:46:23 -07:00
test_llm_response_utils fix(types): normalize null top_logprobs to [] in ChatCompletionTokenLogprob (#22245) 2026-02-28 15:59:29 -08:00
test_skills_data Remove Apache 2 license from SKILL.md (#22322) 2026-02-27 19:33:55 -08:00
test-skill
base_audio_transcription_unit_tests.py
base_embedding_unit_tests.py
base_llm_unit_tests.py Fix mistral ocr failing test 2026-03-09 11:29:33 +05:30
base_rerank_unit_tests.py
conftest.py [Fix] Restore unconditional importlib.reload for llm_translation conftest 2026-03-16 00:35:02 -07:00
dog.wav
duck.png
gettysburg.wav
guinea.png
log.xt
Readme.md
test_a2a.py
test_anthropic_completion.py Merge pull request #24445 from quora/fix/missing-content-part-added 2026-03-30 17:52:40 -07:00
test_aws_base_llm.py
test_azure_agents.py fix(azure-ai-agents): accumulate annotations from multiple text items in streaming 2026-03-18 09:04:00 +05:30
test_azure_ai.py test_completion_azure 2026-03-30 21:54:27 -07:00
test_azure_o_series.py test: test 2026-03-28 19:17:38 -07:00
test_azure_openai.py Litellm ishaan april15 2 (#25828) 2026-04-15 18:42:23 -07:00
test_bedrock_agentcore.py
test_bedrock_agents.py
test_bedrock_anthropic_regression.py Litellm fix update bedrock models (#24947) 2026-04-01 19:22:54 -07:00
test_bedrock_common_utils.py Litellm fix update bedrock models (#24947) 2026-04-01 19:22:54 -07:00
test_bedrock_completion.py fix(bedrock): custom tool schemas and missing tool names for Converse 2026-04-09 10:39:00 +05:30
test_bedrock_dynamic_auth_params_unit_tests.py
test_bedrock_embedding.py
test_bedrock_govcloud.py [Test Fix] fix gov pricing tests (#25022) 2026-04-02 15:55:55 -07:00
test_bedrock_gpt_oss.py [Test] add request-body mock test for bedrock gpt-oss tool schema 2026-04-14 19:36:57 -07:00
test_bedrock_invoke_tests.py Litellm fix update bedrock models (#24947) 2026-04-01 19:22:54 -07:00
test_bedrock_llama.py
test_bedrock_moonshot.py
test_bedrock_nova_embedding.py fix(cost-calc): use per-image pricing for Bedrock multimodal embeddings (#21646) 2026-02-20 08:51:21 -08:00
test_bedrock_nova_json.py
test_cloudflare.py test_completion_cloudflare 2026-03-30 16:40:37 -07:00
test_cohere.py Revert "Fix xdist test isolation: capture true defaults and poll instead of sleep" 2026-03-15 22:57:39 -07:00
test_containers_api.py
test_convert_dict_to_image.py
test_databricks.py [Fix] test_databricks: don't assert stream in request body when not passed 2026-04-11 13:19:39 -07:00
test_deepgram.py
test_deepseek_completion.py
test_elevenlabs.py
test_evals_api.py fix(tests): add flaky retries to flaky CI tests (#21795) 2026-02-21 11:56:29 -08:00
test_fireworks_ai_translation.py fix: fix setup wizard 2026-03-30 09:06:31 -07:00
test_gemini_image_usage.py fix(gemini): resolve image token undercounting in usage metadata (#22608) 2026-03-04 18:52:08 -08:00
test_gemini.py [Fix] Update gemini-2.0-flash to gemini-2.5-flash in test_gemini integration tests 2026-03-30 13:53:38 -07:00
test_gigachat.py
test_gpt4o_audio.py
test_groq.py
test_hosted_vllm_embedding_e2e.py move e2e to llm translation 2026-02-17 22:33:13 +05:30
test_huggingface_chat_completion.py
test_hyperbolic.py
test_infinity.py
test_jina_ai.py
test_lambda_ai.py
test_langgraph.py
test_litellm_proxy_provider.py
test_minimax_tts.py
test_mistral_api.py
test_model_cost_map_resilience.py [Stability] Investigate + fix issue where model cost map became poorly formatted (#20895) 2026-02-10 15:17:01 -08:00
test_morph.py
test_nvidia_nim.py
test_openai_o1.py fix(tests): update outdated model names in o1 and gemini tests 2026-03-12 22:50:52 -07:00
test_openai.py Fix _supports_reasoning_effort_level for responses bridge 2026-03-13 13:29:39 +05:30
test_openrouter.py fix(test): update openrouter image generation assertion for gemini-2.5-flash-image (#23070) 2026-03-07 16:52:04 -08:00
test_optional_params.py fix(utils): allowed_openai_params must not forward unset params as None (#25777) 2026-04-16 19:04:26 +05:30
test_perplexity_reasoning.py
test_prompt_caching.py
test_prompt_factory.py [Infra] Merge internal dev branch with main (#25036) 2026-04-02 16:38:01 -07:00
test_replicate.py
test_rerank.py refactor: refactor testing 2026-03-28 18:39:32 -07:00
test_router_llm_translation_tests.py test: test 2026-03-28 19:17:38 -07:00
test_sambanova_chat_transformation.py
test_skills_api.py Reapply "feat: add model_cost aliases expansion support" 2026-03-12 13:36:57 -03:00
test_skills_e2e.py
test_snowflake.py Merge main and resolve Snowflake test conflict 2026-03-30 18:06:37 -07:00
test_text_completion_unit_tests.py
test_text_completion.py
test_together_ai.py [Fix] Test - Together AI: replace deprecated Mixtral with serverless Qwen3.5-9B 2026-04-14 17:43:35 -07:00
test_triton.py feat(triton): add embedding usage estimation for self-hosted responses (#25345) 2026-04-08 21:14:27 -07:00
test_unit_test_bedrock_invoke.py
test_v0.py
test_voyage_ai.py
test_watsonx.py [Fix] WatsonX tests failing on CI due to missing env vars 2026-03-30 13:27:03 -07:00
test_xai.py Fix usage in xai 2026-02-19 18:48:30 +05:30

Unit tests for individual LLM providers.

Name of the test file is the name of the LLM provider - e.g. test_openai.py is for OpenAI.