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

Closed
opened 2026-02-16 17:41:23 -05:00 by yindo · 11 comments
Owner

Originally created by @GabrielFarfan on GitHub (Dec 22, 2025).

Originally assigned to: @rekram1-node on GitHub.

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

  • vercel/ai#8119 - Similar Mistral validation issue (fixed for generateObject)
  • #4951 - Similar "expected string, received object" pattern
Originally created by @GabrielFarfan on GitHub (Dec 22, 2025). Originally assigned to: @rekram1-node on GitHub. ### 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 ```bash # 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`: ```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 - vercel/ai#8119 - Similar Mistral validation issue (fixed for generateObject) - #4951 - Similar "expected string, received object" pattern
yindo closed this issue 2026-02-16 17:41:23 -05:00
Author
Owner

@github-actions[bot] commented on GitHub (Dec 22, 2025):

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.

@github-actions[bot] commented on GitHub (Dec 22, 2025): 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.
Author
Owner

@nimitbhardwaj commented on GitHub (Dec 22, 2025):

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.

@nimitbhardwaj commented on GitHub (Dec 22, 2025): <img width="1460" height="923" alt="Image" src="https://github.com/user-attachments/assets/ffebf335-224a-4dd8-a173-bab2cd61a17a" /> 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.
Author
Owner

@Vicenzo-Giuseppe commented on GitHub (Dec 22, 2025):

me too all groq models fails too.

@Vicenzo-Giuseppe commented on GitHub (Dec 22, 2025): me too all groq models fails too.
Author
Owner

@rekram1-node commented on GitHub (Dec 22, 2025):

can anyone show me:

cat ~/.cache/opencode/package.json

@rekram1-node commented on GitHub (Dec 22, 2025): can anyone show me: `cat ~/.cache/opencode/package.json`
Author
Owner

@rekram1-node commented on GitHub (Dec 22, 2025):

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

@rekram1-node commented on GitHub (Dec 22, 2025): looks like ai sdk v6 released just now and it busts the cached versions, looking into fix
Author
Owner

@rayhanadev commented on GitHub (Dec 22, 2025):

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"
  }
}
@rayhanadev commented on GitHub (Dec 22, 2025): 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" } } ```
Author
Owner

@rekram1-node commented on GitHub (Dec 22, 2025):

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

I think this should get it fixed

@rekram1-node commented on GitHub (Dec 22, 2025): Will release fix shortly: https://github.com/sst/opencode/commits/dev/ I think this should get it fixed
Author
Owner

@rayhanadev commented on GitHub (Dec 22, 2025):

ty goat 👑

@rayhanadev commented on GitHub (Dec 22, 2025): ty goat 👑
Author
Owner

@rekram1-node commented on GitHub (Dec 22, 2025):

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 :/

@rekram1-node commented on GitHub (Dec 22, 2025): 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 :/
Author
Owner

@rekram1-node commented on GitHub (Dec 22, 2025):

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

now github is down

@rekram1-node commented on GitHub (Dec 22, 2025): welp: https://www.githubstatus.com/ now github is down
Author
Owner

@rekram1-node commented on GitHub (Dec 22, 2025):

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

@rekram1-node commented on GitHub (Dec 22, 2025): after 3 yrs of waiting it finally deployed. Latest should have fix
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#3761