Skip to content

All Mistral models fail with ZodError: "finish" expected string, received object #5981

Closed

Description

@GabrielFarfan

Description

All Mistral provider models fail with a ZodError validation error after successfully generating a response. The error occurs during stream parsing when the AI SDK validates the finish field.

Steps to Reproduce

# Any Mistral model fails:
opencode run -m mistral/ministral-3b-latest "say hi" < /dev/null
opencode run -m mistral/mistral-small-latest "say hi" < /dev/null
opencode run -m mistral/mistral-large-latest "say hi" < /dev/null

Expected Behavior

Command completes successfully after generating response.

Actual Behavior

Response generates correctly, then immediately fails with validation error:

ZodError: [
  {
    "expected": "string",
    "code": "invalid_type",
    "path": ["finish"],
    "message": "Invalid input: expected string, received object"
  }
]

Full error with --format json:

{"type":"text","timestamp":...,"part":{"type":"text","text":"Hi"}}
{"type":"error","timestamp":...,"error":{"name":"UnknownError","data":{"message":"[{\"code\":\"invalid_union\",\"errors\":[[{\"expected\":\"string\",\"code\":\"invalid_type\",\"path\":[\"reason\"],\"message\":\"Invalid input: expected string, received object\"}],...]}"}}}

Root Cause Analysis

The Vercel AI SDK expects the Mistral stream to return {"finish": "stop"} (string), but Mistral's API returns {"finish": {"reason": "stop"}} (object). This causes Zod validation to fail.

Environment

  • OpenCode version: 1.0.186
  • OS: Linux (Debian 12)
  • Installation method: curl
  • Affected models: All mistral/* models

Related Issues

Activity

  1. github-actions commented on Dec 22, 2025

    @github-actions
    Contributor

    This appears to be a unique issue specific to Mistral's API response format for the stream finish field.

    While there is a related issue #5034 about Ministral 3 support, that issue addresses a different error (system message role error) rather than the ZodError validation issue with the finish field.

    This issue is distinct from other provider validation errors in the codebase, as it specifically stems from Mistral's API returning {"finish": {"reason": "stop"}} (object) while the Vercel AI SDK expects {"finish": "stop"} (string).

    Recommendation: This appears to be a fresh/unique issue that may require a custom Mistral provider adapter or upstream fix in the Vercel AI SDK's Mistral integration.

  2. nimitbhardwaj commented on Dec 22, 2025

    @nimitbhardwaj
    Image

    I am also facing this error also for GROQ related models. I am using gpt oss 120b with groq and its not working on opencode.

  3. Vicenzo-Giuseppe commented on Dec 22, 2025

    @Vicenzo-Giuseppe

    me too all groq models fails too.

  4. self-assigned this
    on Dec 22, 2025
  5. rekram1-node commented on Dec 22, 2025

    @rekram1-node
    Contributor

    can anyone show me:

    cat ~/.cache/opencode/package.json

  6. rekram1-node commented on Dec 22, 2025

    @rekram1-node
    Contributor

    looks like ai sdk v6 released just now and it busts the cached versions, looking into fix

  7. rayhanadev commented on Dec 22, 2025

    @rayhanadev

    not sure if you still need it but here you go:

    ╭╴󰀵 // ima // [main]
    ╰─> cat ~/.cache/opencode/package.json
    {
      "dependencies": {
        "oh-my-opencode": "2.4.5",
        "opencode-antigravity-auth": "1.1.2",
        "@tarquinen/opencode-dcp": "1.0.4",
        "@franlol/opencode-md-table-formatter": "0.0.3",
        "opencode-copilot-auth": "0.0.9",
        "opencode-anthropic-auth": "0.0.5",
        "@ai-sdk/gateway": "3.0.0"
      }
    }
    
  8. rekram1-node commented on Dec 22, 2025

    @rekram1-node
    Contributor

    Will release fix shortly:
    https://github.com/sst/opencode/commits/dev/

    I think this should get it fixed

  9. rayhanadev commented on Dec 22, 2025

    @rayhanadev

    ty goat 👑

  10. rekram1-node commented on Dec 22, 2025

    @rekram1-node
    Contributor

    Release is in progress. w/ desktpp stuff it takes a while and some of the npm stuff is getting 503'ed so im doing waht I can but blocked until release goes out :/

  11. rekram1-node commented on Dec 22, 2025

    @rekram1-node
    Contributor

    welp:
    https://www.githubstatus.com/

    now github is down

  12. rekram1-node commented on Dec 22, 2025

    @rekram1-node
    Contributor

    after 3 yrs of waiting it finally deployed. Latest should have fix

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