anomalyco / anomalyco/opencode

Bug: opencode run fails with "Unexpected server error" while API and TUI work fine

Open
#38,800 1 comment 0 reactions 1 assignee View on GitHub

@nexxeln is already working on this.

Since Jul 25, 2026.

Dominant language
TypeScript
Stars
209k
Forks
27.5k
Avg merge
7h 2m
Merged PRs (30d)
384

Description

Bug Report: opencode run fails with "Unexpected server error" while API and TUI work fine

Description

The opencode run command consistently fails with UnknownError: Unexpected server error when using the OpenCode Zen provider. However:

  1. The API works perfectly when called directly via curl with the same API key and model
  2. The TUI works when run interactively in a terminal (human input)
  3. The same configuration that fails in run mode worked in previous sessions

This appears to be a bug in how the run (batch/non-interactive) command constructs or handles the API request, not a server-side or API key issue.

Environment

  • OpenCode version: 1.18.5 (auto-upgraded from 1.18.4 during session)
  • OS: Linux 7.1.3-ogc5.1.fc44.x86_64 (Fedora/Bazzite, x86_64)
  • Node.js: v20.20.2
  • Provider: OpenCode Zen (opencode_zen)
  • Model: big-pickle

Configuration

// ~/.config/opencode/opencode.jsonc
{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "opencode_zen": {
      "name": "OpenCode Zen",
      "npm": "@ai-sdk/openai",
      "options": {
        "baseURL": "https://opencode.ai/zen/v1",
        "apiKey": "sk-..."
      }
    }
  },
  "model": "opencode_zen/big-pickle"
}

Steps to Reproduce

  1. Configure OpenCode with OpenCode Zen provider and big-pickle model
  2. Run: opencode run 'Say OK'
  3. Observe the error

Actual Result

{
  "name": "UnknownError",
  "data": {
    "message": "Unexpected server error. Check server logs for details.",
    "ref": "err_<unique-id>"
  }
}

This error occurs consistently with every opencode run attempt. Each attempt generates a unique ref ID.

Expected Result

The command should execute the prompt and return the model's response, as it does via:

  • Direct API call (curl)
  • Interactive TUI mode

Evidence: API Works Via curl

curl -s "https://opencode.ai/zen/v1/chat/completions" \
  -H "Authorization: Bearer sk-..." \
  -H "Content-Type: application/json" \
  -d '{"model":"big-pickle","messages":[{"role":"user","content":"Say OK"}],"max_tokens":10}'

Response (HTTP 200):

{
  "id": "gen-...",
  "model": "big-pickle",
  "choices": [{
    "index": 0,
    "finish_reason": "length",
    "message": {
      "role": "assistant",
      "content": null,
      "reasoning": "The user wants me to say \"OK\"."
    }
  }],
  "usage": {
    "prompt_tokens": 249,
    "completion_tokens": 10,
    "total_tokens": 259
  }
}

Evidence: TUI Works Interactively

Running opencode (no arguments) opens the TUI, which successfully connects to the same provider/model and processes messages when typed interactively by a human.

Evidence: run Command Fails

$ opencode run 'Say OK'
Error: {
  "name": "UnknownError",
  "data": {
    "message": "Unexpected server error. Check server logs for details.",
    "ref": "err_fa563afb"
  }
}

Also tried with explicit model flag:

$ opencode run 'Say OK' --model opencode_zen/claude-sonnet-4
Error: {
  "name": "UnknownError",
  "data": {
    "message": "Unexpected server error. Check server logs for details.",
    "ref": "err_e4073cfe"
  }
}

Log Analysis

The OpenCode log (~/.local/share/opencode/log/opencode.log) shows:

  • TUI sessions initialize and stream successfully with providerID=opencode modelID=big-pickle
  • The run command attempts are not logged with stream details — they fail before reaching the streaming stage
  • No specific error details are logged for the run failures
# Successful TUI session (from earlier):
timestamp=2026-07-24T19:54:04.438Z level=INFO run=b3c41545 message=stream providerID=opencode modelID=big-pickle session.id=... small=false agent=build mode=primary
timestamp=2026-07-24T19:54:04.440Z level=INFO run=b3c41545 message="llm runtime selected" llm.runtime=ai-sdk llm.provider=opencode llm.model=big-pickle

# Failed `run` attempt — only shows init, no stream:
timestamp=2026-07-25T03:18:13.940Z level=INFO run=f77bccff message="creating instance" directory=...
timestamp=2026-07-25T03:18:14.155Z level=INFO run=f77bccff message=init
timestamp=2026-07-25T03:19:14.481Z level=INFO run=f77bccff message=cleanup prune=7.days

Additional Context

  • The API key is valid and was tested immediately before/after the run failures
  • The model big-pickle is confirmed available in the /v1/models endpoint
  • Multiple models were tested (big-pickle, claude-sonnet-4) — all fail with the same error in run mode
  • The issue started on 2026-07-25; the same configuration worked on 2026-07-24

Hypothesis

The run command may be:

  1. Adding different headers or request parameters compared to the TUI/curl
  2. Using a different authentication flow that the Zen API rejects
  3. Having an issue with how it handles the streaming response in non-interactive mode
  4. Experiencing a regression in how the AI SDK constructs the request in batch mode

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.