Skip to content

fix(agent): skip reasoning param for Mistral API to prevent 422 errors#252

Closed
Sertug17 wants to merge 2 commits into
NousResearch:mainfrom
Sertug17:fix/mistral-422-reasoning-param-v2
Closed

fix(agent): skip reasoning param for Mistral API to prevent 422 errors#252
Sertug17 wants to merge 2 commits into
NousResearch:mainfrom
Sertug17:fix/mistral-422-reasoning-param-v2

Conversation

@Sertug17

@Sertug17 Sertug17 commented Mar 1, 2026

Copy link
Copy Markdown
Contributor

Problem

Fixes #134

When using Mistral API directly (api.mistral.ai), the agent sends a reasoning parameter in extra_body that Mistral does not support. This causes HTTP 422 "Unprocessable Entity" errors.

Root Cause

In run_agent.py, the reasoning parameter is only guarded by:

if _is_openrouter or _is_nous:
    extra_body["reasoning"] = ...

However, if a user routes through OpenRouter but selects a Mistral model, or connects directly to api.mistral.ai, this parameter is still sent and rejected.

Fix

Added _is_mistral detection and excluded it from receiving the reasoning param:

_is_mistral = "api.mistral.ai" in self.base_url.lower()
if (_is_openrouter or _is_nous) and not _is_mistral:
    extra_body["reasoning"] = ...

Testing

Verified the fix prevents reasoning from being added to extra_body when base URL contains api.mistral.ai.

@Sertug17 Sertug17 force-pushed the fix/mistral-422-reasoning-param-v2 branch from 6553e0e to d4b30e5 Compare March 1, 2026 10:27
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.

Error code: 422 when calling mistral api

1 participant