Skip to content

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

Closed as not planned

Description

@thossullivan

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

Activity

  1. changed the title [-]opencode run: unknown model returns a generic 500 UnknownError instead of a 404 with the "did you mean" message[/-] [+][bug] opencode run: unknown model returns a generic 500 UnknownError instead of a 404 with the "did you mean" message[/+] on Sep 3, 2026
  2. thossullivan commented on Sep 3, 2026

    @thossullivan
    Author

    I can take this as well if desired. Plan: in SessionPrompt.getModel, fail with the NotFoundError the prompt endpoint already declares, carrying the existing "Model not found ... Did you mean" message, instead of dying into the generic 500. No schema change required.

  3. thdxr commented on Oct 11, 2026

    @thdxr
    Member

    Thanks for the report! OpenCode 2.0 is now out and development is focused on V2, so we're closing issues filed against OpenCode 1. Please upgrade (opencode upgrade --major, details: https://anoma.ly/notes/opencode-2-0), and if this is still relevant on 2.0, reopen this issue or open a new one with your 2.0 version.

    — from 𝕺𝖕𝖊𝖓𝕮𝖔𝖉𝖊

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