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): top-level response_format beats nested extra_body copy
Miles Adkins0f15b471c48b
diff --git a/litellm/llms/fireworks_ai/chat/transformation.py b/litellm/llms/fireworks_ai/chat/transformation.pyindex 6b763be0bfe..6fccda1a791 100644--- a/litellm/llms/fireworks_ai/chat/transformation.py+++ b/litellm/llms/fireworks_ai/chat/transformation.py@@ -347,7 +347,16 @@ class FireworksAIConfig(FireworksAIMixin, OpenAIGPTConfig):*self._translate_chat_template_kwargs(extra_body, optional_params, model),*self._translate_guided_params(extra_body, optional_params),)- remaining: Final = tuple((k, v) for k, v in extra_body.items() if k not in _EXTRA_BODY_CONSUMED_PARAMS)+ if "response_format" in extra_body and "response_format" in optional_params:+ verbose_logger.debug(+ "fireworks_ai dropping extra_body.response_format; the top-level response_format takes precedence."+ )+ remaining: Final = tuple(+ (k, v)+ for k, v in extra_body.items()+ if k not in _EXTRA_BODY_CONSUMED_PARAMS+ and (k != "response_format" or "response_format" not in optional_params)+ )base: Final = {k: v for k, v in optional_params.items() if k != "extra_body"} # mutable-ok: JSON request bodyreturn { # mutable-ok: JSON request body**base,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 e1b5d457205..cc5b7880e9f 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@@ -1497,6 +1497,26 @@ def test_map_extra_body_params_guided_native_response_format_wins():assert nested == {"extra_body": {"response_format": nested_format}}+def test_map_extra_body_params_top_level_response_format_beats_nested():+ """+ With response_format set both top-level and inside extra_body, the http+ handler merges extra_body last, so the nested copy would silently clobber+ the explicit top-level one. The nested copy must be dropped instead.+ """+ config = FireworksAIConfig()+ result = config.map_extra_body_params(+ {+ "response_format": {"type": "json_object"},+ "extra_body": {+ "guided_json": {"type": "object"},+ "response_format": {"type": "json_schema", "json_schema": {"schema": {}}},+ },+ },+ _REASONING_MODEL,+ )+ assert result == {"response_format": {"type": "json_object"}}++def test_map_extra_body_params_multiple_guided_params_priority_order():config = FireworksAIConfig()result = config.map_extra_body_params(