fix(fireworks_ai): strip thinking_blocks from chat messages before Fireworks API call (#27881)

* fix(fireworks_ai): strip thinking_blocks from chat messages before API call

Fireworks OpenAI-compatible ChatMessage schema uses additionalProperties:false
and rejects Anthropic-style messages[].thinking_blocks (e.g. Claude Code replays),
returning invalid_request_error. Remove the field in _transform_messages_helper
alongside provider_specific_fields.

Adds unit test test_transform_messages_helper_strips_thinking_blocks.

Co-authored-by: Cursor <cursoragent@cursor.com>

* chore(fireworks_ai): drop inline comments from message sanitization

Co-authored-by: Cursor <cursoragent@cursor.com>

* docs(fireworks_ai): explain why provider_specific_fields and thinking_blocks are stripped

Co-authored-by: Cursor <cursoragent@cursor.com>

---------

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
milan-berri 2026-05-14 02:43:36 +03:00 • committed by GitHub
parent b593b88ec6
commit 6274b4c217
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 27 additions and 4 deletions

View file

@ -241,10 +241,13 @@ class FireworksAIConfig(OpenAIGPTConfig):
disable_add_transform_inline_image_block=disable_add_transform_inline_image_block,
)
filter_value_from_dict(cast(dict, message), "cache_control")
# Remove fields not permitted by FireworksAI that may cause:
# "Not permitted, field: 'messages[n].provider_specific_fields'"
if isinstance(message, dict) and "provider_specific_fields" in message:
cast(dict, message).pop("provider_specific_fields", None)
# Remove fields not permitted by FireworksAI (additionalProperties: false
# on their ChatMessage schema) that may cause:
# "Extra inputs are not permitted, field: 'messages[n].<field>'"
if isinstance(message, dict):
m = cast(dict, message)
m.pop("provider_specific_fields", None)
m.pop("thinking_blocks", None)
return messages

View file

@ -232,3 +232,23 @@ def test_transform_messages_helper_removes_provider_specific_fields():
)
for msg in out:
assert "provider_specific_fields" not in msg
def test_transform_messages_helper_strips_thinking_blocks():
"""thinking_blocks must not be forwarded to Fireworks chat completions."""
config = FireworksAIConfig()
messages = [
{"role": "user", "content": "Translate a poem."},
{
"role": "assistant",
"content": "I can help.",
"thinking_blocks": [
{"type": "thinking", "thinking": "internal", "signature": ""}
],
},
]
out = config._transform_messages_helper(
messages, model="accounts/fireworks/models/glm-5p1", litellm_params={}
)
assert "thinking_blocks" not in out[1]
assert out[1]["content"] == "I can help."