diff --git a/litellm/llms/fireworks_ai/common_utils.py b/litellm/llms/fireworks_ai/common_utils.py index 10314d3fac4..84bddf58491 100644 --- a/litellm/llms/fireworks_ai/common_utils.py +++ b/litellm/llms/fireworks_ai/common_utils.py @@ -5,6 +5,7 @@ from typing import Final from httpx import Headers from litellm.constants import SESSION_ID_GENERATED_METADATA_KEY +from litellm.litellm_core_utils.get_model_cost_map import GetModelCostMap from litellm.secret_managers.main import get_secret_str from litellm.types.llms.openai import AllMessageValues @@ -90,13 +91,26 @@ FIREROUTER: Final = "firerouter" ROUTER_SHORT_NAMES: Final = frozenset({FIREROUTER, "auto", "auto-instant"}) +def _priced_only_as_router(short_name: str) -> bool: + catalog: Final = GetModelCostMap.loaded_model_cost_map() + return ( + f"fireworks_ai/accounts/fireworks/routers/{short_name}" in catalog + and f"fireworks_ai/accounts/fireworks/models/{short_name}" not in catalog + ) + + def resolve_fireworks_resource_name(model: str) -> str: stripped: Final = model.removeprefix("fireworks_ai/") if stripped.startswith(("accounts/", AZURE_FOUNDRY_FIREWORKS_MODEL_ID_PREFIX)) or "#" in stripped: return stripped if stripped.startswith(("routers/", "models/")): return f"accounts/fireworks/{stripped}" - if stripped.endswith("-fast") or stripped in ROUTER_SHORT_NAMES or stripped.startswith(f"{FIREROUTER}/"): + if ( + stripped.endswith("-fast") + or stripped in ROUTER_SHORT_NAMES + or stripped.startswith(f"{FIREROUTER}/") + or _priced_only_as_router(stripped) + ): return f"accounts/fireworks/routers/{stripped}" return f"accounts/fireworks/models/{stripped}" diff --git a/litellm/model_prices_and_context_window_backup.json b/litellm/model_prices_and_context_window_backup.json index 0799a298942..f15e1c63f1b 100644 --- a/litellm/model_prices_and_context_window_backup.json +++ b/litellm/model_prices_and_context_window_backup.json @@ -77192,7 +77192,7 @@ "text" ] }, - "fireworks_ai/accounts/fireworks/models/deepseek-v4p1-flash-1017-us": { + "fireworks_ai/accounts/fireworks/routers/deepseek-v4p1-flash-1017-us": { "cache_read_input_token_cost": 9e-09, "cache_read_input_token_cost_priority": 1.125e-08, "input_cost_per_token": 4.5e-07, diff --git a/model_prices_and_context_window.json b/model_prices_and_context_window.json index 0799a298942..f15e1c63f1b 100644 --- a/model_prices_and_context_window.json +++ b/model_prices_and_context_window.json @@ -77192,7 +77192,7 @@ "text" ] }, - "fireworks_ai/accounts/fireworks/models/deepseek-v4p1-flash-1017-us": { + "fireworks_ai/accounts/fireworks/routers/deepseek-v4p1-flash-1017-us": { "cache_read_input_token_cost": 9e-09, "cache_read_input_token_cost_priority": 1.125e-08, "input_cost_per_token": 4.5e-07, diff --git a/tests/unit/llms/fireworks_ai/test_fireworks_ai_common_utils.py b/tests/unit/llms/fireworks_ai/test_fireworks_ai_common_utils.py index 7ebbd0c6a8a..3a28446fef7 100644 --- a/tests/unit/llms/fireworks_ai/test_fireworks_ai_common_utils.py +++ b/tests/unit/llms/fireworks_ai/test_fireworks_ai_common_utils.py @@ -1,6 +1,9 @@ +from typing import Final + import pytest -from litellm.llms.fireworks_ai.common_utils import resolve_fireworks_resource_name +from litellm.litellm_core_utils.get_model_cost_map import GetModelCostMap +from litellm.llms.fireworks_ai.common_utils import ROUTER_SHORT_NAMES, resolve_fireworks_resource_name @pytest.mark.parametrize( @@ -52,3 +55,29 @@ from litellm.llms.fireworks_ai.common_utils import resolve_fireworks_resource_na ) def test_resolve_fireworks_resource_name(model, expected): assert resolve_fireworks_resource_name(model) == expected + + +def _priced_fireworks_names(kind: str) -> frozenset[str]: + prefix: Final = f"fireworks_ai/accounts/fireworks/{kind}/" + catalog: Final = GetModelCostMap.loaded_model_cost_map() + return frozenset(key.removeprefix(prefix) for key in catalog if key.startswith(prefix)) + + +def test_a_short_name_priced_only_as_a_router_resolves_to_the_router(): + router_only: Final = _priced_fireworks_names("routers") - _priced_fireworks_names("models") + assert router_only + assert {name: resolve_fireworks_resource_name(f"fireworks_ai/{name}") for name in router_only} == { + name: f"accounts/fireworks/routers/{name}" for name in router_only + } + + +def test_a_short_name_priced_as_a_model_keeps_the_model_path(): + model_names: Final = frozenset( + name + for name in _priced_fireworks_names("models") + if not name.endswith("-fast") and name not in ROUTER_SHORT_NAMES + ) + assert model_names + assert {name: resolve_fireworks_resource_name(f"fireworks_ai/{name}") for name in model_names} == { + name: f"accounts/fireworks/models/{name}" for name in model_names + }