Skip to content

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]

[Feat] Cost Tracking - Add support for Tiered Cost Tracking for Qwen API (Dashscope) (#14471)

Ishaan Jaffdda115cc6dc4
diff --git a/docs/my-website/docs/providers/dashscope.md b/docs/my-website/docs/providers/dashscope.md
index eb18fa32a47..565776d6c4c 100644
--- a/docs/my-website/docs/providers/dashscope.md
+++ b/docs/my-website/docs/providers/dashscope.md
@@ -1,4 +1,4 @@
-# Dashscope
+# Dashscope (Qwen API)
https://dashscope.console.aliyun.com/
**We support ALL Qwen models, just set `dashscope/` as a prefix when sending completion requests**
diff --git a/litellm/llms/dashscope/cost_calculator.py b/litellm/llms/dashscope/cost_calculator.py
index 0f4490cb3df..6f9ebe302f4 100644
--- a/litellm/llms/dashscope/cost_calculator.py
+++ b/litellm/llms/dashscope/cost_calculator.py
@@ -1,21 +1,158 @@
"""
-Cost calculator for DeepSeek Chat models.
+Cost calculator for Dashscope Chat models.
-Handles prompt caching scenario.
+Handles tiered pricing and prompt caching scenarios.
"""
-from typing import Tuple
+from dataclasses import dataclass
+from typing import List, Optional, Tuple
-from litellm.litellm_core_utils.llm_cost_calc.utils import generic_cost_per_token
-from litellm.types.utils import Usage
+from litellm.types.utils import ModelInfo, Usage
+from litellm.utils import get_model_info
+
+
+@dataclass
+class TokenBreakdown:
+ """Token breakdown for cost calculation."""
+ text_tokens: int
+ cached_tokens: int
+ completion_tokens: int
+ reasoning_tokens: int
+
+
+def _extract_token_breakdown(usage: Usage) -> TokenBreakdown:
+ """Extract token counts from usage, handling cached and reasoning tokens."""
+ cached_tokens = 0
+ if usage.prompt_tokens_details and hasattr(usage.prompt_tokens_details, "cached_tokens"):
+ cached_tokens = usage.prompt_tokens_details.cached_tokens or 0
+
+ text_tokens = usage.prompt_tokens - cached_tokens
+
+ reasoning_tokens = 0
+ if (hasattr(usage, "completion_tokens_details") and
+ usage.completion_tokens_details and
+ hasattr(usage.completion_tokens_details, "reasoning_tokens")):
+ reasoning_tokens = usage.completion_tokens_details.reasoning_tokens or 0
+
+ completion_tokens = (usage.completion_tokens or 0) - reasoning_tokens
+
+ return TokenBreakdown(text_tokens, cached_tokens, completion_tokens, reasoning_tokens)
+
+
+def _calculate_tiered_cost(
+ tokens: int,
+ tiered_pricing: List[dict],
+ cost_key: str,
+ fallback_cost_key: Optional[str] = None
+) -> float:
+ """Calculate cost using tiered pricing structure."""
+ if not tiered_pricing or tokens <= 0:
+ return 0.0
+
+ total_cost = 0.0
+ tokens_processed = 0
+
+ for tier in tiered_pricing:
+ if tokens_processed >= tokens:
+ break
+
+ tier_range = tier.get("range", [])
+ if len(tier_range) != 2:
+ continue
+
+ range_start, range_end = tier_range
+
+ if tokens <= range_start:
+ break
+
+ tier_start = max(range_start, tokens_processed)
+ tier_end = min(range_end, tokens)
+
+ if tier_end > tier_start:
+ tokens_in_tier = tier_end - tier_start
+ cost_per_token = tier.get(cost_key) or tier.get(fallback_cost_key, 0)
+ total_cost += tokens_in_tier * cost_per_token
+ tokens_processed = tier_end
+
+ return total_cost
+
+
+def _calculate_flat_cost(tokens: int, cost_per_token: float) -> float:
+ """Calculate cost using flat pricing."""
+ return tokens * cost_per_token
+
+
+def _calculate_prompt_cost(breakdown: TokenBreakdown, model_info: ModelInfo, tiered_pricing: Optional[List[dict]]) -> float:
+ """Calculate total prompt cost including cached tokens."""
+ if tiered_pricing:
+ text_cost = _calculate_tiered_cost(
+ tokens=breakdown.text_tokens,
+ tiered_pricing=tiered_pricing,
+ cost_key="input_cost_per_token"
+ )
+ cache_cost = _calculate_tiered_cost(
+ tokens=breakdown.cached_tokens,
+ tiered_pricing=tiered_pricing,
+ cost_key="cache_read_input_token_cost"
+ )
+ return text_cost + cache_cost
+
+ input_cost = model_info.get("input_cost_per_token", 0.0)
+ cache_cost = model_info.get("cache_read_input_token_cost", input_cost) or input_cost
+
+ return (_calculate_flat_cost(tokens=breakdown.text_tokens, cost_per_token=input_cost) +
+ _calculate_flat_cost(tokens=breakdown.cached_tokens, cost_per_token=cache_cost))
+
+
+def _calculate_completion_cost(breakdown: TokenBreakdown, model_info: ModelInfo, tiered_pricing: Optional[List[dict]]) -> float:
+ """Calculate total completion cost including reasoning tokens."""
+ if tiered_pricing:
+ completion_cost = _calculate_tiered_cost(
+ tokens=breakdown.completion_tokens,
+ tiered_pricing=tiered_pricing,
+ cost_key="output_cost_per_token"
+ )
+ reasoning_cost = _calculate_tiered_cost(
+ tokens=breakdown.reasoning_tokens,
+ tiered_pricing=tiered_pricing,
+ cost_key="output_cost_per_reasoning_token",
+ fallback_cost_key="output_cost_per_token"
+ )
+ return completion_cost + reasoning_cost
+
+ output_cost = model_info.get("output_cost_per_token", 0.0)
+ reasoning_cost = model_info.get("output_cost_per_reasoning_token", output_cost) or output_cost
+
+ return (_calculate_flat_cost(tokens=breakdown.completion_tokens, cost_per_token=output_cost) +
+ _calculate_flat_cost(tokens=breakdown.reasoning_tokens, cost_per_token=reasoning_cost))
def cost_per_token(model: str, usage: Usage) -> Tuple[float, float]:
"""
- Calculates the cost per token for a given model, prompt tokens, and completion tokens.
-
- Follows the same logic as Anthropic's cost per token calculation.
+ Calculate cost per token for Dashscope models.
+
+ Supports both tiered and flat pricing with cached and reasoning tokens.
+
+ Args:
+ model: Model name without provider prefix
+ usage: LiteLLM Usage block
+
+ Returns:
+ Tuple[float, float] - (prompt_cost_in_usd, completion_cost_in_usd)
"""
- return generic_cost_per_token(
- model=model, usage=usage, custom_llm_provider="deepseek"
+ model_info = get_model_info(model=model, custom_llm_provider="dashscope")
+ breakdown = _extract_token_breakdown(usage)
+ tiered_pricing = model_info.get("tiered_pricing") if isinstance(model_info.get("tiered_pricing"), list) else None
+
+ prompt_cost = _calculate_prompt_cost(
+ breakdown=breakdown,
+ model_info=model_info,
+ tiered_pricing=tiered_pricing
+ )
+ completion_cost = _calculate_completion_cost(
+ breakdown=breakdown,
+ model_info=model_info,
+ tiered_pricing=tiered_pricing
)
+
+ return prompt_cost, completion_cost
diff --git a/litellm/model_prices_and_context_window_backup.json b/litellm/model_prices_and_context_window_backup.json
index c7fabb0ed9f..972e212e693 100644
--- a/litellm/model_prices_and_context_window_backup.json
+++ b/litellm/model_prices_and_context_window_backup.json
@@ -6,6 +6,7 @@
"input_cost_per_token": 0.0,
"output_cost_per_token": 0.0,
"output_cost_per_reasoning_token": 0.0,
+ "input_cost_per_audio_token": 0.0,
"litellm_provider": "one of https://docs.litellm.ai/docs/providers",
"mode": "one of: chat, embedding, completion, image_generation, audio_transcription, audio_speech, image_generation, moderation, rerank",
"supports_function_calling": true,
@@ -19045,14 +19046,45 @@
"max_tokens": 32768,
"max_input_tokens": 30720,
"max_output_tokens": 8192,
+ "input_cost_per_token": 1.6e-06,
+ "output_cost_per_token": 6.4e-06,
"litellm_provider": "dashscope",
"supports_function_calling": true,
"supports_tool_choice": true,
"supports_reasoning": true,
"mode": "chat",
- "source": "https://bailian.console.alibabacloud.com/?spm=a2c63.p38356.0.0.4a615d7bjSUCb4&tab=doc#/doc/?type=model&url=https%3A%2F%2Fwww.alibabacloud.com%2Fhelp%2Fen%2Fdoc-detail%2F2840914.html"
+ "source": "https://www.alibabacloud.com/help/en/model-studio/models"
},
"dashscope/qwen-plus-latest": {
+ "max_tokens": 1000000,
+ "max_input_tokens": 997952,
+ "max_output_tokens": 32768,
+ "litellm_provider": "dashscope",
+ "supports_function_calling": true,
+ "supports_tool_choice": true,
+ "supports_reasoning": true,
+ "mode": "chat",
+ "tiered_pricing": [
+ {"range": [0, 256e3], "input_cost_per_token": 4e-07, "output_cost_per_token": 1.2e-06, "output_cost_per_reasoning_token": 4e-06},
+ {"range": [256e3, 1e6], "input_cost_per_token": 1.2e-06, "output_cost_per_token": 3.6e-06, "output_cost_per_reasoning_token": 1.2e-05}
+ ],
+ "source": "https://www.alibabacloud.com/help/en/model-studio/models"
+ },
+ "dashscope/qwen-turbo-latest": {
+ "max_tokens": 1000000,
+ "max_input_tokens": 1000000,
+ "max_output_tokens": 16384,
+ "input_cost_per_token": 5e-08,
+ "output_cost_per_token": 2e-07,
+ "output_cost_per_reasoning_token": 5e-07,
+ "litellm_provider": "dashscope",
+ "supports_function_calling": true,
+ "supports_tool_choice": true,
+ "supports_reasoning": true,
+ "mode": "chat",
+ "source": "https://www.alibabacloud.com/help/en/model-studio/models"
+ },
+ "dashscope/qwen3-30b-a3b": {
"max_tokens": 131072,
"max_input_tokens": 129024,
"max_output_tokens": 16384,
@@ -19061,29 +19093,277 @@
"supports_tool_choice": true,
"supports_reasoning": true,
"mode": "chat",
- "source": "https://bailian.console.alibabacloud.com/?spm=a2c63.p38356.0.0.4a615d7bjSUCb4&tab=doc#/doc/?type=model&url=https%3A%2F%2Fwww.alibabacloud.com%2Fhelp%2Fen%2Fdoc-detail%2F2840914.html"
+ "source": "https://www.alibabacloud.com/help/en/model-studio/models"
},
- "dashscope/qwen-turbo-latest": {
+ "dashscope/qwen3-max-preview": {
+ "max_tokens": 262144,
+ "max_input_tokens": 258048,
+ "max_output_tokens": 65536,
+ "litellm_provider": "dashscope",
+ "supports_function_calling": true,
+ "supports_tool_choice": true,
+ "supports_reasoning": true,
+ "mode": "chat",
+ "tiered_pricing": [
+ {"range": [0, 32e3], "input_cost_per_token": 1.2e-06, "output_cost_per_token": 6e-06},
+ {"range": [32e3, 128e3], "input_cost_per_token": 2.4e-06, "output_cost_per_token": 1.2e-05},
+ {"range": [128e3, 252e3], "input_cost_per_token": 3.0e-06, "output_cost_per_token": 1.5e-05}
+ ],
+ "source": "https://www.alibabacloud.com/help/en/model-studio/models"
+ },
+ "dashscope/qwen-plus": {
"max_tokens": 131072,
"max_input_tokens": 129024,
"max_output_tokens": 16384,
+ "input_cost_per_token": 4e-07,
+ "output_cost_per_token": 1.2e-06,
"litellm_provider": "dashscope",
"supports_function_calling": true,
"supports_tool_choice": true,
"supports_reasoning": true,
"mode": "chat",
- "source": "https://bailian.console.alibabacloud.com/?spm=a2c63.p38356.0.0.4a615d7bjSUCb4&tab=doc#/doc/?type=model&url=https%3A%2F%2Fwww.alibabacloud.com%2Fhelp%2Fen%2Fdoc-detail%2F2840914.html"
+ "source": "https://www.alibabacloud.com/help/en/model-studio/models"
},
- "dashscope/qwen3-30b-a3b": {
+ "dashscope/qwen-flash": {
+ "max_tokens": 1000000,
+ "max_input_tokens": 997952,
+ "max_output_tokens": 32768,
+ "litellm_provider": "dashscope",
+ "supports_function_calling": true,
+ "supports_tool_choice": true,
+ "supports_reasoning": true,
+ "supports_caching": true,
+ "mode": "chat",
+ "tiered_pricing": [
+ {"range": [0, 256e3], "input_cost_per_token": 5e-08, "output_cost_per_token": 4e-07},
+ {"range": [256e3, 1e6], "input_cost_per_token": 2.5e-07, "output_cost_per_token": 2e-06}
+ ],
+ "source": "https://www.alibabacloud.com/help/en/model-studio/models"
+ },
+ "dashscope/qwen-coder": {
+ "max_tokens": 1000000,
+ "max_input_tokens": 1000000,
+ "max_output_tokens": 16384,
+ "input_cost_per_token": 3e-07,
+ "output_cost_per_token": 1.5e-06,
+ "litellm_provider": "dashscope",
+ "supports_function_calling": true,
+ "supports_tool_choice": true,
+ "supports_reasoning": true,
+ "mode": "chat",
+ "source": "https://www.alibabacloud.com/help/en/model-studio/models"
+ },
+ "dashscope/qwen3-coder-plus": {
+ "max_tokens": 1000000,
+ "max_input_tokens": 997952,
+ "max_output_tokens": 65536,
+ "litellm_provider": "dashscope",
+ "supports_function_calling": true,
+ "supports_tool_choice": true,
+ "supports_reasoning": true,
+ "supports_caching": true,
+ "mode": "chat",
+ "tiered_pricing": [
+ {"range": [0, 32e3], "input_cost_per_token": 1e-06, "output_cost_per_token": 5e-06, "cache_read_input_token_cost": 1e-07},
+ {"range": [32e3, 128e3], "input_cost_per_token": 1.8e-06, "output_cost_per_token": 9e-06, "cache_read_input_token_cost": 1.8e-07},
+ {"range": [128e3, 256e3], "input_cost_per_token": 3e-06, "output_cost_per_token": 1.5e-05, "cache_read_input_token_cost": 3e-07},
+ {"range": [256e3, 1e6], "input_cost_per_token": 6e-06, "output_cost_per_token": 6e-05, "cache_read_input_token_cost": 6e-07}
+ ],
+ "source": "https://www.alibabacloud.com/help/en/model-studio/models"
+ },
+ "dashscope/qwen3-coder-plus-2025-07-22": {
+ "max_tokens": 1000000,
+ "max_input_tokens": 997952,
+ "max_output_tokens": 65536,
+ "litellm_provider": "dashscope",
+ "supports_function_calling": true,
+ "supports_tool_choice": true,
+ "supports_reasoning": true,
+ "mode": "chat",
+ "tiered_pricing": [
+ {"range": [0, 32e3], "input_cost_per_token": 1e-06, "output_cost_per_token": 5e-06},
+ {"range": [32e3, 128e3], "input_cost_per_token": 1.8e-06, "output_cost_per_token": 9e-06},
+ {"range": [128e3, 256e3], "input_cost_per_token": 3e-06, "output_cost_per_token": 1.5e-05},
+ {"range": [256e3, 1e6], "input_cost_per_token": 6e-06, "output_cost_per_token": 6e-05}
+ ],
+ "source": "https://www.alibabacloud.com/help/en/model-studio/models"
+ },
+ "dashscope/qwen3-coder-flash": {
+ "max_tokens": 1000000,
+ "max_input_tokens": 997952,
+ "max_output_tokens": 65536,
+ "litellm_provider": "dashscope",
+ "supports_function_calling": true,
+ "supports_tool_choice": true,
+ "supports_reasoning": true,
+ "supports_caching": true,
+ "mode": "chat",
+ "tiered_pricing": [
+ {"range": [0, 32e3], "input_cost_per_token": 3e-07, "output_cost_per_token": 1.5e-06, "cache_read_input_token_cost": 8e-08},
+ {"range": [32e3, 128e3], "input_cost_per_token": 5e-07, "output_cost_per_token": 2.5e-06, "cache_read_input_token_cost": 1.2e-07},
+ {"range": [128e3, 256e3], "input_cost_per_token": 8e-07, "output_cost_per_token": 4e-06, "cache_read_input_token_cost": 2e-07},
+ {"range": [256e3, 1e6], "input_cost_per_token": 1.6e-06, "output_cost_per_token": 9.6e-06, "cache_read_input_token_cost": 4e-07}
+ ],
+ "source": "https://www.alibabacloud.com/help/en/model-studio/models"
+ },
+ "dashscope/qwen3-coder-flash-2025-07-28": {
+ "max_tokens": 1000000,
+ "max_input_tokens": 997952,
+ "max_output_tokens": 65536,
+ "litellm_provider": "dashscope",
+ "supports_function_calling": true,
+ "supports_tool_choice": true,
+ "supports_reasoning": true,
+ "mode": "chat",
+ "tiered_pricing": [
+ {"range": [0, 32e3], "input_cost_per_token": 3e-07, "output_cost_per_token": 1.5e-06},
+ {"range": [32e3, 128e3], "input_cost_per_token": 5e-07, "output_cost_per_token": 2.5e-06},
+ {"range": [128e3, 256e3], "input_cost_per_token": 8e-07, "output_cost_per_token": 4e-06},
+ {"range": [256e3, 1e6], "input_cost_per_token": 1.6e-06, "output_cost_per_token": 9.6e-06}
+ ],
+ "source": "https://www.alibabacloud.com/help/en/model-studio/models"
+ },
+ "dashscope/qwen-plus-2025-09-11": {
+ "max_tokens": 1000000,
+ "max_input_tokens": 997952,
+ "max_output_tokens": 32768,
+ "litellm_provider": "dashscope",
+ "supports_function_calling": true,
+ "supports_tool_choice": true,
+ "supports_reasoning": true,
+ "mode": "chat",
+ "tiered_pricing": [
+ {"range": [0, 256e3], "input_cost_per_token": 4e-07, "output_cost_per_token": 1.2e-06, "output_cost_per_reasoning_token": 4e-06},
+ {"range": [256e3, 1e6], "input_cost_per_token": 1.2e-06, "output_cost_per_token": 3.6e-06, "output_cost_per_reasoning_token": 1.2e-05}
+ ],
+ "source": "https://www.alibabacloud.com/help/en/model-studio/models"
+ },
+ "dashscope/qwen-plus-2025-07-28": {
+ "max_tokens": 1000000,
+ "max_input_tokens": 997952,
+ "max_output_tokens": 32768,
+ "litellm_provider": "dashscope",
+ "supports_function_calling": true,
+ "supports_tool_choice": true,
+ "supports_reasoning": true,
+ "mode": "chat",
+ "tiered_pricing": [
+ {"range": [0, 256e3], "input_cost_per_token": 4e-07, "output_cost_per_token": 1.2e-06, "output_cost_per_reasoning_token": 4e-06},
+ {"range": [256e3, 1e6], "input_cost_per_token": 1.2e-06, "output_cost_per_token": 3.6e-06, "output_cost_per_reasoning_token": 1.2e-05}
+ ],
+ "source": "https://www.alibabacloud.com/help/en/model-studio/models"
+ },
+ "dashscope/qwen-plus-2025-07-14": {
+ "max_tokens": 131072,
+ "max_input_tokens": 129024,
+ "max_output_tokens": 16384,
+ "input_cost_per_token": 4e-07,
+ "output_cost_per_token": 1.2e-06,
+ "output_cost_per_reasoning_token": 4e-06,
+ "litellm_provider": "dashscope",
+ "supports_function_calling": true,
+ "supports_tool_choice": true,
+ "supports_reasoning": true,
+ "mode": "chat",
+ "source": "https://www.alibabacloud.com/help/en/model-studio/models"
+ },
+ "dashscope/qwen-plus-2025-04-28": {
+ "max_tokens": 131072,
+ "max_input_tokens": 129024,
+ "max_output_tokens": 16384,
+ "input_cost_per_token": 4e-07,
+ "output_cost_per_token": 1.2e-06,
+ "output_cost_per_reasoning_token": 4e-06,
+ "litellm_provider": "dashscope",
+ "supports_function_calling": true,
+ "supports_tool_choice": true,
+ "supports_reasoning": true,
+ "mode": "chat",
+ "source": "https://www.alibabacloud.com/help/en/model-studio/models"
+ },
+ "dashscope/qwen-plus-2025-01-25": {
+ "max_tokens": 131072,
+ "max_input_tokens": 129024,
+ "max_output_tokens": 8192,
+ "input_cost_per_token": 4e-07,
+ "output_cost_per_token": 1.2e-06,
+ "litellm_provider": "dashscope",
+ "supports_function_calling": true,
+ "supports_tool_choice": true,
+ "supports_reasoning": true,
+ "mode": "chat",
+ "source": "https://www.alibabacloud.com/help/en/model-studio/models"
+ },
+ "dashscope/qwen-flash-2025-07-28": {
+ "max_tokens": 1000000,
+ "max_input_tokens": 997952,
+ "max_output_tokens": 32768,
+ "litellm_provider": "dashscope",
+ "supports_function_calling": true,
+ "supports_tool_choice": true,
+ "supports_reasoning": true,
+ "supports_caching": true,
+ "mode": "chat",
+ "tiered_pricing": [
+ {"range": [0, 256e3], "input_cost_per_token": 5e-08, "output_cost_per_token": 4e-07},
+ {"range": [256e3, 1e6], "input_cost_per_token": 2.5e-07, "output_cost_per_token": 2e-06}
+ ],
+ "source": "https://www.alibabacloud.com/help/en/model-studio/models"
+ },
+ "dashscope/qwen-turbo": {
"max_tokens": 131072,
"max_input_tokens": 129024,
"max_output_tokens": 16384,
+ "input_cost_per_token": 5e-08,
+ "output_cost_per_token": 2e-07,
+ "output_cost_per_reasoning_token": 5e-07,
+ "litellm_provider": "dashscope",
+ "supports_function_calling": true,
+ "supports_tool_choice": true,
+ "supports_reasoning": true,
+ "mode": "chat",
+ "source": "https://www.alibabacloud.com/help/en/model-studio/models"
+ },
+ "dashscope/qwen-turbo-2025-04-28": {
+ "max_tokens": 1000000,
+ "max_input_tokens": 1000000,
+ "max_output_tokens": 16384,
+ "input_cost_per_token": 5e-08,
+ "output_cost_per_token": 2e-07,
+ "output_cost_per_reasoning_token": 5e-07,
+ "litellm_provider": "dashscope",
+ "supports_function_calling": true,
+ "supports_tool_choice": true,
+ "supports_reasoning": true,
+ "mode": "chat",
+ "source": "https://www.alibabacloud.com/help/en/model-studio/models"
+ },
+ "dashscope/qwen-turbo-2024-11-01": {
+ "max_tokens": 1000000,
+ "max_input_tokens": 1000000,
+ "max_output_tokens": 8192,
+ "input_cost_per_token": 5e-08,
+ "output_cost_per_token": 2e-07,
+ "litellm_provider": "dashscope",
+ "supports_function_calling": true,
+ "supports_tool_choice": true,
+ "supports_reasoning": true,
+ "mode": "chat",
+ "source": "https://www.alibabacloud.com/help/en/model-studio/models"
+ },
+ "dashscope/qwq-plus": {
+ "max_tokens": 131072,
+ "max_input_tokens": 98304,
+ "max_output_tokens": 8192,
+ "max_chain_of_thought_tokens": 32768,
+ "input_cost_per_token": 8e-07,
+ "output_cost_per_token": 2.4e-06,
"litellm_provider": "dashscope",
"supports_function_calling": true,
"supports_tool_choice": true,
"supports_reasoning": true,
"mode": "chat",
- "source": "https://bailian.console.alibabacloud.com/?spm=a2c63.p38356.0.0.4a615d7bjSUCb4&tab=doc#/doc/?type=model&url=https%3A%2F%2Fwww.alibabacloud.com%2Fhelp%2Fen%2Fdoc-detail%2F2840914.html"
+ "source": "https://www.alibabacloud.com/help/en/model-studio/models"
},
"moonshot/moonshot-v1-8k": {
"max_tokens": 8192,
diff --git a/litellm/types/utils.py b/litellm/types/utils.py
index c6f7098a1a7..e54516371e5 100644
--- a/litellm/types/utils.py
+++ b/litellm/types/utils.py
@@ -162,6 +162,7 @@ class ModelInfoBase(ProviderSpecificModelInfo, total=False):
SearchContextCostPerQuery
] # Cost for using web search tool
citation_cost_per_token: Optional[float] # Cost per citation token for Perplexity
+ tiered_pricing: Optional[List[Dict[str, Any]]] # Tiered pricing structure for models like Dashscope
litellm_provider: Required[str]
mode: Required[
Literal[
diff --git a/litellm/utils.py b/litellm/utils.py
index be26405b43b..84d86bea647 100644
--- a/litellm/utils.py
+++ b/litellm/utils.py
@@ -4902,6 +4902,7 @@ def _get_model_info_helper( # noqa: PLR0915
citation_cost_per_token=_model_info.get(
"citation_cost_per_token", None
),
+ tiered_pricing=_model_info.get("tiered_pricing", None),
litellm_provider=_model_info.get(
"litellm_provider", custom_llm_provider
),
diff --git a/model_prices_and_context_window.json b/model_prices_and_context_window.json
index c7fabb0ed9f..972e212e693 100644
--- a/model_prices_and_context_window.json
+++ b/model_prices_and_context_window.json
@@ -6,6 +6,7 @@
"input_cost_per_token": 0.0,
"output_cost_per_token": 0.0,
"output_cost_per_reasoning_token": 0.0,
+ "input_cost_per_audio_token": 0.0,
"litellm_provider": "one of https://docs.litellm.ai/docs/providers",
"mode": "one of: chat, embedding, completion, image_generation, audio_transcription, audio_speech, image_generation, moderation, rerank",
"supports_function_calling": true,
@@ -19045,14 +19046,45 @@
"max_tokens": 32768,
"max_input_tokens": 30720,
"max_output_tokens": 8192,
+ "input_cost_per_token": 1.6e-06,
+ "output_cost_per_token": 6.4e-06,
"litellm_provider": "dashscope",
"supports_function_calling": true,
"supports_tool_choice": true,
"supports_reasoning": true,
"mode": "chat",
- "source": "https://bailian.console.alibabacloud.com/?spm=a2c63.p38356.0.0.4a615d7bjSUCb4&tab=doc#/doc/?type=model&url=https%3A%2F%2Fwww.alibabacloud.com%2Fhelp%2Fen%2Fdoc-detail%2F2840914.html"
+ "source": "https://www.alibabacloud.com/help/en/model-studio/models"
},
"dashscope/qwen-plus-latest": {
+ "max_tokens": 1000000,
+ "max_input_tokens": 997952,
+ "max_output_tokens": 32768,
+ "litellm_provider": "dashscope",
+ "supports_function_calling": true,
+ "supports_tool_choice": true,
+ "supports_reasoning": true,
+ "mode": "chat",
+ "tiered_pricing": [
+ {"range": [0, 256e3], "input_cost_per_token": 4e-07, "output_cost_per_token": 1.2e-06, "output_cost_per_reasoning_token": 4e-06},
+ {"range": [256e3, 1e6], "input_cost_per_token": 1.2e-06, "output_cost_per_token": 3.6e-06, "output_cost_per_reasoning_token": 1.2e-05}
+ ],
+ "source": "https://www.alibabacloud.com/help/en/model-studio/models"
+ },
+ "dashscope/qwen-turbo-latest": {
+ "max_tokens": 1000000,
+ "max_input_tokens": 1000000,
+ "max_output_tokens": 16384,
+ "input_cost_per_token": 5e-08,
+ "output_cost_per_token": 2e-07,
+ "output_cost_per_reasoning_token": 5e-07,
+ "litellm_provider": "dashscope",
+ "supports_function_calling": true,
+ "supports_tool_choice": true,
+ "supports_reasoning": true,
+ "mode": "chat",
+ "source": "https://www.alibabacloud.com/help/en/model-studio/models"
+ },
+ "dashscope/qwen3-30b-a3b": {
"max_tokens": 131072,
"max_input_tokens": 129024,
"max_output_tokens": 16384,
@@ -19061,29 +19093,277 @@
"supports_tool_choice": true,
"supports_reasoning": true,
"mode": "chat",
- "source": "https://bailian.console.alibabacloud.com/?spm=a2c63.p38356.0.0.4a615d7bjSUCb4&tab=doc#/doc/?type=model&url=https%3A%2F%2Fwww.alibabacloud.com%2Fhelp%2Fen%2Fdoc-detail%2F2840914.html"
+ "source": "https://www.alibabacloud.com/help/en/model-studio/models"
},
- "dashscope/qwen-turbo-latest": {
+ "dashscope/qwen3-max-preview": {
+ "max_tokens": 262144,
+ "max_input_tokens": 258048,
+ "max_output_tokens": 65536,
+ "litellm_provider": "dashscope",
+ "supports_function_calling": true,
+ "supports_tool_choice": true,
+ "supports_reasoning": true,
+ "mode": "chat",
+ "tiered_pricing": [
+ {"range": [0, 32e3], "input_cost_per_token": 1.2e-06, "output_cost_per_token": 6e-06},
+ {"range": [32e3, 128e3], "input_cost_per_token": 2.4e-06, "output_cost_per_token": 1.2e-05},
+ {"range": [128e3, 252e3], "input_cost_per_token": 3.0e-06, "output_cost_per_token": 1.5e-05}
+ ],
+ "source": "https://www.alibabacloud.com/help/en/model-studio/models"
+ },
+ "dashscope/qwen-plus": {
"max_tokens": 131072,
"max_input_tokens": 129024,
"max_output_tokens": 16384,
+ "input_cost_per_token": 4e-07,
+ "output_cost_per_token": 1.2e-06,
"litellm_provider": "dashscope",
"supports_function_calling": true,
"supports_tool_choice": true,
"supports_reasoning": true,
"mode": "chat",
- "source": "https://bailian.console.alibabacloud.com/?spm=a2c63.p38356.0.0.4a615d7bjSUCb4&tab=doc#/doc/?type=model&url=https%3A%2F%2Fwww.alibabacloud.com%2Fhelp%2Fen%2Fdoc-detail%2F2840914.html"
+ "source": "https://www.alibabacloud.com/help/en/model-studio/models"
},
- "dashscope/qwen3-30b-a3b": {
+ "dashscope/qwen-flash": {
+ "max_tokens": 1000000,
+ "max_input_tokens": 997952,
+ "max_output_tokens": 32768,
+ "litellm_provider": "dashscope",
+ "supports_function_calling": true,
+ "supports_tool_choice": true,
+ "supports_reasoning": true,
+ "supports_caching": true,
+ "mode": "chat",
+ "tiered_pricing": [
+ {"range": [0, 256e3], "input_cost_per_token": 5e-08, "output_cost_per_token": 4e-07},
+ {"range": [256e3, 1e6], "input_cost_per_token": 2.5e-07, "output_cost_per_token": 2e-06}
+ ],
+ "source": "https://www.alibabacloud.com/help/en/model-studio/models"
+ },
+ "dashscope/qwen-coder": {
+ "max_tokens": 1000000,
+ "max_input_tokens": 1000000,
+ "max_output_tokens": 16384,
+ "input_cost_per_token": 3e-07,
+ "output_cost_per_token": 1.5e-06,
+ "litellm_provider": "dashscope",
+ "supports_function_calling": true,
+ "supports_tool_choice": true,
+ "supports_reasoning": true,
+ "mode": "chat",
+ "source": "https://www.alibabacloud.com/help/en/model-studio/models"
+ },
+ "dashscope/qwen3-coder-plus": {
+ "max_tokens": 1000000,
+ "max_input_tokens": 997952,
+ "max_output_tokens": 65536,
+ "litellm_provider": "dashscope",
+ "supports_function_calling": true,
+ "supports_tool_choice": true,
+ "supports_reasoning": true,
+ "supports_caching": true,
+ "mode": "chat",
+ "tiered_pricing": [
+ {"range": [0, 32e3], "input_cost_per_token": 1e-06, "output_cost_per_token": 5e-06, "cache_read_input_token_cost": 1e-07},
+ {"range": [32e3, 128e3], "input_cost_per_token": 1.8e-06, "output_cost_per_token": 9e-06, "cache_read_input_token_cost": 1.8e-07},
+ {"range": [128e3, 256e3], "input_cost_per_token": 3e-06, "output_cost_per_token": 1.5e-05, "cache_read_input_token_cost": 3e-07},
+ {"range": [256e3, 1e6], "input_cost_per_token": 6e-06, "output_cost_per_token": 6e-05, "cache_read_input_token_cost": 6e-07}
+ ],
+ "source": "https://www.alibabacloud.com/help/en/model-studio/models"
+ },
+ "dashscope/qwen3-coder-plus-2025-07-22": {
+ "max_tokens": 1000000,
+ "max_input_tokens": 997952,
+ "max_output_tokens": 65536,
+ "litellm_provider": "dashscope",
+ "supports_function_calling": true,
+ "supports_tool_choice": true,
+ "supports_reasoning": true,
+ "mode": "chat",
+ "tiered_pricing": [
+ {"range": [0, 32e3], "input_cost_per_token": 1e-06, "output_cost_per_token": 5e-06},
+ {"range": [32e3, 128e3], "input_cost_per_token": 1.8e-06, "output_cost_per_token": 9e-06},
+ {"range": [128e3, 256e3], "input_cost_per_token": 3e-06, "output_cost_per_token": 1.5e-05},
+ {"range": [256e3, 1e6], "input_cost_per_token": 6e-06, "output_cost_per_token": 6e-05}
+ ],
+ "source": "https://www.alibabacloud.com/help/en/model-studio/models"
+ },
+ "dashscope/qwen3-coder-flash": {
+ "max_tokens": 1000000,
+ "max_input_tokens": 997952,
+ "max_output_tokens": 65536,
+ "litellm_provider": "dashscope",
+ "supports_function_calling": true,
+ "supports_tool_choice": true,
+ "supports_reasoning": true,
+ "supports_caching": true,
+ "mode": "chat",
+ "tiered_pricing": [
+ {"range": [0, 32e3], "input_cost_per_token": 3e-07, "output_cost_per_token": 1.5e-06, "cache_read_input_token_cost": 8e-08},
+ {"range": [32e3, 128e3], "input_cost_per_token": 5e-07, "output_cost_per_token": 2.5e-06, "cache_read_input_token_cost": 1.2e-07},
+ {"range": [128e3, 256e3], "input_cost_per_token": 8e-07, "output_cost_per_token": 4e-06, "cache_read_input_token_cost": 2e-07},
+ {"range": [256e3, 1e6], "input_cost_per_token": 1.6e-06, "output_cost_per_token": 9.6e-06, "cache_read_input_token_cost": 4e-07}
+ ],
+ "source": "https://www.alibabacloud.com/help/en/model-studio/models"
+ },
+ "dashscope/qwen3-coder-flash-2025-07-28": {
+ "max_tokens": 1000000,
+ "max_input_tokens": 997952,
+ "max_output_tokens": 65536,
+ "litellm_provider": "dashscope",
+ "supports_function_calling": true,
+ "supports_tool_choice": true,
+ "supports_reasoning": true,
+ "mode": "chat",
+ "tiered_pricing": [
+ {"range": [0, 32e3], "input_cost_per_token": 3e-07, "output_cost_per_token": 1.5e-06},
+ {"range": [32e3, 128e3], "input_cost_per_token": 5e-07, "output_cost_per_token": 2.5e-06},
+ {"range": [128e3, 256e3], "input_cost_per_token": 8e-07, "output_cost_per_token": 4e-06},
+ {"range": [256e3, 1e6], "input_cost_per_token": 1.6e-06, "output_cost_per_token": 9.6e-06}
+ ],
+ "source": "https://www.alibabacloud.com/help/en/model-studio/models"
+ },
+ "dashscope/qwen-plus-2025-09-11": {
+ "max_tokens": 1000000,
+ "max_input_tokens": 997952,
+ "max_output_tokens": 32768,
+ "litellm_provider": "dashscope",
+ "supports_function_calling": true,
+ "supports_tool_choice": true,
+ "supports_reasoning": true,
+ "mode": "chat",
+ "tiered_pricing": [
+ {"range": [0, 256e3], "input_cost_per_token": 4e-07, "output_cost_per_token": 1.2e-06, "output_cost_per_reasoning_token": 4e-06},
+ {"range": [256e3, 1e6], "input_cost_per_token": 1.2e-06, "output_cost_per_token": 3.6e-06, "output_cost_per_reasoning_token": 1.2e-05}
+ ],
+ "source": "https://www.alibabacloud.com/help/en/model-studio/models"
+ },
+ "dashscope/qwen-plus-2025-07-28": {
+ "max_tokens": 1000000,
+ "max_input_tokens": 997952,
+ "max_output_tokens": 32768,
+ "litellm_provider": "dashscope",
+ "supports_function_calling": true,
+ "supports_tool_choice": true,
+ "supports_reasoning": true,
+ "mode": "chat",
+ "tiered_pricing": [
+ {"range": [0, 256e3], "input_cost_per_token": 4e-07, "output_cost_per_token": 1.2e-06, "output_cost_per_reasoning_token": 4e-06},
+ {"range": [256e3, 1e6], "input_cost_per_token": 1.2e-06, "output_cost_per_token": 3.6e-06, "output_cost_per_reasoning_token": 1.2e-05}
+ ],
+ "source": "https://www.alibabacloud.com/help/en/model-studio/models"
+ },
+ "dashscope/qwen-plus-2025-07-14": {
+ "max_tokens": 131072,
+ "max_input_tokens": 129024,
+ "max_output_tokens": 16384,
+ "input_cost_per_token": 4e-07,
+ "output_cost_per_token": 1.2e-06,
+ "output_cost_per_reasoning_token": 4e-06,
+ "litellm_provider": "dashscope",
+ "supports_function_calling": true,
+ "supports_tool_choice": true,
+ "supports_reasoning": true,
+ "mode": "chat",
+ "source": "https://www.alibabacloud.com/help/en/model-studio/models"
+ },
+ "dashscope/qwen-plus-2025-04-28": {
+ "max_tokens": 131072,
+ "max_input_tokens": 129024,
+ "max_output_tokens": 16384,
+ "input_cost_per_token": 4e-07,
+ "output_cost_per_token": 1.2e-06,
+ "output_cost_per_reasoning_token": 4e-06,
+ "litellm_provider": "dashscope",
+ "supports_function_calling": true,
+ "supports_tool_choice": true,
+ "supports_reasoning": true,
+ "mode": "chat",
+ "source": "https://www.alibabacloud.com/help/en/model-studio/models"
+ },
+ "dashscope/qwen-plus-2025-01-25": {
+ "max_tokens": 131072,
+ "max_input_tokens": 129024,
+ "max_output_tokens": 8192,
+ "input_cost_per_token": 4e-07,
+ "output_cost_per_token": 1.2e-06,
+ "litellm_provider": "dashscope",
+ "supports_function_calling": true,
+ "supports_tool_choice": true,
+ "supports_reasoning": true,
+ "mode": "chat",
+ "source": "https://www.alibabacloud.com/help/en/model-studio/models"
+ },
+ "dashscope/qwen-flash-2025-07-28": {
+ "max_tokens": 1000000,
+ "max_input_tokens": 997952,
+ "max_output_tokens": 32768,
+ "litellm_provider": "dashscope",
+ "supports_function_calling": true,
+ "supports_tool_choice": true,
+ "supports_reasoning": true,
+ "supports_caching": true,
+ "mode": "chat",
+ "tiered_pricing": [
+ {"range": [0, 256e3], "input_cost_per_token": 5e-08, "output_cost_per_token": 4e-07},
+ {"range": [256e3, 1e6], "input_cost_per_token": 2.5e-07, "output_cost_per_token": 2e-06}
+ ],
+ "source": "https://www.alibabacloud.com/help/en/model-studio/models"
+ },
+ "dashscope/qwen-turbo": {
"max_tokens": 131072,
"max_input_tokens": 129024,
"max_output_tokens": 16384,
+ "input_cost_per_token": 5e-08,
+ "output_cost_per_token": 2e-07,
+ "output_cost_per_reasoning_token": 5e-07,
+ "litellm_provider": "dashscope",
+ "supports_function_calling": true,
+ "supports_tool_choice": true,
+ "supports_reasoning": true,
+ "mode": "chat",
+ "source": "https://www.alibabacloud.com/help/en/model-studio/models"
+ },
+ "dashscope/qwen-turbo-2025-04-28": {
+ "max_tokens": 1000000,
+ "max_input_tokens": 1000000,
+ "max_output_tokens": 16384,
+ "input_cost_per_token": 5e-08,
+ "output_cost_per_token": 2e-07,
+ "output_cost_per_reasoning_token": 5e-07,
+ "litellm_provider": "dashscope",
+ "supports_function_calling": true,
+ "supports_tool_choice": true,
+ "supports_reasoning": true,
+ "mode": "chat",
+ "source": "https://www.alibabacloud.com/help/en/model-studio/models"
+ },
+ "dashscope/qwen-turbo-2024-11-01": {
+ "max_tokens": 1000000,
+ "max_input_tokens": 1000000,
+ "max_output_tokens": 8192,
+ "input_cost_per_token": 5e-08,
+ "output_cost_per_token": 2e-07,
+ "litellm_provider": "dashscope",
+ "supports_function_calling": true,
+ "supports_tool_choice": true,
+ "supports_reasoning": true,
+ "mode": "chat",
+ "source": "https://www.alibabacloud.com/help/en/model-studio/models"
+ },
+ "dashscope/qwq-plus": {
+ "max_tokens": 131072,
+ "max_input_tokens": 98304,
+ "max_output_tokens": 8192,
+ "max_chain_of_thought_tokens": 32768,
+ "input_cost_per_token": 8e-07,
+ "output_cost_per_token": 2.4e-06,
"litellm_provider": "dashscope",
"supports_function_calling": true,
"supports_tool_choice": true,
"supports_reasoning": true,
"mode": "chat",
- "source": "https://bailian.console.alibabacloud.com/?spm=a2c63.p38356.0.0.4a615d7bjSUCb4&tab=doc#/doc/?type=model&url=https%3A%2F%2Fwww.alibabacloud.com%2Fhelp%2Fen%2Fdoc-detail%2F2840914.html"
+ "source": "https://www.alibabacloud.com/help/en/model-studio/models"
},
"moonshot/moonshot-v1-8k": {
"max_tokens": 8192,
diff --git a/tests/test_litellm/llms/dashscope/test_dashscope_cost_calculator.py b/tests/test_litellm/llms/dashscope/test_dashscope_cost_calculator.py
new file mode 100644
index 00000000000..73e992e22d1
--- /dev/null
+++ b/tests/test_litellm/llms/dashscope/test_dashscope_cost_calculator.py
@@ -0,0 +1,159 @@
+"""
+Test suite for Dashscope cost calculation functionality.
+
+Tests the cost calculation for Dashscope models including:
+- Tiered pricing based on input token ranges
+- Caching discounts
+- Reasoning tokens
+- Standard flat pricing fallback
+"""
+
+import json
+import math
+import os
+import sys
+
+import pytest
+
+# Add the project root to Python path
+sys.path.insert(0, os.path.abspath("../../../.."))
+
+import litellm
+from litellm.llms.dashscope.cost_calculator import (
+ cost_per_token as dashscope_cost_per_token,
+)
+from litellm.types.utils import (
+ CompletionTokensDetailsWrapper,
+ PromptTokensDetailsWrapper,
+ Usage,
+)
+
+
+class TestDashscopeCostCalculator:
+ """Test suite for Dashscope cost calculation functionality."""
+
+ @pytest.fixture(autouse=True)
+ def setup_model_cost_map(self):
+ """Set up the model cost map for testing."""
+ # Ensure we use local model cost map for consistent testing
+ os.environ["LITELLM_LOCAL_MODEL_COST_MAP"] = "True"
+
+ # Find the project root directory and load model cost map
+ current_dir = os.path.dirname(os.path.abspath(__file__))
+ project_root = current_dir
+ while not os.path.exists(os.path.join(project_root, "model_prices_and_context_window.json")):
+ parent = os.path.dirname(project_root)
+ if parent == project_root: # Reached filesystem root
+ break
+ project_root = parent
+
+ model_cost_path = os.path.join(project_root, "model_prices_and_context_window.json")
+ with open(model_cost_path, "r") as f:
+ model_cost_map = json.load(f)
+ litellm.model_cost = model_cost_map
+
+ def test_flat_pricing_basic_cost_calculation(self):
+ """Test basic cost calculation for flat pricing models (qwen-max)."""
+ usage = Usage(
+ prompt_tokens=1000,
+ completion_tokens=500,
+ total_tokens=1500
+ )
+
+ prompt_cost, completion_cost = dashscope_cost_per_token(
+ model="qwen-max",
+ usage=usage
+ )
+
+ # Expected costs for qwen-max:
+ # Input: 1000 tokens * $1.6e-6 = $0.0016
+ # Output: 500 tokens * $6.4e-6 = $0.0032
+ expected_prompt_cost = 1000 * 1.6e-6
+ expected_completion_cost = 500 * 6.4e-6
+
+ assert math.isclose(prompt_cost, expected_prompt_cost, rel_tol=1e-10)
+ assert math.isclose(completion_cost, expected_completion_cost, rel_tol=1e-10)
+
+ def test_tiered_pricing_single_tier(self):
+ """Test tiered pricing when all tokens fall within first tier."""
+ usage = Usage(
+ prompt_tokens=20000, # Within first tier (0-32K)
+ completion_tokens=1000,
+ total_tokens=21000
+ )
+
+ prompt_cost, completion_cost = dashscope_cost_per_token(
+ model="qwen3-coder-plus",
+ usage=usage
+ )
+
+ # Expected costs for qwen3-coder-plus (tier 1):
+ # Input: 20,000 tokens * $1e-6 = $0.02
+ # Output: 1,000 tokens * $5e-6 = $0.005
+ expected_prompt_cost = 20000 * 1e-6
+ expected_completion_cost = 1000 * 5e-6
+
+ assert math.isclose(prompt_cost, expected_prompt_cost, rel_tol=1e-10)
+ assert math.isclose(completion_cost, expected_completion_cost, rel_tol=1e-10)
+
+ def test_tiered_pricing_multiple_tiers(self):
+ """Test tiered pricing when tokens span multiple tiers."""
+ usage = Usage(
+ prompt_tokens=150000, # Spans tiers 1 (0-32K), 2 (32K-128K), 3 (128K-256K)
+ completion_tokens=2000,
+ total_tokens=152000
+ )
+
+ prompt_cost, completion_cost = dashscope_cost_per_token(
+ model="qwen3-coder-plus",
+ usage=usage
+ )
+
+ # Expected input cost calculation:
+ # Tier 1 (0-32K): 32,000 tokens * $1e-6 = $0.032
+ # Tier 2 (32K-128K): 96,000 tokens * $1.8e-6 = $0.1728
+ # Tier 3 (128K-256K): 22,000 tokens * $3e-6 = $0.066
+ # Total input cost = $0.032 + $0.1728 + $0.066 = $0.2708
+
+ expected_prompt_cost = (32000 * 1e-6) + (96000 * 1.8e-6) + (22000 * 3e-6)
+ expected_completion_cost = 2000 * 5e-6 # All in tier 1 for output
+
+ assert math.isclose(prompt_cost, expected_prompt_cost, rel_tol=1e-10)
+ assert math.isclose(completion_cost, expected_completion_cost, rel_tol=1e-10)
+
+ def test_tiered_pricing_with_caching(self):
+ """Test tiered pricing with cached tokens."""
+ prompt_tokens_details = PromptTokensDetailsWrapper(
+ cached_tokens=10000 # 10K cached tokens
+ )
+
+ usage = Usage(
+ prompt_tokens=50000, # 40K regular + 10K cached = 50K total
+ completion_tokens=1000,
+ total_tokens=51000,
+ prompt_tokens_details=prompt_tokens_details
+ )
+
+ prompt_cost, completion_cost = dashscope_cost_per_token(
+ model="qwen3-coder-plus",
+ usage=usage
+ )
+
+ # Expected cost calculation:
+ # Regular tokens: 40,000 (32K in tier 1 + 8K in tier 2)
+ # - Tier 1: 32,000 * $1e-6 = $0.032
+ # - Tier 2: 8,000 * $1.8e-6 = $0.0144
+ # Cached tokens: 10,000 in tier 1 at discounted rate
+ # - Tier 1 cached: 10,000 * $1e-7 = $0.001
+ # Total input cost = $0.032 + $0.0144 + $0.001 = $0.0474
+
+ regular_tokens = 40000
+ cached_tokens = 10000
+
+ expected_regular_cost = (32000 * 1e-6) + (8000 * 1.8e-6)
+ expected_cached_cost = cached_tokens * 1e-7 # Tier 1 cached rate
+ expected_prompt_cost = expected_regular_cost + expected_cached_cost
+ expected_completion_cost = 1000 * 5e-6
+
+ assert math.isclose(prompt_cost, expected_prompt_cost, rel_tol=1e-10)
+ assert math.isclose(completion_cost, expected_completion_cost, rel_tol=1e-10)
\ No newline at end of file
diff --git a/ui/litellm-dashboard/src/components/provider_info_helpers.tsx b/ui/litellm-dashboard/src/components/provider_info_helpers.tsx
index 31f5b10043b..17aa637af89 100644
--- a/ui/litellm-dashboard/src/components/provider_info_helpers.tsx
+++ b/ui/litellm-dashboard/src/components/provider_info_helpers.tsx
@@ -11,8 +11,9 @@ export enum Providers {
Azure = "Azure",
Azure_AI_Studio = "Azure AI Foundry (Studio)",
Cerebras = "Cerebras",
- Cohere = "Cohere",
- Databricks = "Databricks",
+ Cohere = "Cohere",
+ Dashscope = "Dashscope",
+ Databricks = "Databricks (Qwen API)",
DeepInfra = "DeepInfra",
Deepgram = "Deepgram",
Deepseek = "Deepseek",
@@ -37,7 +38,7 @@ export enum Providers {
Vertex_AI = "Vertex AI (Anthropic, Gemini, etc.)",
VolcEngine = "VolcEngine",
Voyage = "Voyage AI",
- xAI = "xAI",
+ xAI = "xAI",
}
export const provider_map: Record<string, string> = {
@@ -56,6 +57,7 @@ export const provider_map: Record<string, string> = {
OpenAI_Text_Compatible: "text-completion-openai",
Vertex_AI: "vertex_ai",
Databricks: "databricks",
+ Dashscope: "dashscope",
xAI: "xai",
Deepseek: "deepseek",
Ollama: "ollama",
@@ -91,6 +93,7 @@ export const providerLogoMap: Record<string, string> = {
[Providers.Cerebras]: `${asset_logos_folder}cerebras.svg`,
[Providers.Cohere]: `${asset_logos_folder}cohere.svg`,
[Providers.Databricks]: `${asset_logos_folder}databricks.svg`,
+ [Providers.Dashscope]: `${asset_logos_folder}dashscope.svg`,
[Providers.Deepseek]: `${asset_logos_folder}deepseek.svg`,
[Providers.FireworksAI]: `${asset_logos_folder}fireworks.svg`,
[Providers.Groq]: `${asset_logos_folder}groq.svg`,