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]

fix optimize get llm provider

Ishaan Jaffbb1489eced60
diff --git a/litellm/cost_calculator.py b/litellm/cost_calculator.py
index ecddcc0eef7..14b1f036c13 100644
--- a/litellm/cost_calculator.py
+++ b/litellm/cost_calculator.py
@@ -629,17 +629,17 @@ def completion_cost( # noqa: PLR0915
raise ValueError(
f"Model is None and does not exist in passed completion_response. Passed completion_response={completion_response}, model={model}"
)
-
- try:
- model, custom_llm_provider, _, _ = litellm.get_llm_provider(
- model=model
- ) # strip the llm provider from the model name -> for image gen cost calculation
- except Exception as e:
- verbose_logger.debug(
- "litellm.cost_calculator.py::completion_cost() - Error inferring custom_llm_provider - {}".format(
- str(e)
+ if custom_llm_provider is None:
+ try:
+ model, custom_llm_provider, _, _ = litellm.get_llm_provider(
+ model=model
+ ) # strip the llm provider from the model name -> for image gen cost calculation
+ except Exception as e:
+ verbose_logger.debug(
+ "litellm.cost_calculator.py::completion_cost() - Error inferring custom_llm_provider - {}".format(
+ str(e)
+ )
)
- )
if (
call_type == CallTypes.image_generation.value
or call_type == CallTypes.aimage_generation.value