OpenCode Setup: Add a Custom Provider (Viro API) in 5 Minutes
Set up OpenCode with a custom OpenAI-compatible provider: install, opencode.json config, picking models, MCP servers and troubleshooting. Uses the Viro API for models on 100% renewable energy.
OpenCode is an open-source coding agent that runs in your terminal, as a desktop app or in the browser. Its big advantage: you choose the model provider. Any OpenAI-compatible API works.
This guide sets OpenCode up with the Viro API, which hosts open models on 100% renewable energy and offers frontier models (Claude, GPT, Gemini) with their energy matched with renewables. The same steps work for any OpenAI-compatible provider: just change the URL and models.
What you need
- A terminal on macOS, Linux or Windows.
- A Viro API key from console.viro.app. New accounts get free sandbox credit, no card needed.
1. Install OpenCode
curl -fsSL https://opencode.ai/v2/install | bash
Prefer a package manager? OpenCode also installs with Homebrew (brew install anomalyco/tap/opencode-v2) or npm (npm install -g @opencode/cli), and there are desktop builds for Mac, Windows and Linux. Check opencode.ai/docs for the latest.
2. Save your API key
Add this to ~/.zshrc, ~/.bashrc or your shell’s profile:
export VIRO_API_KEY="viro_sk_..."
Open a new terminal and test the key:
curl https://api.viro.app/v1/models -H "Authorization: Bearer $VIRO_API_KEY"
You should get back a JSON list of models.
3. Add the provider to opencode.json
OpenCode reads ~/.config/opencode/opencode.json for every project, and opencode.json in a project root for that project only (project settings win). Create one of them with:
{
"$schema": "https://opencode.ai/config.json",
"providers": {
"viro": {
"name": "Viro",
"env": ["VIRO_API_KEY"],
"package": "@opencode/ai/providers/openai-compatible",
"settings": { "baseURL": "https://api.viro.app/v1" },
"models": {
"clean": { "name": "Viro Clean (renewable router)", "modelID": "viro/clean" },
"kimi-k2.7-code": { "name": "Kimi K2.7 Code", "modelID": "viro/kimi-k2.7-code" },
"deepseek-v4.1-flash": { "name": "DeepSeek V4.1 Flash", "modelID": "viro/deepseek-v4.1-flash" },
"glm-5.3": { "name": "GLM-5.3", "modelID": "viro/glm-5.3" },
"claude-sonnet-5": { "name": "Claude Sonnet 5 (energy matched)", "modelID": "anthropic/claude-sonnet-5" }
}
}
}
}
What each part does:
env: the environment variable(s) holding your key. Nothing secret lives in the file.package: OpenCode’s adapter for OpenAI-compatible APIs.settings.baseURL: the provider’s API address, ending in/v1.models: the models you want in OpenCode’s picker. The key (kimi-k2.7-code) is how you refer to it in OpenCode (viro/kimi-k2.7-code);modelIDis the exact name sent to the API.
This uses OpenCode’s current (V2) config format. Older guides show "provider", "npm" and "options" instead; those are the V1 shapes.
4. Pick a model
Start OpenCode in a project:
cd your-project
opencode
Then type /models and choose one. Some good picks from the Viro catalog:
| Model | Energy | Context | Price per 1M tokens (in / out) |
|---|---|---|---|
| Kimi K2.7 Code | 100% renewable | 262K | $1.56 / $6.24 |
| GLM-5.3 | 100% renewable | 1M | $1.80 / $5.40 |
| DeepSeek V4.1 Flash | 100% renewable | 1M | $0.36 / $1.80 |
| Qwen3.8 27B | 100% renewable | 262K | $0.72 / $4.32 |
| Claude Sonnet 5 | Energy matched | 1M | $3.00 / $15.00 |
| GPT-5.6 Terra | Energy matched | 1M+ | $3.00 / $18.00 |
Prices from the Viro API catalog in November 2026. For the full, current list, see the Viro API model catalog, or ask the API: GET https://api.viro.app/v1/models. To add another model, give it a key and its modelID in the models map.
Not sure which? Use the router models instead of picking one yourself:
viro/cleanpicks the best eligible model running on renewable-verified infrastructure.viro/optimizedbalances quality, cost and energy per request.viro/frontierpicks the strongest available model.
Tool calling (reading files, editing, running commands) depends on the model. If a model struggles with OpenCode’s tools, switch to a coding-focused one like Kimi K2.7 Code.
5. Add your instructions
OpenCode reads AGENTS.md in your project, and ~/.config/opencode/AGENTS.md for instructions you want everywhere. Coming from Claude Code? It reads CLAUDE.md in any folder without an AGENTS.md, plus skills in .claude/skills.
6. Add MCP servers (optional)
MCP servers go under mcp.servers:
{
"mcp": {
"servers": {
"docs": { "type": "remote", "url": "https://mcp.example.com/mcp" },
"files": { "type": "local", "command": ["npx", "-y", "example-mcp-server"] }
}
}
}
Or add them from the terminal with opencode mcp add.
Troubleshooting
- 401 or “invalid API key”: open a new terminal so
VIRO_API_KEYis loaded, and re-run thecurltest above. - “Model not found”: check the
modelIDmatches a model fromGET /v1/modelsexactly, including theviro/,anthropic/oropenai/prefix. - Model doesn’t appear in
/models: it needs an entry in yourmodelsmap. Restart OpenCode after editing the config. - The agent stops using tools: try a different model; tool-calling reliability varies by model.
Why run OpenCode on Viro?
- Clean by default: open models run in data centers powered by 100% renewable energy.
- Frontier when you need it: Claude, GPT and Gemini through the same key, with their electricity matched with renewables and clearly labelled.
- Zero data retention on Viro-hosted models: your prompts and code aren’t stored.
- One bill, usage-based, starting with free sandbox credit.
Switching from another agent? See our guides for Claude Code and Codex, and why it matters in the environmental footprint of AI coding agents.
Frequently asked questions
How do I add a custom provider to OpenCode?
Add it under providers in opencode.json with a name, an env list for the API key, the package @opencode/ai/providers/openai-compatible, settings.baseURL set to the provider's /v1 URL, and a models map. Then pick a model with /models.
Where is the OpenCode config file?
Globally at ~/.config/opencode/opencode.json, or per project as opencode.json (or .opencode/opencode.json) in the project root. Project settings override global ones. JSON and JSONC both work.
How do I pass an API key to OpenCode without putting it in the config?
List the environment variable in the provider's env array, for example "env": ["VIRO_API_KEY"], and export it in your shell. Elsewhere in the config you can reference variables as {env:NAME}.
Does OpenCode list all of a provider's models automatically?
Add each model you want to pick under the provider's models map. Use modelID to send the provider's exact model name, for example viro/kimi-k2.7-code.
How do I add MCP servers to OpenCode?
Under mcp.servers in opencode.json, as type local with a command array, or type remote with a url. You can also run opencode mcp add.
Sources
- Providers, OpenCode docs
- Config, OpenCode docs
- MCP servers, OpenCode docs
- Rules, OpenCode docs
- Viro API models, Viro
Cover photo by Pankaj Patel on Unsplash



