Uh oh!
There was an error while loading. Please reload this page.
fix: resolve Mistral API compatibility issues - #2440
Merged
rekram1-node merged 10 commits intoNov 6, 2025
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.
uloco
commented
Sep 23, 2025
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? |
This was referenced Nov 2, 2025
ErwanLegrand
commented
Nov 2, 2025
rekram1-node
commented
Nov 2, 2025
Collaborator
ill check this out tmr, sorry for delays |
Uh oh!
There was an error while loading. Please reload this page.
rekram1-node
commented
Nov 6, 2025
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
xywsxp pushed a commit
to xywsxp/opencode
that referenced
this pull request
Apr 24, 2026
Co-authored-by: Aiden Cline <aidenpcline@gmail.com>
xywsxp pushed a commit
to xywsxp/opencode
that referenced
this pull request
Apr 24, 2026
Co-authored-by: Aiden Cline <aidenpcline@gmail.com>
Rwanbt pushed a commit
to Rwanbt/unifia
that referenced
this pull request
May 5, 2026
Co-authored-by: Aiden Cline <aidenpcline@gmail.com>
Rwanbt pushed a commit
to Rwanbt/unifia
that referenced
this pull request
May 5, 2026
Co-authored-by: Aiden Cline <aidenpcline@gmail.com>
AIALRA-0 pushed a commit
to AIALRA-0/opencode-turn-engine
that referenced
this pull request
Jun 10, 2026
Co-authored-by: Aiden Cline <aidenpcline@gmail.com>
AIALRA-0 pushed a commit
to AIALRA-0/opencode-turn-engine
that referenced
this pull request
Jun 10, 2026
Co-authored-by: Aiden Cline <aidenpcline@gmail.com>
AIALRA-0 pushed a commit
to AIALRA-0/opencode-turn-engine
that referenced
this pull request
Jun 10, 2026
Co-authored-by: Aiden Cline <aidenpcline@gmail.com>
AIALRA-0 pushed a commit
to AIALRA-0/opencode-turn-engine
that referenced
this pull request
Jun 10, 2026
Co-authored-by: Aiden Cline <aidenpcline@gmail.com>
avion23 pushed a commit
to avion23/opencode
that referenced
this pull request
Jun 10, 2026
Co-authored-by: Aiden Cline <aidenpcline@gmail.com>
avion23 pushed a commit
to avion23/opencode
that referenced
this pull request
Jun 10, 2026
Co-authored-by: Aiden Cline <aidenpcline@gmail.com>
Rwanbt pushed a commit
to Rwanbt/unifia
that referenced
this pull request
Jun 14, 2026
Co-authored-by: Aiden Cline <aidenpcline@gmail.com>
Rwanbt pushed a commit
to Rwanbt/unifia
that referenced
this pull request
Jun 14, 2026
Co-authored-by: Aiden Cline <aidenpcline@gmail.com>
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 freeto 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