OpenCode
Configure OpenCode with a Model Gate OpenAI-compatible provider.
OpenCode through Model Gate
For current OpenCode versions, use an OpenAI-compatible custom provider.
Configuration path
| System | Path |
|---|---|
| Windows | %USERPROFILE%\.config\opencode\opencode.jsonc |
| Linux or macOS | ~/.config/opencode/opencode.jsonc |
Environment variable
Linux or macOS
export MODEL_GATE_API_KEY="mg_live_..."
Windows PowerShell
$env:MODEL_GATE_API_KEY = "mg_live_..."
Configuration
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"model_gate": {
"name": "Model Gate",
"npm": "@ai-sdk/openai-compatible",
"options": {
"baseURL": "https://api.model-gate.com/v1",
"apiKey": "{env:MODEL_GATE_API_KEY}"
},
"models": {
"ch-47": {
"name": "Claude Opus 4.7 through Model Gate"
}
}
}
},
"model": "model_gate/ch-47"
}
Use @ai-sdk/openai instead when a selected OpenCode workflow specifically requires the Responses API rather than Chat Completions.
Start
opencode
Troubleshooting
| Problem | Resolution |
|---|---|
| Provider is missing | Confirm the provider ID in the model name matches model_gate. |
| Authentication fails | Confirm the environment variable is present before starting OpenCode. |
| Wrong endpoint | Use https://api.model-gate.com/v1. |
| Model not found | Use an enabled canonical model or alias. |
| Config validation fails | Check the installed OpenCode documentation because provider schema can change between versions. |
Current provider documentation: https://opencode.ai/docs/providers.