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
fix(fireworks_ai): support router slugs via routers/ prefix
heathriel1d8a642e0683
diff --git a/litellm/llms/fireworks_ai/chat/transformation.py b/litellm/llms/fireworks_ai/chat/transformation.pyindex a796aa47b70..26f0caefacd 100644--- a/litellm/llms/fireworks_ai/chat/transformation.py+++ b/litellm/llms/fireworks_ai/chat/transformation.py@@ -39,7 +39,11 @@ from ...openai.chat.gpt_transformation import (OpenAIChatCompletionStreamingHandler,OpenAIGPTConfig,)-from ..common_utils import FireworksAIException, FireworksAIMixin+from ..common_utils import (+ FireworksAIException,+ FireworksAIMixin,+ resolve_fireworks_resource_name,+)def _extract_fireworks_hidden_params(payload: dict) -> dict:@@ -459,12 +463,10 @@ class FireworksAIConfig(FireworksAIMixin, OpenAIGPTConfig):litellm_params: dict,headers: dict,) -> dict:- if not model.startswith("accounts/") and "#" not in model:- if model.endswith("-fast"):- model = f"accounts/fireworks/routers/{model}"- else:- model = f"accounts/fireworks/models/{model}"- messages = self._transform_messages_helper(messages=messages, model=model, litellm_params=litellm_params)+ resolved_model: Final = resolve_fireworks_resource_name(model)+ messages = self._transform_messages_helper(+ messages=messages, model=resolved_model, litellm_params=litellm_params+ )if "tools" in optional_params and optional_params["tools"] is not None:tools: Final = self._transform_tools(tools=optional_params["tools"])optional_params["tools"] = tools@@ -478,7 +480,7 @@ class FireworksAIConfig(FireworksAIMixin, OpenAIGPTConfig):"include_usage": True,}return super().transform_request(- model=model,+ model=resolved_model,messages=messages,optional_params=optional_params,litellm_params=litellm_params,diff --git a/litellm/llms/fireworks_ai/common_utils.py b/litellm/llms/fireworks_ai/common_utils.pyindex 143dd151027..e07e7a26f9e 100644--- a/litellm/llms/fireworks_ai/common_utils.py+++ b/litellm/llms/fireworks_ai/common_utils.py@@ -29,6 +29,17 @@ def get_fireworks_session_id(litellm_params: dict) -> str | None:return None+def resolve_fireworks_resource_name(model: str) -> str:+ stripped: Final = model.removeprefix("fireworks_ai/")+ if stripped.startswith("accounts/") or "#" in stripped:+ return stripped+ if stripped.startswith(("routers/", "models/")):+ return f"accounts/fireworks/{stripped}"+ if stripped.endswith("-fast"):+ return f"accounts/fireworks/routers/{stripped}"+ return f"accounts/fireworks/models/{stripped}"++class FireworksAIMixin:"""Common Base Config functions across Fireworks AI Endpointsdiff --git a/litellm/llms/fireworks_ai/completion/transformation.py b/litellm/llms/fireworks_ai/completion/transformation.pyindex c141e097d3a..c460510f39c 100644--- a/litellm/llms/fireworks_ai/completion/transformation.py+++ b/litellm/llms/fireworks_ai/completion/transformation.py@@ -4,7 +4,7 @@ from litellm.types.llms.openai import AllMessageValues, OpenAITextCompletionUserfrom ...base_llm.completion.transformation import BaseTextCompletionConfigfrom ...openai.completion.utils import _transform_prompt-from ..common_utils import FireworksAIMixin+from ..common_utils import FireworksAIMixin, resolve_fireworks_resource_nameclass FireworksAITextCompletionConfig(FireworksAIMixin, BaseTextCompletionConfig):@@ -50,11 +50,8 @@ class FireworksAITextCompletionConfig(FireworksAIMixin, BaseTextCompletionConfig) -> dict:prompt: Final = _transform_prompt(messages=messages)- if not model.startswith("accounts/") and "#" not in model:- model = f"accounts/fireworks/models/{model}"-data: Final = {- "model": model,+ "model": resolve_fireworks_resource_name(model),"prompt": prompt,**optional_params,}diff --git a/tests/test_litellm/llms/fireworks_ai/chat/test_fireworks_ai_chat_transformation.py b/tests/test_litellm/llms/fireworks_ai/chat/test_fireworks_ai_chat_transformation.pyindex 94945ed4bfb..87908ef60c3 100644--- a/tests/test_litellm/llms/fireworks_ai/chat/test_fireworks_ai_chat_transformation.py+++ b/tests/test_litellm/llms/fireworks_ai/chat/test_fireworks_ai_chat_transformation.py@@ -1282,3 +1282,46 @@ def test_streaming_surfaces_fireworks_response_fields():assert surfaced["fireworks_raw_outputs"] == [raw_output]assert surfaced["fireworks_perf_metrics"] == {"prompt-tokens": 5}assert surfaced["fireworks_prompt_token_ids"] == [1, 2, 3]+++def test_transform_request_routes_router_slug():+ config = FireworksAIConfig()++ data = config.transform_request(+ model="routers/glm-latest",+ messages=[{"role": "user", "content": "hi"}],+ optional_params={},+ litellm_params={},+ headers={},+ )++ assert data["model"] == "accounts/fireworks/routers/glm-latest"+++def test_transform_request_bare_slug_stays_model():+ config = FireworksAIConfig()++ data = config.transform_request(+ model="glm-4p6",+ messages=[{"role": "user", "content": "hi"}],+ optional_params={},+ litellm_params={},+ headers={},+ )++ assert data["model"] == "accounts/fireworks/models/glm-4p6"+++def test_transform_request_direct_route_passthrough():+ config = FireworksAIConfig()+ model = "accounts/fireworks/models/qwen2p5-coder-7b#accounts/gitlab/deployments/2fb7764c"++ data = config.transform_request(+ model=model,+ messages=[{"role": "user", "content": "hi"}],+ optional_params={},+ litellm_params={},+ headers={},+ )++ assert data["model"] == modeldiff --git a/tests/test_litellm/llms/fireworks_ai/completion/test_fireworks_ai_completion_transformation.py b/tests/test_litellm/llms/fireworks_ai/completion/test_fireworks_ai_completion_transformation.pynew file mode 100644index 00000000000..996f1fd975b--- /dev/null+++ b/tests/test_litellm/llms/fireworks_ai/completion/test_fireworks_ai_completion_transformation.py@@ -0,0 +1,34 @@+import os+import sys++sys.path.insert(0, os.path.abspath("../../../../.."))++from litellm.llms.fireworks_ai.completion.transformation import (+ FireworksAITextCompletionConfig,+)+++def test_transform_text_completion_request_routes_router_slug():+ config = FireworksAITextCompletionConfig()++ data = config.transform_text_completion_request(+ model="routers/glm-latest",+ messages=[{"role": "user", "content": "hi"}],+ optional_params={},+ headers={},+ )++ assert data["model"] == "accounts/fireworks/routers/glm-latest"+++def test_transform_text_completion_request_bare_slug_stays_model():+ config = FireworksAITextCompletionConfig()++ data = config.transform_text_completion_request(+ model="glm-4p6",+ messages=[{"role": "user", "content": "hi"}],+ optional_params={},+ headers={},+ )++ assert data["model"] == "accounts/fireworks/models/glm-4p6"diff --git a/tests/test_litellm/llms/fireworks_ai/test_fireworks_ai_common_utils.py b/tests/test_litellm/llms/fireworks_ai/test_fireworks_ai_common_utils.pynew file mode 100644index 00000000000..4af395baf41--- /dev/null+++ b/tests/test_litellm/llms/fireworks_ai/test_fireworks_ai_common_utils.py@@ -0,0 +1,45 @@+import os+import sys++import pytest++sys.path.insert(0, os.path.abspath("../../../.."))++from litellm.llms.fireworks_ai.common_utils import resolve_fireworks_resource_name+++ "model, expected",+ [+ ("routers/glm-latest", "accounts/fireworks/routers/glm-latest"),+ ("routers/firerouter", "accounts/fireworks/routers/firerouter"),+ ("fireworks_ai/routers/glm-latest", "accounts/fireworks/routers/glm-latest"),+ ("models/glm-4p6", "accounts/fireworks/models/glm-4p6"),+ ("fireworks_ai/models/glm-4p6", "accounts/fireworks/models/glm-4p6"),+ ("glm-4p6", "accounts/fireworks/models/glm-4p6"),+ ("fireworks_ai/glm-4p6", "accounts/fireworks/models/glm-4p6"),+ ("kimi-k2p6-fast", "accounts/fireworks/routers/kimi-k2p6-fast"),+ (+ "accounts/fireworks/routers/glm-latest",+ "accounts/fireworks/routers/glm-latest",+ ),+ (+ "accounts/fireworks/models/glm-4p6",+ "accounts/fireworks/models/glm-4p6",+ ),+ (+ "fireworks_ai/accounts/fireworks/routers/glm-latest",+ "accounts/fireworks/routers/glm-latest",+ ),+ (+ "accounts/fireworks/models/qwen2p5-coder-7b#accounts/gitlab/deployments/2fb7764c",+ "accounts/fireworks/models/qwen2p5-coder-7b#accounts/gitlab/deployments/2fb7764c",+ ),+ (+ "glm-4p6#accounts/gitlab/deployments/2fb7764c",+ "glm-4p6#accounts/gitlab/deployments/2fb7764c",+ ),+ ],+)+def test_resolve_fireworks_resource_name(model, expected):+ assert resolve_fireworks_resource_name(model) == expecteddiff --git a/type-discipline-budget.json b/type-discipline-budget.jsonindex ab8198304bb..d9038e20df9 100644--- a/type-discipline-budget.json+++ b/type-discipline-budget.json@@ -30,6 +30,6 @@"limit": 16783},"LIT011": {- "limit": 5602+ "limit": 5599}}