fix: resolve Mistral API compatibility issues#2440
Merged
rekram1-node merged 10 commits intoanomalyco:devfrom Nov 6, 2025
Merged
fix: resolve Mistral API compatibility issues#2440rekram1-node merged 10 commits intoanomalyco:devfrom
rekram1-node merged 10 commits intoanomalyco:devfrom
Conversation
Fixes "Unexpected role 'user' after role 'tool'" error that occurs when switching from Claude to Mistral models mid-conversation. Mistral has stricter message sequence requirements than other providers. - Add fixMistralMessageSequence() function to detect tool→user sequences - Insert intermediate assistant messages to maintain proper conversation flow - Apply fix for models containing "mistral" or "devstral" in their name - Preserve valid sequences unchanged Resolves issue where users get API errors when switching between providers during conversations with tool usage.
Resolves 'Unsupported content type in assistant message: undefined' error by ensuring the inserted assistant message has the proper structure expected by the AI SDK.
Mistral API requires tool call IDs to be alphanumeric with exactly 9 characters. Convert IDs like 'toolu_01CBhTTz95qkd9LJMdC9sf8t' to 'toolu01CB'. Fixes 'Tool call id was toolu_01CBhTTz95qkd9LJMdC9sf8t but must be a-z, A-Z, 0-9, with a length of 9' error.
Filter on providerID rather than individual model names to ensure all Mistral models receive the necessary API compatibility transforms, including future model variants.
|
I don't want to be that guy but can we please get this in? I really want to use mistral instead of copilot with gtp4.1 but I am facing too many issues with it. What is the blocker here? |
f16de3d to
cc0d460
Compare
This was referenced Nov 2, 2025
Tool Call ID Format Incompatible with Mistral API: "must be a-z, A-Z, 0-9, with a length of 9"
#1680
Closed
Collaborator
|
ill check this out tmr, sorry for delays |
Collaborator
|
thank u! |
thdxr
pushed a commit
that referenced
this pull request
Nov 7, 2025
Co-authored-by: Aiden Cline <aidenpcline@gmail.com>
1 task
This was referenced Mar 8, 2026
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.
Summary
Fixes multiple Mistral API compatibility issues that occur when using Mistral models with tool calling:
AI_APICallError: Unexpected role 'user' after role 'tool'by inserting assistant messages between tool and user messages to maintain proper conversation flowError: Unsupported content type in assistant message: undefinedby ensuring inserted messages have proper AI SDK structureRoot Cause
Mistral API requirements:
toolInvocationsfieldSolution
Added Mistral-specific transforms in
packages/opencode/src/provider/transform.ts:normalizeMistralToolCallIds()- converts tool call IDs to 9-character alphanumeric formatfixMistralMessageSequence()- inserts assistant messages to maintain proper sequenceTest Plan
Files Changed
packages/opencode/src/provider/transform.ts- Added Mistral-specific message transformsResolves API errors that occur when using Mistral models with tool calling functionality.
closes #526
closes #1680
closes #2865