opencode Integration with CodeGateway: OpenAI-Compatible Provider

(Unofficial)

This guide is independently community-maintained. It is not affiliated with, endorsed by, or sponsored by the vendor of the third-party tool it covers. All third-party trademarks are the property of their respective owners.

One opencode.json registers CodeGateway as an OpenAI-compatible provider with DeepSeek/Kimi/GLM models.

TL;DR: Drop an opencode.json in your project root registering an OpenAI-compatible provider, and opencode uses CodeGateway models — one command to run.

Prerequisites

  • Register at codegateway.dev — trial credit included after you bind a card (current amount shown on the signup/pricing page) — and create an API key (sk-cg- prefix).

  • opencode reads opencode.json from the project root; pass the key via an env var ({env:CG_KEY} syntax) instead of writing it into the file.

1. Install opencode

bash
curl -fsSL https://opencode.ai/install | bash

Or npm i -g opencode-ai / brew install sst/tap/opencode. Verify with opencode --version.

2. Register the CodeGateway provider

Create (or merge) opencode.json in the project root:

json
{
"$schema": "https://opencode.ai/config.json",
"model": "cg/deepseek-v4-pro",
"provider": {
"cg": {
"npm": "@ai-sdk/openai-compatible",
"name": "CodeGateway",
"options": {
"baseURL": "https://api.codegateway.dev/v1",
"apiKey": "{env:CG_KEY}"
},
"models": {
"deepseek-v4-pro": { "name": "DeepSeek V4 Pro" },
"kimi-k2.7-code": { "name": "Kimi K2.7 Code" }
}
}
}
}

Field notes:

  • npm: @ai-sdk/openai-compatible for OpenAI-compatible endpoints.

  • options.baseURL: always https://api.codegateway.dev/v1.

  • options.apiKey: {env:CG_KEY}; alternatively /connect → Other to store the key locally.

  • models: the model ids you want (matching the model list); model picks the default as provider/model.

Then export the key:

bash
export CG_KEY="sk-cg-your-key"

3. Verify

bash
opencode run --model cg/deepseek-v4-pro "Reply with only: hello"

A reply means it works. For everyday use run opencode and switch models with /models.

Verified on the OpenAI-compatible surface:

  • deepseek-v4-pro: main workhorse.

  • kimi-k2.7-code: long coding tasks.

  • glm-5.3: balanced.

  • qwen3.8-27b: light reasoning.

Note: GPT-series models are region-restricted upstream; Claude / Gemini series are not OpenAI-compatible — use Claude Code setup for Claude models.

FAQ

Q: Must I put the key in opencode.json? No. Prefer {env:CG_KEY}; or /connect → Other (stored in the local auth file). OAuth login is not supported by CodeGateway.

Q: My registered model doesn't show up? Check models ids against the model list and that model uses the provider/model format.

Q: "provider not found"? Make sure opencode.json sits in the working directory and the provider.cg object is valid.

Q: Can I use two gateways at once? Yes — add a second id (e.g. cg2) under provider; /models groups by provider.

Q: Does opencode save my key? /connect stores it in the local auth file; {env:...} never writes it to disk. Both work.

References

Turn this doc into a real API call

Lacking an official key or facing overseas card payment issues? Create an sk-cg- key after signing up, point your base URL at CodeGateway, and keep your existing SDK or CLI unchanged. Pay per token; binding a card adds free credit.

Sign up free
Author:CodeGateway Team
opencode Integration with CodeGateway | CodeGateway