The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
Merge remote-tracking branch 'origin/main' into litellm_max_parallel_requests_queue_size
yassin61ce1b46d984
diff --cc tests/test_litellm/test_utils.pyindex 07da804c0f9,876c36b1071..dc6a6ad8cef--- a/tests/test_litellm/test_utils.py+++ b/tests/test_litellm/test_utils.py@@@ -6064,182 -5692,3 +5693,30 @@@ def test_get_model_info_gemini(monkeypaassert info.get("rpm") is not None, f"{model} does not have rpm"- def test_get_model_info_resolves_provider_prefixed_model_ids(local_model_cost_map):- """Perplexity's Agent API third-party models are keyed `perplexity/perplexity/<id>`- because Perplexity's own id already starts with `perplexity/`. Callers run- `get_llm_provider` first, which hands `_get_potential_model_names` model- `perplexity/glm-5.2` with provider `perplexity`, and every candidate but the- provider-prefixed one strips that second `perplexity/` off. Regression: the- entries were unreachable from `supports_reasoning` and from the cost calculator's- per-token fallback, so a mapped model reported no reasoning support and raised- "This model isn't mapped yet" on the only path where its rates are ever used."""- for model, reasoning in (- ("perplexity/perplexity/glm-5.2", True),- ("perplexity/perplexity/kimi-k3", True),- ("perplexity/perplexity/deepseek-v4-flash-0731", True),- ("perplexity/perplexity/kimi-k2.7-code", False),- ("perplexity/perplexity/nemotron-3.5-lightning-30b-a3b", True),- ("perplexity/perplexity/nemotron-3-ultra-550b-a55b", True),- ):- assert litellm.supports_reasoning(model=model) is reasoning, model-- via_provider = litellm.get_model_info(model="perplexity/glm-5.2", custom_llm_provider="perplexity")- assert via_provider["key"] == "perplexity/perplexity/glm-5.2"- assert via_provider["mode"] == "responses"-- lightning = litellm.get_model_info(- model="perplexity/nemotron-3.5-lightning-30b-a3b", custom_llm_provider="perplexity"- )- assert lightning["key"] == "perplexity/perplexity/nemotron-3.5-lightning-30b-a3b"- assert lightning["mode"] == "responses"-- ultra = litellm.get_model_info(model="perplexity/perplexity/nemotron-3-ultra-550b-a55b")- assert ultra["key"] == "perplexity/perplexity/nemotron-3-ultra-550b-a55b"--- def test_get_model_info_shows_supports_computer_use(monkeypatch):- """- Tests if 'supports_computer_use' is correctly retrieved by get_model_info.- We'll use 'claude-4-sonnet-20250514' as it's configured- in the backup JSON to have supports_computer_use: True.- """- monkeypatch.setenv("LITELLM_LOCAL_MODEL_COST_MAP", "True")- # Ensure litellm.model_cost is loaded, relying on the backup mechanism if primary fails- # as per previous debugging.- litellm.model_cost = litellm.get_model_cost_map(url="")-- # This model should have 'supports_computer_use': True in the backup JSON- model_known_to_support_computer_use = "claude-4-sonnet-20250514"- info = litellm.get_model_info(model_known_to_support_computer_use)-- # After the fix in utils.py, this should now be present and True- assert info.get("supports_computer_use") is True--- def test_get_model_info_surfaces_supports_adaptive_thinking(local_model_cost_map):- """supports_adaptive_thinking must flow through get_model_info like every other- capability flag: both from an explicit cost-map entry and from a- fallback-generalization rule for an unmapped model. Regression: the field shipped- in the JSON but was never declared on ModelInfo nor copied during construction, so- get_model_info (and _supports_factory) silently dropped it for any provider-prefixed- or unmapped name."""- explicit = litellm.get_model_info(model="claude-opus-4-8")- assert explicit["supports_adaptive_thinking"] is True-- generalized = litellm.get_model_info(model="claude-opus-4-9", custom_llm_provider="anthropic")- assert generalized["supports_adaptive_thinking"] is True--- def test_get_model_info_surfaces_supports_parallel_function_calling(local_model_cost_map):- """A registry entry's supports_parallel_function_calling must read back through get_model_info- and litellm.supports_parallel_function_calling. Regression: the key was never copied into- ModelInfo, so provider-prefixed entries read None / False even when the map said True, and an- explicit False was indistinguishable from unset."""- declared_true = litellm.get_model_info(model="together_ai/zai-org/GLM-5.3-Flash")- assert declared_true["supports_parallel_function_calling"] is True- assert litellm.supports_parallel_function_calling(model="together_ai/zai-org/GLM-5.3-Flash") is True--- def test_model_info_for_fireworks_short_form_models():- """- Test that fireworks_ai short-form model entries (fireworks_ai/<model>)- are correctly configured in model_prices_and_context_window.json.-- These entries enable cost attribution for models called via short-form- names (e.g., fireworks_ai/glm-4p7 instead of- fireworks_ai/accounts/fireworks/models/glm-4p7).- """- import json- from pathlib import Path-- json_path = Path(__file__).parents[2] / "model_prices_and_context_window.json"- with open(json_path) as f:- model_cost = json.load(f)-- # glm-4p7: short-form and long-form- for key in [- "fireworks_ai/glm-4p7",- "fireworks_ai/accounts/fireworks/models/glm-4p7",- ]:- info = model_cost.get(key)- assert info is not None, f"{key} not found in model_prices_and_context_window.json"- assert info["litellm_provider"] == "fireworks_ai"- assert info["mode"] == "chat"- assert info["supports_reasoning"] is True-- # minimax-m2p1: short-form and long-form- for key in [- "fireworks_ai/minimax-m2p1",- "fireworks_ai/accounts/fireworks/models/minimax-m2p1",- ]:- info = model_cost.get(key)- assert info is not None, f"{key} not found in model_prices_and_context_window.json"- assert info["litellm_provider"] == "fireworks_ai"- assert info["mode"] == "chat"-- # kimi-k2p5: short-form only (long-form already existed)- info = model_cost.get("fireworks_ai/kimi-k2p5")- assert info is not None, "fireworks_ai/kimi-k2p5 not found in model_prices_and_context_window.json"- assert info["litellm_provider"] == "fireworks_ai"- assert info["mode"] == "chat"--- def test_model_info_for_vertex_ai_deepseek_model():- model_info = litellm.get_model_info(model="vertex_ai/deepseek-ai/deepseek-r1-0528-maas")- assert model_info is not None- assert model_info["litellm_provider"] == "vertex_ai-deepseek_models"- assert model_info["mode"] == "chat"-- assert model_info["input_cost_per_token"] is not None- assert model_info["output_cost_per_token"] is not None--- def test_provider_prefixed_lookup_never_outranks_an_existing_row(local_model_cost_map):- """The provider-prefixed candidate is tried last, after every candidate that- already existed, so no model that resolves today can change answer. `perplexity/sonar`- is the case that proves it: both `perplexity/sonar` and `perplexity/perplexity/sonar`- are cost-map keys, and the shorter one must keep winning."""- sonar = litellm.get_model_info(model="sonar", custom_llm_provider="perplexity")- assert sonar["key"] == "perplexity/sonar"- assert sonar["mode"] == "chat"-- still_sonar = litellm.get_model_info(model="perplexity/sonar", custom_llm_provider="perplexity")- assert still_sonar["key"] == "perplexity/sonar"- assert still_sonar["mode"] == "chat"-- for model, provider, expected_key in (- ("claude-sonnet-4-5", "anthropic", "claude-sonnet-4-5"),- ("anthropic/claude-sonnet-4-5", "anthropic", "claude-sonnet-4-5"),- ("gemini/gemini-2.0-flash", "gemini", "gemini/gemini-2.0-flash"),- ("openrouter/openai/gpt-4o", "openrouter", "openrouter/openai/gpt-4o"),- ):- assert litellm.get_model_info(model=model, custom_llm_provider=provider)["key"] == expected_key--+ ("max_parallel_requests", "rpm", "tpm", "default_max_parallel_requests", "expected"),+ [+ (3, 100, 100_000, 7, 3),+ (None, 100, 100_000, 7, 100),+ (None, None, 100_000, 7, 600),+ (None, None, 50, 7, 1),+ (None, None, None, 7, 7),+ (None, None, None, None, None),+ ],+)+def test_calculate_max_parallel_requests_precedence(+ max_parallel_requests: int | None,+ rpm: int | None,+ tpm: int | None,+ default_max_parallel_requests: int | None,+ expected: int | None,+) -> None:+ assert (+ calculate_max_parallel_requests(+ max_parallel_requests=max_parallel_requests,+ rpm=rpm,+ tpm=tpm,+ default_max_parallel_requests=default_max_parallel_requests,+ )+ == expected+ )