anomalyco / anomalyco/opencode
Server (1.18.31): Free tier zen models fail - User-Agent not forwarded to zen API
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 209k
- Forks
- 27.5k
- PR merge metrics
- PR metrics pending
Description
Bug Report
Versión: opencode 1.18.31 (latest)
Plataforma: Linux (Ubuntu 22.04)
Descripción
El servidor opencode (opencode serve / puerto 4096) no reenvía el header User-Agent cuando hace peticiones a la API zen (https://opencode.ai/zen/v1/...). Esto hace que el tier gratuito de modelos zen falle con error 403:
Error from provider (Console): OpenCode's free tier can only be used from within OpenCode
Impacto
- TUI (
opencode/iago-opencode) → Fallan modelos zen gratuitos - CLI run (
opencode run -m muse-spark-1.3-contributor-free) → Fallan modelos zen gratuitos - openchamber (web UI) → Fallan modelos zen gratuitos
- Cualquier cliente que use la API del servidor (
opencode serve) → Fallan modelos zen gratuitos
Comportamiento esperado vs actual
| Componente | Esperado | Actual |
|---|---|---|
| Servidor opencode → zen API | Incluye User-Agent: opencode/1.18.31 |
No incluye User-Agent |
| Tier gratuito zen | Funciona | 403 Forbidden |
Root Cause
El servidor opencode actúa como proxy hacia la API zen. Cuando recibe una petición de /api/session/{id}/message con modelo zen, hace la petición a https://opencode.ai/zen/v1/chat/completions sin incluir el header User-Agent que la API zen ahora requiere para el tier gratuito.
Workaround parcial (openchamber)
En openchamber 1.24.1 agregué el header en el proxy:
proxyReq.setHeader('user-agent', 'opencode/1.18.31');
Esto hace que openchamber → servidor opencode funcione, pero el servidor → zen API sigue fallando porque el binario no reenvía el header.
Bug adicional relacionado
El endpoint POST /api/session/{id}/message del servidor devuelve HTML (página web UI) en lugar de JSON cuando falla, rompiendo todos los clientes API.
Request
Que el servidor opencode incluya automáticamente User-Agent: opencode/<version> en todas las peticiones salientes a la API zen (y idealmente a todos los proveedores que lo requieran).
Logs relevantes
# Petición que falla (desde servidor opencode a zen API)
POST https://opencode.ai/zen/v1/chat/completions
# Headers faltantes: User-Agent: opencode/1.18.31
# Respuesta:
403 Forbidden
{\"type\":\"error\",\"error\":{\"type\":\"FreeTierError\",\"message\":\"Error from provider (Console): OpenCode's free tier can only be used from within OpenCode\"}}
Configuración probada (no funciona)
{
\"$schema\": \"https://opencode.ai/config.json\",
\"provider\": {
\"opencode\": {
\"headers\": {
\"User-Agent\": \"opencode/1.18.31\"
}
}
}
}
Incluso configurando headers en provider.opencode, el servidor no los reenvía a la API zen.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the opencode serve POST /api/session/{id}/message entry point and trace the outgoing request to https://opencode.ai/zen/v1/chat/completions. Reproduce the free-tier request, then verify that the server sends the versioned User-Agent and that provider failures return JSON rather than the web UI HTML.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 65/100