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(fal_ai): strip provider prefix before keyed cost lookup

github-actions[bot]d5e6a0c9b8b2
diff --git a/litellm/llms/fal_ai/cost_calculator.py b/litellm/llms/fal_ai/cost_calculator.py
index b2320de247e..74848784c5b 100644
--- a/litellm/llms/fal_ai/cost_calculator.py
+++ b/litellm/llms/fal_ai/cost_calculator.py
@@ -61,6 +61,8 @@ def cost_calculator(
"""
if not isinstance(image_response, ImageResponse):
raise ValueError(f"image_response must be of type ImageResponse got type={type(image_response)}")
+ # the proxy cost path passes the provider-prefixed model name
+ model = model.removeprefix(f"{litellm.LlmProviders.FAL_AI.value}/")
num_images: Final[int] = len(image_response.data) if image_response.data else 0
keyed_cost_per_image: Final = _keyed_cost_per_image(model=model, optional_params=optional_params)
if keyed_cost_per_image is not None:
diff --git a/tests/test_litellm/llms/fal_ai/test_cost_calculator.py b/tests/test_litellm/llms/fal_ai/test_cost_calculator.py
index 689b620a90b..f167aceaa95 100644
--- a/tests/test_litellm/llms/fal_ai/test_cost_calculator.py
+++ b/tests/test_litellm/llms/fal_ai/test_cost_calculator.py
@@ -37,6 +37,24 @@ def test_alias_model_uses_keyed_price():
assert cost == pytest.approx(0.211)
+def test_provider_prefixed_model_uses_keyed_price():
+ cost = cost_calculator(
+ model="fal_ai/openai/gpt-image-2",
+ image_response=_image_response(),
+ optional_params={"quality": "high", "image_size": {"width": 1024, "height": 1024}},
+ )
+ assert cost == pytest.approx(0.211)
+
+
+def test_provider_prefixed_edit_model_uses_keyed_edit_price():
+ cost = cost_calculator(
+ model="fal_ai/openai/gpt-image-2/edit",
+ image_response=_image_response(),
+ optional_params={"quality": "high", "image_size": {"width": 1024, "height": 1024}},
+ )
+ assert cost == pytest.approx(0.219)
+
+
def test_default_request_priced_at_default_size_and_quality():
cost = cost_calculator(
model="openai/gpt-image-2",
@@ -126,3 +144,13 @@ def test_route_image_generation_passes_optional_params_to_fal():
optional_params={"quality": "high", "image_size": {"width": 1024, "height": 1024}},
)
assert cost == pytest.approx(0.211)
+
+
+def test_route_image_generation_with_provider_prefixed_model_uses_keyed_price():
+ cost = CostCalculatorUtils.route_image_generation_cost_calculator(
+ model="fal_ai/openai/gpt-image-2",
+ completion_response=_image_response(),
+ custom_llm_provider="fal_ai",
+ optional_params={"quality": "high", "image_size": {"width": 1024, "height": 1024}},
+ )
+ assert cost == pytest.approx(0.211)