fix: sanitize tool_calls for all strict APIs (Fireworks, Mistral, etc.)#5183
Merged
teknium1 merged 7 commits intoApr 5, 2026
Merged
Conversation
added 7 commits
April 5, 2026 07:32
Adds a centralized method to determine when tool_calls need sanitization for strict APIs. Returns True for all APIs except codex_responses mode. This prevents 400 errors from providers like Fireworks that reject unknown fields (call_id, response_item_id) in tool_calls.
Replaces hardcoded Mistral check with the new _should_sanitize_tool_calls() method. This ensures tool_calls are sanitized for all strict APIs, not just Mistral. Prevents 400 errors from Fireworks and other providers.
Replaces hardcoded Mistral check with the new _should_sanitize_tool_calls() method. Ensures summary generation works correctly with Fireworks and other strict APIs that reject unknown tool_call fields.
Replaces hardcoded Mistral check with the new _should_sanitize_tool_calls() method. Updates comment to mention Fireworks alongside Mistral as strict APIs requiring tool_call field sanitization.
Adds test verifying that: - Codex mode returns False (no sanitization needed) - Chat completions mode returns True (sanitization needed) - Anthropic mode returns True (sanitization needed) This ensures strict APIs like Fireworks receive properly sanitized tool_calls.
Adds comprehensive tests verifying: - Fireworks-compatible messages after sanitization - Codex mode preserves fields for Responses API replay - Fireworks provider triggers sanitization correctly - Codex responses mode correctly skips sanitization Prevents regression of 400 validation errors on strict APIs.
Updates _sanitize_tool_calls_for_strict_api docstring to explicitly mention Fireworks alongside Mistral as strict APIs requiring sanitization. Also documents the specific fields that are stripped (call_id, response_item_id).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix: Tool Call Sanitization for Strict APIs
Problem
Codex-only fields (call_id, response_item_id) were being sent to strict APIs
like Fireworks, causing 400 errors:
"Extra inputs are not permitted, field: 'messages[X].tool_calls[Y].call_id'"
Root Cause
Sanitization was only applied for api.mistral.ai, not for other strict APIs.
Solution
Created
_should_sanitize_tool_calls()method that returns True for all APIsexcept codex_responses. Updated 3 locations in run_agent.py:
Tests Added
All existing tests pass:
Commits