anomalyco / anomalyco/opencode

[bug] opencode run: unknown model returns a generic 500 UnknownError instead of a 404 with the "did you mean" message

Open
#47,162 1 comment 0 reactions 1 assignee View on GitHub

@rekram1-node is already working on this.

Since Sep 3, 2026.

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

Description

Description

The prompt service already publishes a Model not found: provider/model. Did you mean ...? event, then dies with the raw error, and the HTTP error middleware maps every defect to UnknownError. The prompt endpoint already declares a 404 error type with a message field, so the fix is to convert the provider error into that before it dies.

Same class of problem as the secondary point in #47080.

Plugins

None

OpenCode version

1.18.27

Steps to reproduce

1. Install 1.18.27 to a scratch prefix and use an empty HOME so no real config or auth is involved:

npm install -g --prefix /tmp/oc-test opencode-ai@1.18.27
mkdir -p /tmp/oc-test/home /tmp/oc-test/proj && cd /tmp/oc-test/proj && git init -q

2. Run with a model id that is not in the OpenRouter catalog:

env -i PATH="$PATH" HOME=/tmp/oc-test/home OPENROUTER_API_KEY=sk-or-invalid TERM=dumb \
  /tmp/oc-test/bin/opencode run --print-logs --log-level DEBUG \
  -m openrouter/does-not-exist-xyz --format json "Reply with the single word pong."
echo "exit=$?"

stdout:

{"type":"error","sessionID":"ses_...","error":{"name":"UnknownError","data":{"message":"Unexpected server error. Check server logs for details.","ref":"err_00111007"}}}

stderr (server log) already has the useful message:

level=ERROR message=failed ref=err_00111007 error="ProviderModelNotFoundError: Model not found: openrouter/does-not-exist-xyz. Did you mean: dots-studio/dots-3-note-preview:free?"
    at SessionPrompt.getModel ...

Exit 1.

3. Same command with a real model id and the same bad key, for comparison:

env -i PATH="$PATH" HOME=/tmp/oc-test/home OPENROUTER_API_KEY=sk-or-invalid TERM=dumb \
  /tmp/oc-test/bin/opencode run -m openrouter/openai/gpt-4o-mini \
  --format json "Reply with the single word pong."
{"type":"error","sessionID":"ses_...","error":{"name":"APIError","data":{"message":"Missing Authentication header","statusCode":401,"isRetryable":false,...}}}

A bad key gets a specific, typed error, but an unknown model gets an opaque 500 and the caller has to go read the server log. No network call is made in step 2, the failure is local.

Expected Result

Step 2 returns a 404 NotFoundError carrying the Model not found: ... Did you mean ... message, and exits 1.

Screenshot and/or share link

N/A; this was a headless subprocess

Operating System

macOS 26.3 (Apple Silicon)

Terminal

iTerm2

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.