TiaraBasori/OpenCode2API

Wrap OpenCode into an OpenAI-compatible API and use models from OpenCode Zen for free unlimitedly. | 把 OpenCode 封装成 OpenAI 兼容 API,无限白嫖来自 OpenCode Zen 的模型。

OpenCode2API – A Bridge from OpenCode to OpenAI‑compatible APIs

What it is

  • An open‑source Node.js proxy that sits in front of a locally‑run OpenCode server (the runtime for the OpenCode AI models) and exposes the same HTTP endpoints that OpenAI, Anthropic (Claude), and other LLM providers use.
  • By doing so, any client that knows how to talk to the OpenAI /v1/chat/completions (or Anthropic /v1/messages) API can now use the free OpenCode Zen models without code changes.

Key features

  • OpenAI‑compatible endpoints – /v1/models, /v1/chat/completions, /v1/responses (a custom streaming + reasoning endpoint) and /v1/messages (Anthropic‑style). Full Server‑Sent Events (SSE) streaming is supported.
  • Reasoning control – callers can ask the model to spend more “effort” on reasoning via the reasoning_effort or reasoning: {"effort":"high"} fields.
  • Tool calling – the proxy forwards tool specifications from the client and returns standard tool_calls/function_call objects, while optionally restricting which built‑in OpenCode tools may be used.
  • Session continuation – the Responses API can reference a previous response ID, keeping a conversation alive for up to 30 minutes.
  • Observability – health check (/health, /health/details), Prometheus metrics (/metrics), and an optional read‑only web panel (/panel).
  • Docker‑first deployment – a single docker compose up -d brings up the proxy and the OpenCode backend together.

How to get started

  1. Docker (recommended) – clone the repo, copy .env.example to .env, fill in your OpenCode server password and a secret API_KEY, then run docker compose up -d. The proxy listens on port 10000 by default.
  2. Node.js development – install the OpenCode CLI, npm install, copy config.json.example to config.json, and run npm start.

Typical usage

  • Chat completions – a normal OpenAI‑style POST to /v1/chat/completions with a model name like opencode/big-pickle.
  • Responses API – a streaming call that also accepts a reasoning object to request higher‑effort processing.
  • Tool calls – include a tools array in the request; the proxy will return tool_calls (or Anthropic‑style tool_use blocks) that the client can execute and feed back.
  • Anthropic compatibility – the /v1/messages endpoint works with Claude SDKs, using the x‑api‑key header and Anthropic‑specific SSE event names.

Configuration highlights

Variable Purpose
API_KEY Secret token required for all proxy requests (Bearer header).
OPENCODE_API_KEYS Optional comma‑separated list of name:key pairs for multi‑user setups.
OPENCODE_SERVER_PASSWORD Password for the underlying OpenCode backend.
OPENCODE_DISABLE_TOOLS When true, blocks all built‑in OpenCode tools unless explicitly allowed.
OPENCODE_INTERNAL_ALLOWED_TOOLS Whitelist of internal tools that may be used when the client does not supply its own tools.
OPENCODE_WEB_PANEL_ENABLED Turns the optional /panel dashboard on or off.
OPENCODE_PROXY_AUTO_CLEANUP_CONVERSATIONS Auto‑removes stored conversation state after the TTL expires.

Who might use this

  • Developers building apps that rely on the OpenAI API but want to run free, locally hosted OpenCode models.
  • Teams needing a single endpoint for both OpenAI‑style and Anthropic‑style clients.
  • Anyone who wants tool‑calling support while keeping the OpenCode backend isolated behind a proxy.

License – MIT, so you can freely modify, embed, or redistribute the proxy.

Acknowledgements – The project builds on earlier community proxies such as dxxzst/opencode-to-openai and lucasliet/opencode-openai-proxy.

Related

  • Project
  • Project
  • Project
  • Project
  • Project