GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix: resolve Mistral API compatibility issues by NicolaivdSmagt · Pull Request #2440 · anomalyco/opencode

Conversation

@NicolaivdSmagt

@NicolaivdSmagt NicolaivdSmagt commented Sep 5, 2025 •
edited by rekram1-node
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

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:

  1. Conversation roles must strictly alternate user/assistant/user/assistant after tool usage
  2. Tool call IDs must be exactly 9 alphanumeric characters
  3. 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
All reactions
  • ❤️ 5 reactions
NicolaivdSmagt added 4 commits September 5, 2025 16:19
@NicolaivdSmagt
fix: resolve Mistral API message sequence error when switching models
2728335
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.
@NicolaivdSmagt
fix: add toolInvocations to assistant message in Mistral sequence fix
52b332f
Resolves 'Unsupported content type in assistant message: undefined' error
by ensuring the inserted assistant message has the proper structure
expected by the AI SDK.
@NicolaivdSmagt
fix: normalize Mistral tool call IDs to meet API requirements
b872227
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.
@NicolaivdSmagt
fix: use provider ID instead of model name for Mistral detection
8e29dd1
Filter on providerID rather than individual model names to ensure all
Mistral models receive the necessary API compatibility transforms,
including future model variants.
@uloco

uloco commented Sep 23, 2025

Copy link
Copy Markdown

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
All reactions
  • 👍 5 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions
github-actions Bot force-pushed the dev branch from f16de3d to cc0d460 Compare September 29, 2025 05:53
This was referenced Nov 2, 2025
Timeout then tool errors with Devstral-Medium #2865
Closed
Tool Call ID Format Incompatible with Mistral API: "must be a-z, A-Z, 0-9, with a length of 9" #1680
Closed
Persistent tool call errors with Deepseek v3 and Devstral #526
Closed
@ErwanLegrand

ErwanLegrand commented Nov 2, 2025

Copy link
Copy Markdown

Fixes #526 , #1680 and #2865 .

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@rekram1-node

rekram1-node commented Nov 2, 2025

Copy link
Copy Markdown
Member

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.

rekram1-node added 6 commits November 5, 2025 13:44
@rekram1-node
Merge branch 'dev' into fix-mistral-message-sequence
ac38547
@rekram1-node
fix
0598d1f
@rekram1-node
Merge branch 'dev' into fix-mistral-message-sequence
fce72ee
@rekram1-node
fix
3e0d457
@rekram1-node
rm redundant comment
451986e
@rekram1-node
tweak
d131bd5
@rekram1-node
rekram1-node merged commit a2ab019 into anomalyco:dev Nov 6, 2025
@rekram1-node

rekram1-node commented Nov 6, 2025

Copy link
Copy Markdown
Member

thank u!

lochetti reacted with heart emoji
All reactions
  • ❤️ 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

thdxr pushed a commit that referenced this pull request Nov 7, 2025
@NicolaivdSmagt @rekram1-node @thdxr
fix: resolve Mistral API compatibility issues (#2440)
9e04ff0
Co-authored-by: Aiden Cline <[email protected]>
@lochetti lochetti mentioned this pull request Nov 7, 2025
Fix: Normalize Mistral tool call IDs to comply with API requirements #3080
Closed
@maxious maxious mentioned this pull request Jan 6, 2026
Devstral via LiteLLM OpenAI-compatible fails with invalid_request_message_order on first file edit #6346
Closed
@arpanpal-at arpanpal-at mentioned this pull request Jan 15, 2026
[Bug] @ai-sdk/amazon-bedrock: Tool call IDs incompatible with Mistral models - "must be a-z, A-Z, 0-9, with a length of 9" vercel/ai#11802
Closed
1 task done
This was referenced Mar 8, 2026
[BUG]: codestral, pixtral, mixtral skip Mistral tool call transform (has fix) #16636
Closed
fix(provider): extend mistral transform to codestral, pixtral, mixtra… #16638
Closed
Rwanbt pushed a commit to Rwanbt/unifia that referenced this pull request May 5, 2026
@NicolaivdSmagt @rekram1-node
fix: resolve Mistral API compatibility issues (anomalyco#2440)
554b06f
Co-authored-by: Aiden Cline <[email protected]>
Rwanbt pushed a commit to Rwanbt/unifia that referenced this pull request May 5, 2026
@NicolaivdSmagt @rekram1-node @thdxr
fix: resolve Mistral API compatibility issues (anomalyco#2440)
40411c6
Co-authored-by: Aiden Cline <[email protected]>
AIALRA-0 pushed a commit to AIALRA-0/opencode-turn-engine that referenced this pull request Jun 10, 2026
@NicolaivdSmagt @rekram1-node
fix: resolve Mistral API compatibility issues (anomalyco#2440)
5545ca8
Co-authored-by: Aiden Cline <[email protected]>
AIALRA-0 pushed a commit to AIALRA-0/opencode-turn-engine that referenced this pull request Jun 10, 2026
@NicolaivdSmagt @rekram1-node @thdxr
fix: resolve Mistral API compatibility issues (anomalyco#2440)
86ac4f7
Co-authored-by: Aiden Cline <[email protected]>
Rwanbt pushed a commit to Rwanbt/unifia that referenced this pull request Jun 14, 2026
@NicolaivdSmagt @rekram1-node
fix: resolve Mistral API compatibility issues (anomalyco#2440)
815cc91
Co-authored-by: Aiden Cline <[email protected]>
Rwanbt pushed a commit to Rwanbt/unifia that referenced this pull request Jun 14, 2026
@NicolaivdSmagt @rekram1-node @thdxr
fix: resolve Mistral API compatibility issues (anomalyco#2440)
e955019
Co-authored-by: Aiden Cline <[email protected]>
meSingh pushed a commit to meSingh/opencode that referenced this pull request Sep 6, 2026
@NicolaivdSmagt @rekram1-node
fix: resolve Mistral API compatibility issues (anomalyco#2440)
6f8491b
Co-authored-by: Aiden Cline <[email protected]>
meSingh pushed a commit to meSingh/opencode that referenced this pull request Sep 6, 2026
@NicolaivdSmagt @rekram1-node @thdxr
fix: resolve Mistral API compatibility issues (anomalyco#2440)
f7f561c
Co-authored-by: Aiden Cline <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Timeout then tool errors with Devstral-Medium Tool Call ID Format Incompatible with Mistral API: "must be a-z, A-Z, 0-9, with a length of 9" Persistent tool call errors with Deepseek v3 and Devstral

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@NicolaivdSmagt @uloco @ErwanLegrand @rekram1-node
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.