OpenCode

OpenCode is an open-source terminal AI coding agent. Its custom provider support lets you connect any OpenAI-compatible endpoint, including ModelGo, from a terminal, IDE, or desktop client.

Before you start

  • Install Node.js 18 or later.
  • Install OpenCode and confirm that opencode -v works in your terminal.
  • Create or copy an API key in the ModelGo console.
  • Confirm a logical model name available to your API key in the model catalog.

1. Install OpenCode

Run:

bash
npm install -g opencode-ai
opencode -v

You can also use the installation method provided by the OpenCode project. A version printed by opencode -v confirms a successful installation.

2. Configure the ModelGo provider

OpenCode reads user configuration from:

  • macOS/Linux: ~/.config/opencode/opencode.json
  • Windows: %USERPROFILE%\\.config\\opencode\\opencode.json

Create or edit opencode.json. Replace your-model-id with a logical model name from the model catalog:

json
{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "modelgo": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "ModelGo",
      "options": {
        "baseURL": "https://api.modelgo.ai/v1",
        "apiKey": "{env:MODELGO_API_KEY}"
      },
      "models": {
        "your-model-id": {
          "name": "your-model-id"
        }
      }
    }
  }
}

Set the environment variable:

bash
export MODELGO_API_KEY="sk-your-token"

Windows PowerShell:

powershell
$env:MODELGO_API_KEY = "sk-your-token"
SettingModelGo value
nameModelGo, the display name in OpenCode
options.baseURLhttps://api.modelgo.ai/v1
options.apiKey{env:MODELGO_API_KEY}
modelsA logical model ID and display name from the model catalog

3. Select a model and start a chat

Start OpenCode:

bash
opencode

Enter /models to open the model picker, then select a model under the ModelGo provider.

Open the model picker in OpenCode

The ModelGo provider label confirms that OpenCode recognized the provider.

Identify ModelGo in the OpenCode model list

You can also type ModelGo in the picker to filter the list:

Filter ModelGo models in OpenCode

Select the model and enter a simple task such as “Describe this project in three sentences.”

Start a chat with ModelGo in OpenCode

4. Verify the configuration

If the model list is empty, confirm that the API key can reach ModelGo:

bash
curl https://api.modelgo.ai/v1/models \
  -H "Authorization: Bearer $MODELGO_API_KEY"

The id values in the response are the logical model names to use in models.

Troubleshooting

OpenCode cannot find the config file

Check that the file is named opencode.json and is in ~/.config/opencode/ (or %USERPROFILE%\\.config\\opencode\\ on Windows). A project-level file with the same name can override user settings.

401 or authentication errors

Confirm that MODELGO_API_KEY is set in the current terminal and contains no extra spaces. Restart OpenCode after changing the variable.

404 or endpoint errors

Use https://api.modelgo.ai/v1 as baseURL; do not append /chat/completions.

Empty model list or unavailable model

Make sure the ID in models exactly matches a logical ModelGo model and that the model is enabled for the API key.

Related docs