override auth header

This commit is contained in:
Frank Deng 2026-04-25 19:03:38 -07:00
parent 3e9cf5d5d1
commit 86c405eef9
4 changed files with 12 additions and 6 deletions

View file

@ -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

View file

@ -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"

View file

@ -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(

View file

@ -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: