Skip to content

Mistral API error with Devstral via LiteLLM: "Expected last role User or Tool (or Assistant with prefix True)" #19115

Closed as not planned

Description

@nanosek

Description

When using Devstral (Mistral model) via LiteLLM with @ai-sdk/openai-compatible,
Mistral returns error 3230: "Expected last role User or Tool (or Assistant with prefix True)"

(Opencode diagnosed this itself with devstral model base on the 1.3.2 codebase)

The issue occurs because:

  1. Agent performs tool calls (ends with tool role)
  2. Agent continues with assistant message (no user after)
  3. Mistral expects either a user/tool message OR an assistant with prefix=true
    OpenCode's Mistral transformation (transform.ts lines 90-134) handles tool→user
    transitions but NOT assistant→(end) transitions.
    Expected: OpenCode should either insert a continuation user message OR add
    prefix:true to the last assistant message when sending to Mistral.

Stuff works if I am using the mistral provider explicitly, but then the token usage (context) is not working.

So basically 2 routes to resolution for me: either mistral provider can deal with the context / cost informations from litellm (like openai provider) or the openai provider is able to fix this ordering issue for models which have mistral / devstral in its name

Plugins

No response

OpenCode version

No response

Steps to reproduce

No response

Screenshot and/or share link

No response

Operating System

No response

Terminal

No response

Activity

  1. added
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on Mar 25, 2026
  2. github-actions commented on Mar 25, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

  3. nanosek commented on Mar 25, 2026

    @nanosek
    Author

    similar, but the concrete constrain of mistral is a different one here it seems

  4. ziouf commented on Mar 25, 2026

    @ziouf

    I think it's related to this #16636 and so, to this #16638

  5. removed
    bugSomething isn't working
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on May 3, 2026
  6. github-actions commented on Jul 5, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions