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/litellm_internal_staging' into pr37724
mateo-berri885d95d71b7b
diff --cc tests/test_litellm/test_cost_calculator.pyindex f0a84fe620b,dc2fbe3ed73..4117b2fce6d--- a/tests/test_litellm/test_cost_calculator.py+++ b/tests/test_litellm/test_cost_calculator.py@@@ -2613,53 -2619,7 +2619,50 @@@ def test_completion_cost_anthropic_autoassert cost == pytest.approx(expected_priority)- def test_completion_cost_vertex_ai_gemini_flex_traffic_type(monkeypatch):++def test_completion_cost_vertex_ai_gemini_flex_traffic_type(_local_model_cost_map):+ """+ Vertex AI flex-tier billing regression for issue #37647.++ Vertex Gemini 3.x models route through ``cost_per_character`` (the+ ``cost_router`` token-path gate only matches "gemini-2"), and its token+ fallbacks dropped ``service_tier``. A response served with+ ``trafficType=ON_DEMAND_FLEX`` must be billed at the flex rate, not the+ standard rate.+ """+ from litellm import completion_cost+- monkeypatch.setenv("LITELLM_LOCAL_MODEL_COST_MAP", "True")- monkeypatch.setattr(litellm, "model_cost", litellm.get_model_cost_map(url=""))-+ model = "gemini-3-test-flex-tier-cost-model"+ litellm.register_model(+ model_cost={+ model: {+ "input_cost_per_token": 1.5e-6,+ "output_cost_per_token": 9e-6,+ "input_cost_per_token_flex": 7.5e-7,+ "output_cost_per_token_flex": 4.5e-6,+ "litellm_provider": "vertex_ai",+ "max_tokens": 8192,+ }+ }+ )++ def _cost_for_traffic_type(traffic_type):+ usage = Usage(prompt_tokens=1000, completion_tokens=500, total_tokens=1500)+ response = ModelResponse(usage=usage, model=model)+ response._hidden_params["provider_specific_fields"] = {"traffic_type": traffic_type}+ return completion_cost(+ completion_response=response,+ model=model,+ custom_llm_provider="vertex_ai",+ )++ standard_cost = _cost_for_traffic_type("ON_DEMAND")+ flex_cost = _cost_for_traffic_type("ON_DEMAND_FLEX")++ assert standard_cost == pytest.approx(1000 * 1.5e-6 + 500 * 9e-6)+ assert flex_cost == pytest.approx(1000 * 7.5e-7 + 500 * 4.5e-6)++- def test_completion_cost_non_string_service_tier_defers_to_served_tier():+ def test_completion_cost_non_string_service_tier_defers_to_served_tier(_local_model_cost_map):"""Regression: a non-string request-level ``service_tier`` (reachable via``allowed_openai_params``/``drop_params``) must not crash cost tracking.