Skip to content

Zen API endpoints return 404 on CORS preflight (OPTIONS) — blocks all browser-based clients #31041

Description

@OHKNO

Description

All Zen API endpoints (/zen/v1/* and /zen/go/v1/*) return a 404 HTML page on CORS preflight (OPTIONS) requests, which blocks any browser-based client from calling the API. The actual POST endpoints are alive and working — this is purely a CORS preflight routing issue.

Evidence

Direct curl testing confirms the API backend is functional, but OPTIONS requests fall through to the frontend router:

Endpoint Method Result
/zen/v1/chat/completions POST ✅ 401 "Invalid API key" (API is alive)
/zen/go/v1/chat/completions POST ✅ 401 "Invalid API key" (API is alive)
/zen/v1/models GET ✅ 200 (full model list returned)
/zen/v1/chat/completions OPTIONS (preflight) ❌ 404 — returns HTML "Not Found" page, no CORS headers
/zen/go/v1/chat/completions OPTIONS (preflight) ❌ 404 — same thing

OPTIONS request/response:

curl -X OPTIONS \
  -H "Origin: https://example.com" \
  -H "Access-Control-Request-Method: POST" \
  -H "Access-Control-Request-Headers: authorization,content-type" \
  "https://opencode.ai/zen/v1/chat/completions"

Response: HTTP 404 with full HTML page (<title>Not Found | opencode</title>), zero CORS headers.

Browser console error:

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote
resource at https://opencode.ai/zen/v1/chat/completions.
(Reason: CORS header Access-Control-Allow-Origin missing). Status code: 404.

Impact

Root Cause

The API gateway is not handling OPTIONS requests — they fall through to the frontend SPA router, which returns a 404 HTML page. The server needs to respond to OPTIONS preflight requests with:

  • Access-Control-Allow-Origin: * (or specific origins)
  • Access-Control-Allow-Methods: POST, GET, OPTIONS
  • Access-Control-Allow-Headers: Authorization, Content-Type
  • Access-Control-Max-Age: 86400

Environment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions