Files
opencode-proxy/README.md
T
2026-07-21 01:06:08 -05:00

1.7 KiB

OpenCode Go Proxy

A small, unauthenticated OpenAI-compatible proxy for OpenCode Go.

Setup

Requires Node.js 18 or newer.

npm install

Create keys.txt in the project root. Put one OpenCode Go API key on each line. Blank lines and comments are ignored; inline comments are supported.

go-first-key
go-second-key # optional comment
# disabled-key

Start the proxy:

npm start

The proxy listens at http://localhost:4005/oai/v1 and http://localhost:4005/ant/v1. It does not require authentication from clients. Keys are selected round-robin for each request and are sent upstream as Bearer tokens. If an upstream request fails, the proxy tries each remaining key once before returning the final failure response.

Endpoints

curl http://localhost:4005/oai/v1/models
curl http://localhost:4005/oai/v1/chat/completions \
  -H 'content-type: application/json' \
  -d '{"model":"kimi-k3","messages":[{"role":"user","content":"Hello"}]}'

Streaming requests are supported with "stream":true and are passed through as Server-Sent Events. The model list is fetched from OpenCode Go, so it can include models whose upstream transport is not OpenAI Chat Completions.

The Anthropic-compatible adapter exposes POST /ant/v1/messages and GET /ant/v1/models. Messages, tools, JSON responses, and streaming events are translated to and from OpenAI Chat Completions. Anthropic clients should use their normal Messages API request format and can use the OpenCode model IDs returned by the models endpoint.

For Claude Code, either set ANTHROPIC_BASE_URL=http://localhost:4005/ant or use the displayed http://localhost:4005/ant/v1 value; both forms are supported.

Tests

npm test