Skip to content

fix: strip call_id and response_item_id from tool_calls for Mistral compatibility#864

Open
unmodeled-tyler wants to merge 2 commits intoNousResearch:mainfrom
unmodeled-tyler:fix/mistral-tool-calls-clean
Open

fix: strip call_id and response_item_id from tool_calls for Mistral compatibility#864
unmodeled-tyler wants to merge 2 commits intoNousResearch:mainfrom
unmodeled-tyler:fix/mistral-tool-calls-clean

Conversation

@unmodeled-tyler
Copy link
Contributor

Summary

  • Strips call_id and response_item_id from tool_calls before sending to strict APIs like Mistral
  • Fixes 429 rate limit handling (was incorrectly treated as non-retryable)
  • Updates .gitignore with common patterns

Problem

Mistral's API strictly validates the Chat Completions schema and rejects unknown fields with 422 - Extra inputs are not permitted. The call_id and response_item_id fields were added for Codex Responses API support (ce175d7) but are not part of the Chat Completions spec.

This extends the fix from PR #253 (which stripped finish_reason) to also strip these internal fields.

Changes

  1. Strip call_id and response_item_id from tool_calls in 3 locations:

    • Main conversation loop
    • _handle_max_iterations()
    • flush_memories()
  2. Fix 429 rate limit handling - Changed from non-retryable to retryable with exponential backoff

  3. Update .gitignore - Added config.yaml, sessions/, *.log, .DS_Store, Thumbs.db

Safety

The Codex Responses API code path has built-in fallback logic that uses the id field when call_id is not present, so this change is safe for both API modes:

  • Chat Completions API (Mistral, OpenRouter, etc.): Correctly removes non-spec fields
  • Codex Responses API: Safe - has fallback to id field

Related

Testing

Tested with Mistral API via Telegram gateway - tool calls now work correctly without 422 errors.

…ompatibility

Mistral's API strictly validates the Chat Completions schema and rejects
unknown fields with 422 "Extra inputs are not permitted". The call_id and
response_item_id fields were added for Codex Responses API support (ce175d7)
but are not part of the Chat Completions spec.

This extends the fix from PR NousResearch#253 (which stripped finish_reason) to also
strip these internal fields before sending to strict APIs like Mistral.

Changes:
- Strip call_id and response_item_id from tool_calls in 3 locations:
  - Main conversation loop
  - _handle_max_iterations()
  - flush_memories()
- Fix 429 rate limit handling (was incorrectly treated as non-retryable)
- Update .gitignore with common patterns

The Codex Responses API code path has built-in fallback logic that uses
the 'id' field when call_id is not present, so this change is safe for
both API modes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant