Model Rover

OpenCode

Connect OpenCode with a custom OpenAI-compatible provider.

OpenCode can use the gateway through a custom OpenAI-compatible provider.

Install

Install OpenCode using the official documentation:

npm install -g opencode-ai
opencode --version

Before starting OpenCode, set AI_GATEWAY_API_KEY:

export AI_GATEWAY_API_KEY="YOUR_API_KEY"

On Windows, set AI_GATEWAY_API_KEY as a user environment variable before launching OpenCode.

Configure

Use opencode.json in the project root or the global ~/.config/opencode/opencode.json file.

{
"$schema": "https://opencode.ai/config.json",
"model": "gateway/<FULL_MODEL_ID>",
"provider": {
  "gateway": {
    "npm": "@ai-sdk/openai-compatible",
    "name": "AI Gateway",
    "options": {
      "baseURL": "http://127.0.0.1:11113/v1",
      "apiKey": "{env:AI_GATEWAY_API_KEY}"
    },
    "models": {
      "<FULL_MODEL_ID>": {
        "name": "<FULL_MODEL_ID>"
      }
    }
  }
}
}

The first gateway/ segment is the OpenCode provider ID. The complete model ID after it is sent to the gateway unchanged. @ai-sdk/openai-compatible uses Chat Completions.

Verify

Run opencode, open /models, select gateway/<FULL_MODEL_ID>, and send a read-only task.

Troubleshooting

  • The provider ID must be consistent between model, the provider key, and the model reference.
  • The base URL must include /v1 but must not include /chat/completions.
  • The environment variable must exist before the startup process launches.
  • The model must support function calling.
  • If a project configuration contains a key, do not commit it. The recommended configuration above contains no actual key.

Help us improve this page

Found something unclear, outdated, or incorrect?

Last updated on