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
fix(cost): reach tiered pricing for models without top-level per-token rates
mateo-berri2f6f5c496167
diff --git a/litellm/cost_calculator.py b/litellm/cost_calculator.pyindex 6b6653c5646..eb17a53a46e 100644--- a/litellm/cost_calculator.py+++ b/litellm/cost_calculator.py@@ -645,7 +645,11 @@ def cost_per_token(else:model_info: Final = _cached_get_model_info_helper(model=model, custom_llm_provider=custom_llm_provider)- if (model_info.get("input_cost_per_token") or 0.0) > 0 or (model_info.get("output_cost_per_token") or 0.0) > 0:+ if (+ (model_info.get("input_cost_per_token") or 0.0) > 0+ or (model_info.get("output_cost_per_token") or 0.0) > 0+ or model_info.get("tiered_pricing") is not None+ ):return generic_cost_per_token(model=model,usage=usage_block,diff --git a/tests/test_litellm/test_cost_calculator.py b/tests/test_litellm/test_cost_calculator.pyindex 3f024e2fd03..8378375c09c 100644--- a/tests/test_litellm/test_cost_calculator.py+++ b/tests/test_litellm/test_cost_calculator.py@@ -42,6 +42,26 @@ def test_cost_per_token_duplicate_openai_prefix_matches_model_cost(monkeypatch):assert prompt_usd + completion_usd > 0+def test_cost_per_token_tiered_only_model_bills_at_tier_rate(monkeypatch):+ """+ Regression: models that publish only tiered_pricing (no top-level per-token rates),+ e.g. volcengine doubao-seed-2.0, must reach the generic tiered path instead of+ recording zero spend.+ """+ monkeypatch.setenv("LITELLM_LOCAL_MODEL_COST_MAP", "True")+ monkeypatch.setattr(litellm, "model_cost", litellm.get_model_cost_map(url=""))++ prompt_usd, completion_usd = cost_per_token(+ model="volcengine/doubao-seed-2-0-pro-260215",+ prompt_tokens=40000,+ completion_tokens=500,+ custom_llm_provider="volcengine",+ )++ assert prompt_usd == pytest.approx(40000 * 7e-07)+ assert completion_usd == pytest.approx(500 * 3.5e-06)++def test_cost_per_token_non_string_model_does_not_hang():"""The provider-prefix dedup loop must not spin forever when `model` is a