From 86c405eef98c6e06b72e1f528ca5f8fbfeb29ed8 Mon Sep 17 00:00:00 2001 From: Frank Deng Date: Sat, 25 Apr 2026 19:03:38 -0700 Subject: [PATCH] override auth header --- litellm/llms/fireworks_ai/chat/transformation.py | 8 +++++++- litellm/llms/fireworks_ai/messages/transformation.py | 2 +- .../messages/test_fireworks_ai_messages_transformation.py | 4 ++-- .../test_fireworks_ai_responses_transformation.py | 4 ++-- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/litellm/llms/fireworks_ai/chat/transformation.py b/litellm/llms/fireworks_ai/chat/transformation.py index 2081c80a987..a7ea90ad408 100644 --- a/litellm/llms/fireworks_ai/chat/transformation.py +++ b/litellm/llms/fireworks_ai/chat/transformation.py @@ -70,7 +70,9 @@ class FireworksAIConfig(OpenAIGPTConfig): Parameter handling ------------------ - All standard OpenAI params are passed through (``tool_choice``, - ``response_format``, ``max_completion_tokens``, ``strict`` in tools). + ``response_format``, ``strict`` in tools). + - ``max_completion_tokens`` is mapped to ``max_tokens`` (Fireworks + treats it as an alias and rejects requests with both). - Additional Fireworks-supported params: ``top_k``, ``top_logprobs``, ``seed``, ``logit_bias``, ``parallel_tool_calls``, ``thinking``, ``prompt_truncate_length``, ``context_length_exceeded_behavior``. @@ -180,6 +182,10 @@ class FireworksAIConfig(OpenAIGPTConfig): optional_params["tool_choice"] = value elif param == "response_format": optional_params["response_format"] = value + elif param == "max_completion_tokens": + # Fireworks treats max_completion_tokens as an alias for max_tokens + # and rejects requests containing both. Normalize to max_tokens. + optional_params["max_tokens"] = value elif param in supported_openai_params: if value is not None: optional_params[param] = value diff --git a/litellm/llms/fireworks_ai/messages/transformation.py b/litellm/llms/fireworks_ai/messages/transformation.py index 6f4256f1758..2fbebb6aa94 100644 --- a/litellm/llms/fireworks_ai/messages/transformation.py +++ b/litellm/llms/fireworks_ai/messages/transformation.py @@ -33,7 +33,7 @@ class FireworksAIMessagesConfig(AnthropicMessagesConfig): or get_secret_str("FIREWORKSAI_API_KEY") or get_secret_str("FIREWORKS_AI_TOKEN") ) - if api_key and "Authorization" not in headers: + if api_key: headers["Authorization"] = f"Bearer {api_key}" if "content-type" not in headers: headers["content-type"] = "application/json" diff --git a/tests/test_litellm/llms/fireworks_ai/messages/test_fireworks_ai_messages_transformation.py b/tests/test_litellm/llms/fireworks_ai/messages/test_fireworks_ai_messages_transformation.py index 76957f6f25f..bb928807f53 100644 --- a/tests/test_litellm/llms/fireworks_ai/messages/test_fireworks_ai_messages_transformation.py +++ b/tests/test_litellm/llms/fireworks_ai/messages/test_fireworks_ai_messages_transformation.py @@ -62,7 +62,7 @@ class TestValidateAnthropicMessagesEnvironment: ) assert headers["Authorization"] == "Bearer ai-env-key" - def test_should_not_overwrite_existing_authorization(self, config): + def test_should_override_existing_authorization_with_explicit_key(self, config): headers, _ = config.validate_anthropic_messages_environment( headers={"Authorization": "Bearer pre-existing"}, model="claude-3-5-sonnet", @@ -71,7 +71,7 @@ class TestValidateAnthropicMessagesEnvironment: litellm_params={}, api_key="new-key", ) - assert headers["Authorization"] == "Bearer pre-existing" + assert headers["Authorization"] == "Bearer new-key" def test_should_set_default_content_type(self, config): headers, _ = config.validate_anthropic_messages_environment( diff --git a/tests/test_litellm/llms/fireworks_ai/responses/test_fireworks_ai_responses_transformation.py b/tests/test_litellm/llms/fireworks_ai/responses/test_fireworks_ai_responses_transformation.py index be2af7d8d3c..fd79966504d 100644 --- a/tests/test_litellm/llms/fireworks_ai/responses/test_fireworks_ai_responses_transformation.py +++ b/tests/test_litellm/llms/fireworks_ai/responses/test_fireworks_ai_responses_transformation.py @@ -85,14 +85,14 @@ class TestValidateEnvironment: ) assert headers["Authorization"] == "Bearer env-key" - def test_should_not_overwrite_existing_authorization(self, config): + def test_should_override_existing_authorization_with_explicit_key(self, config): params = GenericLiteLLMParams(api_key="new-key") headers = config.validate_environment( headers={"Authorization": "Bearer pre-existing"}, model="accounts/fireworks/models/llama-v3-70b", litellm_params=params, ) - assert headers["Authorization"] == "Bearer pre-existing" + assert headers["Authorization"] == "Bearer new-key" class TestGetCompleteUrl: