Connect OpenCode to ModelGo: Setup & Troubleshooting

OpenCode is an open-source terminal AI coding agent that connects to ModelGo through a custom OpenAI-compatible provider. You need an API key from the ModelGo Console and a logical model name from the Model Catalog.

1. Install

bash
npm install -g opencode-ai
opencode -v

2. Configure the ModelGo provider

Edit ~/.config/opencode/opencode.json (Windows: %USERPROFILE%\.config\opencode\opencode.json) and 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"
        }
      }
    }
  }
}
bash
export MODELGO_API_KEY="mgk_your_api_key"

In Windows PowerShell use $env:MODELGO_API_KEY = "mgk_your_api_key". Set baseURL to https://api.modelgo.ai/v1; do not append the full /chat/completions path.

3. Select a model and verify

Start opencode, enter /models to open the model picker, and select a model under the ModelGo provider:

Identify ModelGo in the OpenCode model list

If the model list is empty, confirm that the API key can reach ModelGo; the id values returned are the logical model names to use in models:

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

Troubleshooting

  • OpenCode cannot find the config file: check that the file is named opencode.json and is in ~/.config/opencode/; a project-level file with the same name overrides user settings.
  • 401: confirm MODELGO_API_KEY is set in the current terminal, then restart OpenCode.
  • 404: use https://api.modelgo.ai/v1 as baseURL; do not append /chat/completions.
  • Model unavailable: make sure the ID in models exactly matches a logical ModelGo model enabled for the API key.

Related docs