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_effortorreasoning: {"effort":"high"}fields. - Tool calling – the proxy forwards tool specifications from the client and returns standard
tool_calls/function_callobjects, 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 -dbrings up the proxy and the OpenCode backend together.
How to get started
- Docker (recommended) – clone the repo, copy
.env.exampleto.env, fill in your OpenCode server password and a secretAPI_KEY, then rundocker compose up -d. The proxy listens on port 10000 by default. - Node.js development – install the OpenCode CLI,
npm install, copyconfig.json.exampletoconfig.json, and runnpm start.
Typical usage
- Chat completions – a normal OpenAI‑style POST to
/v1/chat/completionswith a model name likeopencode/big-pickle. - Responses API – a streaming call that also accepts a
reasoningobject to request higher‑effort processing. - Tool calls – include a
toolsarray in the request; the proxy will returntool_calls(or Anthropic‑styletool_useblocks) that the client can execute and feed back. - Anthropic compatibility – the
/v1/messagesendpoint works with Claude SDKs, using thex‑api‑keyheader 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