Skip to content

opencode

opencode is an open-source agentic coding CLI. It speaks the OpenAI Chat Completions protocol natively, and CodeGate exposes exactly that protocol at /v1/chat/completions. Point it at CodeGate with two environment variables and you are running.

1. Install opencode

bash
npm install -g opencode-ai

Verify:

bash
opencode --version

2. Get a CodeGate API key

Open codegate.dev/console/token and click Add Token. Copy the sk-... value.

If you have not added credit yet, do that at Console, Top Up first. A few dollars will cover a lot of opencode prompts.

3. Point opencode at CodeGate

Set two environment variables:

bash
export OPENAI_BASE_URL="https://codegate.dev/v1"
export OPENAI_API_KEY="sk-..."

That is it. opencode will now hit POST https://codegate.dev/v1/chat/completions for every prompt, which is CodeGate's OpenAI-compatible endpoint.

Persist across shells

Add the two export lines to ~/.zshrc (macOS default), ~/.bashrc (Linux default), or your shell's equivalent. Reopen the terminal or run source ~/.zshrc.

For a per-project override, put them in a .env file and load it with direnv or dotenv.

4. Verify

bash
opencode "Explain what CodeGate is in one sentence."

You should see a short answer come back within a second or two. If it hangs, the key or the base URL is likely off, see the troubleshooting section below.

5. Model selection

opencode sends the model name in the request. Any Claude or GPT model CodeGate supports is valid — for example claude-sonnet-5 or gpt-5.2. See Models and Pricing for the exact per-token cost per model.

Troubleshooting

401 Unauthorized. The OPENAI_API_KEY is missing, wrong, or truncated. Print echo $OPENAI_API_KEY and confirm it starts with sk- and looks intact.

403 or 404 on /v1/chat/completions. OPENAI_BASE_URL is set to something other than https://codegate.dev/v1. Check with echo $OPENAI_BASE_URL. It must include the /v1 suffix, no trailing slash.

402 Payment Required. Balance ran out. Top up at Console, Top Up.

Empty responses or hangs. Rare, but if it happens, retry once. CodeGate fails over between upstreams, so a second attempt almost always succeeds. Persistent failures: join the Discord.

Next

Built on new-api. Served by CodeGate.