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
perf: skip output cost lookups when no audio/reasoning/image tokens
Ryan Crabbeeab8bb4e0610
diff --git a/litellm/litellm_core_utils/llm_cost_calc/utils.py b/litellm/litellm_core_utils/llm_cost_calc/utils.pyindex d1a47efde7e..38cd69110d5 100644--- a/litellm/litellm_core_utils/llm_cost_calc/utils.py+++ b/litellm/litellm_core_utils/llm_cost_calc/utils.py@@ -688,18 +688,11 @@ def generic_cost_per_token( # noqa: PLR0915## TEXT COSTcompletion_cost = float(text_tokens) * completion_base_cost- _output_cost_per_audio_token = _get_cost_per_unit(- model_info, "output_cost_per_audio_token", None- )- _output_cost_per_reasoning_token = _get_cost_per_unit(- model_info, "output_cost_per_reasoning_token", None- )- _output_cost_per_image_token = _get_cost_per_unit(- model_info, "output_cost_per_image_token", None- )-## AUDIO COSTif not is_text_tokens_total and audio_tokens is not None and audio_tokens > 0:+ _output_cost_per_audio_token = _get_cost_per_unit(+ model_info, "output_cost_per_audio_token", None+ )_output_cost_per_audio_token = (_output_cost_per_audio_tokenif _output_cost_per_audio_token is not None@@ -709,6 +702,9 @@ def generic_cost_per_token( # noqa: PLR0915## REASONING COSTif not is_text_tokens_total and reasoning_tokens and reasoning_tokens > 0:+ _output_cost_per_reasoning_token = _get_cost_per_unit(+ model_info, "output_cost_per_reasoning_token", None+ )_output_cost_per_reasoning_token = (_output_cost_per_reasoning_tokenif _output_cost_per_reasoning_token is not None@@ -718,6 +714,9 @@ def generic_cost_per_token( # noqa: PLR0915## IMAGE COSTif not is_text_tokens_total and image_tokens and image_tokens > 0:+ _output_cost_per_image_token = _get_cost_per_unit(+ model_info, "output_cost_per_image_token", None+ )_output_cost_per_image_token = (_output_cost_per_image_tokenif _output_cost_per_image_token is not None