litellm/tests/test_litellm/proxy
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
..
_experimental/mcp_server Merge remote-tracking branch 'origin/main' into worktree-foamy-jumping-coral 2026-04-15 18:29:55 -07:00
agent_endpoints test(a2a): assert create_a2a_client default timeout uses DEFAULT_A2A_AGENT_TIMEOUT 2026-04-10 21:18:15 +03:00
anthropic_endpoints Litellm ishaan march 20 (#24303) 2026-03-21 12:40:11 -07:00
auth fix(auth): gate post-custom-auth DB lookups behind opt-in flag (#25634) 2026-04-13 08:02:16 -07:00
client build: migrate packaging, CI, and Docker from Poetry to uv (#25007) 2026-04-09 11:46:23 -07:00
common_utils fix(budget): align budget table reset times with standardized calendar schedule (#25440) 2026-04-11 19:45:23 -07:00
db fix: make PodLockManager.release_lock atomic compare-and-delete (re-land #21226) (#24466) 2026-04-15 17:33:21 -07:00
discovery_endpoints feat: add control plane for multi-proxy worker management 2026-03-19 22:50:19 -07:00
experimental/mcp_server Litellm fix GitHub action testing (#11163) 2025-05-26 14:41:42 -07:00
google_endpoints fix: Metadata / Trace ID Missing in S3 Streaming Callbacks 2026-02-25 14:16:42 +05:30
guardrails fix(utils): allowed_openai_params must not forward unset params as None (#25777) 2026-04-16 19:04:26 +05:30
health_endpoints address review feedback 2026-04-11 21:52:39 -07:00
hooks Litellm ishaan april1 try2 (#25110) 2026-04-03 14:57:44 -07:00
image_endpoints fixing core proxy tests 2026-02-12 17:54:32 -08:00
management_endpoints Merge pull request #25665 from BerriAI/litellm_oss_staging_04_13_2026_p1 2026-04-14 23:50:08 +05:30
management_helpers fix(proxy): enforce team membership in team-scoped key management checks 2026-04-14 12:11:11 +03:00
middleware [Fix] Fix test failures and Docker build from pinned dependency upgrade 2026-04-01 09:43:33 -07:00
openai_files_endpoint Refactor file content streaming handling to improve routing and support 2026-04-11 18:56:15 +00:00
pass_through_endpoints fix(proxy): pass-through multipart uploads and Bedrock custom body 2026-04-09 19:43:57 -07:00
policy_engine Litellm ishaan april4 2 (#25150) 2026-04-04 23:09:42 +00:00
prompts feat: add POST /team/permissions_bulk_update endpoint 2026-04-06 17:45:35 -07:00
public_endpoints feat(ui): expose Azure Entra ID credential fields in provider form 2026-04-04 11:19:45 -07:00
rag_endpoints tests and route permissions (#21508) 2026-02-18 16:58:38 -08:00
realtime_endpoints fix(tests): fix flaky realtime WebRTC endpoint tests 2026-03-12 23:14:51 -07:00
response_api_endpoints Fix x-litellm-key-spend update 2025-12-12 11:44:51 +05:30
spend_tracking fix: hash sk- api_key in /spend/logs date-range path and add filter tests 2026-04-11 23:33:15 -07:00
test_configs Litellm fix GitHub action testing (#11163) 2025-05-26 14:41:42 -07:00
ui_crud_endpoints Update tests/test_litellm/proxy/ui_crud_endpoints/test_proxy_setting_endpoints.py 2026-03-14 15:42:17 -07:00
vector_store_endpoints test_delete_vector_store_checks_access 2026-01-31 12:05:09 -08:00
__init__.py test fix 2025-10-17 10:46:42 -07:00
conftest.py remove conftest patch. TODO: make a different PR for this 2026-04-09 22:29:49 +00:00
test_aiohttp_cleanup_closed.py fix(aiohttp): only set enable_cleanup_closed when required (#21897) 2026-02-23 21:06:29 -08:00
test_aiohttp_session_recovery.py fix: use AsyncMock for concurrent test consistency 2026-03-18 00:54:23 +00:00
test_api_key_masking_in_errors.py fix: mask API keys in error responses for invalid/malformed keys (#20289) 2026-02-12 19:58:05 +05:30
test_audio_speech_prometheus_hooks.py fix req changes 2026-02-28 21:32:57 +05:30
test_batch_expiry.py fix(proxy): improve team expiry enforcement validation 2026-03-03 17:29:39 -08:00
test_batch_metadata_none_fix.py Fix issue #13995: Handle None metadata in batch requests (#13996) 2025-08-27 14:51:09 -07:00
test_caching_routes.py [Bug Fix] Ensure /redis/info works on GCP Redis (#11732) 2025-06-14 15:35:09 -07:00
test_chat_completion_metadata.py fix: propagate JWT auth metadata to OTEL spans (#19627) 2026-01-23 21:21:23 -08:00
test_common_request_processing.py fix(proxy): preserve dict guardrail HTTPException.detail + bedrock context (#25558) 2026-04-11 09:40:39 -07:00
test_cors_config.py refactor: extract _get_cors_config() for testability, fix no-op CORS tests 2026-04-11 22:24:04 +05:30
test_custom_proxy.py fix(ui/): fix routing for custom server root path (#15701) 2025-10-23 13:59:29 -07:00
test_empty_model_list.py [Release Fix] (#22411) 2026-02-28 09:46:35 -08:00
test_enforce_user_param.py Enforce support of enforce_user_param to openai post endpoints 2025-12-03 12:19:21 +05:30
test_fallback_management_endpoints.py Add fallback endpoints support 2026-01-16 10:51:33 +05:30
test_fastapi_offline_routes.py [Bug Fix] - Get Routes (#13466) 2025-08-09 12:52:23 -07:00
test_health_check_functions.py Optimize database query which fetches latest model_id, model_name pairs and dedupes them in memory. 2026-04-15 00:54:37 +00:00
test_health_check_max_tokens.py style: black format test_health_check_max_tokens.py 2026-04-15 18:18:56 -07:00
test_litellm_pre_call_utils.py feat(proxy): add credential overrides per team/project via model_config metadata (#24438) 2026-04-09 07:22:27 -07:00
test_max_budget_env_var.py Fix PR review issues: gpt-4-0314 prompt caching, case-insensitive data URL check, test I/O mocking 2026-03-21 11:30:29 -07:00
test_model_dump_with_preserved_fields.py Fix_mapped tests part 2 2026-02-26 12:43:39 +05:30
test_model_id_header_propagation.py (fix) propagate x-litellm-model-id in responses (#16986) 2025-11-24 20:40:43 -08:00
test_model_info_default_limits.py refactor: consolidate duplicate helpers and eliminate success-handler double lookup 2026-03-19 07:26:43 -04:00
test_model_level_guardrails.py test: use __file__-relative sys.path for stable test imports 2026-03-16 21:07:07 +01:00
test_openapi_schema_validation.py Reapply "feat: add model_cost aliases expansion support" 2026-03-12 13:36:57 -03:00
test_prometheus_cleanup.py [Infra] Merging RC Branch with Main (#23786) 2026-03-16 15:32:20 -07:00
test_proxy_cli.py build: migrate packaging, CI, and Docker from Poetry to uv (#25007) 2026-04-09 11:46:23 -07:00
test_proxy_server.py Fix failing test and code qa + lint 2026-04-14 20:53:17 +05:30
test_proxy_types.py fix: Add PROXY_ADMIN role to system user for key rotation (#21896) 2026-02-27 19:11:29 -08:00
test_proxy_utils.py fix(proxy): preserve dict guardrail HTTPException.detail + bedrock context (#25558) 2026-04-11 09:40:39 -07:00
test_pyroscope.py Fix CI/CD pyroscope test failure (#21219) 2026-02-14 12:07:20 -08:00
test_response_model_sanitization.py fix: return winning model name instead of comma-separated list for fastest_response 2026-03-27 22:34:26 -07:00
test_route_a2a_models.py Fix test_route_a2a_model_bypasses_router 2026-02-05 09:47:05 +05:30
test_route_llm_request.py Override router settings 2026-01-31 16:04:52 -08:00
test_shared_health_check.py Litellm ishaan april4 2 (#25150) 2026-04-04 23:09:42 +00:00
test_spend_log_cleanup.py fix: harden CORS, create_views exception handling, and spend log cleanup loop 2026-04-11 18:58:04 +05:30
test_swagger_chat_completions.py [Release Fix] (#22411) 2026-02-28 09:46:35 -08:00
test_team_member_update.py fix mapped tests (#12320) 2025-07-04 10:04:43 -07:00
test_tools_allowlist_enforcement.py Bug Fix: auto-inject prompt caching support for Gemini models (#21881) 2026-03-03 20:25:35 -08:00
test_update_llm_router_resilience.py fix(proxy): isolate get_config failures from model loading in sync loop 2026-02-26 17:49:44 -03:00
test_utils.py add NO_OPENAPI env var to disable /openapi.json endpoint (#25547) 2026-04-14 23:37:49 +05:30