Route OpenCode Zen rows on each model's protocol api #347
Merged
posthog[bot](GitHub profile, opens in a new tab)merged 4 commits into
main fromrefs/pull/347/head·merged by tombeckenham View on GitHubWhy#
The daily OpenCode Zen spec sync now fails with a 404, so the provider shows as degraded and its routes cannot be refreshed. The cause is a change in the upstream source format, not an outage.
Observed#
ingest_failedforopencodeat the 2026-10-17 spec-sync shard:fetch failed: https://raw.githubusercontent.com/anomalyco/opencode/dev/packages/console/app/src/routes/zen/openai/v1/chat/completions.ts → 404 Not Found./v1/statusshowsopencodeasdegraded.opencode-gois not affected.
Cause#
- models.dev 05585a4 ("give each model its own inference endpoint") changed the OpenCode provider
apifromhttps://opencode.ai/inference/v1to.../inference/openai/v1. It also gave each model its ownprovider.api:inference/openai/v1,inference/anthropic/v1orinference/google/v1beta. parseOpenCodeCatalogapplied the providerapito every row. So Anthropic rows gotinference/openai/v1/messagesand Gemini rows gotinference/openai/v1/models/<id>. These are not served paths.opencode-routes.tsmappedinference/openai/v1/...toroutes/zen/openai/v1/..., and that directory does not exist. The console'slib/inference-proxy.tsmaps theroutes/zen/v1handlers onto the protocol paths (/openai/v1/chat/completions,/openai/v1/responses,/anthropic/v1/messages,/google/v1beta/models/<model>). This matches the Inference API docs.
Fix#
opencode-catalog.ts: a Zen row uses its ownprovider.apiwhen the row states one. Otherwise it uses the providerapi. Both must be opencode.ai paths.opencode-routes.ts: protocol paths map back to theroutes/zen/v1handler that the proxy serves them from. A path that its protocol does not serve (for exampleopenai/v1/messages) is refused, and nothing is fetched.- Go is unchanged. It keeps its documented
v1/...ids, and a test now pins this. - Review follow-ups:
- The
schemaEndpointIdfact source now points at the model'sproviderobject when that object statesapi. - An unreadable
apinames its model. - An unknown
inference/<x>/...prefix is refused with anopencode:error instead of a raw fetch 404.
- The
Evidence#
- Live reproduction with the adapter's real
fetchSpecagainst models.dev and GitHub:- Before:
FAIL fetch failed: …/routes/zen/openai/v1/chat/completions.ts → 404 Not Found. This is the same as production. - After: the spec builds. The listing binds
inference/openai/v1/chat/completions(25),inference/openai/v1/responses(30),inference/anthropic/v1/messages(17), andinference/google/v1beta/models/<id>(8) tov1/chat/completions.ts,v1/responses.ts,v1/messages.tsandv1/models/[model].ts.
- Before:
- New regression tests in
opencode-catalog.test.tsandopencode-routes.test.ts: all 7 original cases fail before the fix and pass after it. The follow-up adds cases for an emptyapi, unknown prefixes, Go ids, and fact-source provenance. - CI steps run locally: frozen install,
check,lint,typecheck,check:client,test(217 files, 2038 tests),build. All pass.
Review#
Independent review of the first commit found no blocking issues. Its non-blocking points are addressed above, except two that were declined on purpose:
- Refusing an npm/api disagreement in the catalog parser. The 15-minute poll must not fail for the whole provider over one row. Spec sync already fails closed, and
bindSyncedRoutesOnlykeeps unsynced ids from being served. - A Go error-prefix nit. It cannot trigger.
Notes#
- Stored Zen route ids move from
inference/v1/...to the protocol paths that models.dev now states. Each moved row emits onemodel.updated. - No pricing code changed. The other open signals have their own issues and are not part of this PR: #346 (Vercel), #324 and #331 (Azure), #304 (FAL).
Created with PostHog Desktop
🤖 Generated with Claude Code
- 1
tombeckenham merged thisf617ad4
tombeckenham closed this
Sign in to join this conversation.
Deploying with
Cloudflare Workers#
The latest updates on your project. Learn more about integrating Git with Workers.
View logs
Branch Preview URL