GeezerVison is showing github.com — fix: resolve Mistral API compatibility issues by NicolaivdSmagt · Pull Request #2440 · anomalyco/opencode
Conversation
NicolaivdSmagt
commented
Sep 5, 2025
•
edited by rekram1-node
Loading
Uh oh!
There was an error while loading. Please reload this page.
Summary
Fixes multiple Mistral API compatibility issues that occur when using Mistral models with tool calling:
- Message sequence error: Resolves
AI_APICallError: Unexpected role 'user' after role 'tool' by inserting assistant messages between tool and user messages to maintain proper conversation flow
- Assistant message format: Fixes
Error: Unsupported content type in assistant message: undefined by ensuring inserted messages have proper AI SDK structure
- Tool call ID format: Resolves tool call ID validation errors by normalizing IDs to meet Mistral's alphanumeric 9-character requirement
Root Cause
Mistral API requirements:
- Conversation roles must strictly alternate user/assistant/user/assistant after tool usage
- Tool call IDs must be exactly 9 alphanumeric characters
- Assistant messages require proper structure with
toolInvocations field
Solution
Added Mistral-specific transforms in packages/opencode/src/provider/transform.ts:
normalizeMistralToolCallIds() - converts tool call IDs to 9-character alphanumeric format
fixMistralMessageSequence() - inserts assistant messages to maintain proper sequence
- Applied transforms for all Mistral models by checking provider ID
Test Plan
- Verify tool call ID normalization to 9-character alphanumeric format
- Verify message sequence correction inserts assistant messages between tool and user
- Verify existing valid sequences remain unchanged
- Test conversations with tool usage using Mistral models
- Covers all Mistral model variants via provider ID detection
Files Changed
packages/opencode/src/provider/transform.ts - Added Mistral-specific message transforms
Resolves API errors that occur when using Mistral models with tool calling functionality.
closes #526
closes #1680
closes #2865
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
uloco, chartpath, lochetti, agbocsardi, and ErwanLegrand reacted with heart emoji
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?
|
chartpath, lochetti, agbocsardi, dlecan, and invader6000 reacted with thumbs up emoji
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This was referenced Nov 2, 2025
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
ill check this out tmr, sorry for delays
|
ErwanLegrand reacted with thumbs up emoji
lochetti reacted with heart emoji
All reactions
-
👍
1 reaction
-
❤️
1 reaction
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
lochetti reacted with heart emoji
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This was referenced Mar 8, 2026
Rwanbt
pushed a commit
to Rwanbt/unifia
that referenced
this pull request
May 5, 2026
Rwanbt
pushed a commit
to Rwanbt/unifia
that referenced
this pull request
May 5, 2026
AIALRA-0
pushed a commit
to AIALRA-0/opencode-turn-engine
that referenced
this pull request
Jun 10, 2026
AIALRA-0
pushed a commit
to AIALRA-0/opencode-turn-engine
that referenced
this pull request
Jun 10, 2026
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
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.
|