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.jsonfrom the project root; pass the key via an env var ({env:CG_KEY}syntax) instead of writing it into the file.
1. Install opencode
curl -fsSL https://opencode.ai/install | bashOr 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:
{
"$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-compatiblefor OpenAI-compatible endpoints.options.baseURL: alwayshttps://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);modelpicks the default asprovider/model.
Then export the key:
export CG_KEY="sk-cg-your-key"3. Verify
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.
Recommended 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.