Skip to content

OpenCode

OpenCode is an open-source terminal AI coding agent that lets you add custom OpenAI-compatible providers in its config file. OpenPalmLab provides /v1/chat/completions, so the setup below is all you need.

Install OpenCode first, then follow the steps below to connect it to the gateway. The install script from the official 1.x documentation (macOS / Linux / WSL):

终端窗口
curl -fsSL https://opencode.ai/install | bash

Or use a package manager:

终端窗口
npm install -g opencode-ai
brew install anomalyco/tap/opencode

On Windows the official docs recommend WSL; choco install opencode and scoop install opencode also work.

Check the install:

终端窗口
opencode --version

If it prints a version number, you are set. For all install methods see the official documentation.

  • OpenCode is installed.
  • You have a console token whose group includes models that support Chat Completions (see the pricing page).

Option 1: generate the config in the console

Section titled “Option 1: generate the config in the console”

The console builds the config in your browser; your token never leaves it.

  1. Open the console API Keys page, choose Terminal Commands in the action menu of the token you want, and pick the OpenCode tab.
  2. Pick a model and your system (macOS / Linux, Windows CMD or PowerShell; the system only changes how the file path is written).
  3. Save the content as ~/.config/opencode/opencode.json (on Windows, %USERPROFILE%\.config\opencode\opencode.json), merged with what is there.

The file contains your token, so do not commit it to a repository.

Edit ~/.config/opencode/opencode.json:

{
"$schema": "https://opencode.ai/config.json",
"provider": {
"newapi": {
"npm": "@ai-sdk/openai-compatible",
"name": "OpenPalmLab",
"options": {
"baseURL": "https://api.openpalm.ai/v1",
"apiKey": "sk-xxxx"
},
"models": {
"YOUR_MODEL": { "name": "YOUR_MODEL" }
}
}
},
"model": "newapi/YOUR_MODEL"
}
  • baseURL must include /v1.
  • The key under models and its name are a model name from the pricing page. You can list several.
  • model has the form provider/model and sets the default model.

Run opencode in a project directory and ask anything. Then open the console Usage Logs page; a request record for your token means it works.

Symptom Fix
Model not found The model is not listed under models, or model is not written as newapi/<model>.
401 The token is wrong, expired or out of quota.
404 baseURL is missing /v1.
No available channel for model ... That model has no available channel in your group. Choose another model, or use a token in a different group.

See Troubleshooting for more. Similar clients: Claude Code, Codex CLI, Gemini CLI.