Switch OpenCode upstream APIs with clovapi
OpenCode global config supports multiple API styles; clovapi switch writes the right provider block and transcodes via the local proxy.
OpenCode loads models and providers from global config files whose paths vary by OS, with merge rules across opencode.jsonc, opencode.json, and config.json. Hand-editing JSON is easy to conflict with project-level overrides, and slow when you change upstreams often.
What clovapi does for OpenCode
Running clovapi switch --cli opencode <profile> will:
- Resolve OpenCode’s global config directory (Windows:
%AppData%\opencode\first, else~/.config/opencode/). - Pick or create
opencode.jsonc(or an existingopencode.json/config.json). - Write
providerand top-levelmodelfor the profile’s API style (anthropic/…,clovapi/…,gemini/…, etc.). - Start the local proxy so OpenCode traffic goes through localhost.
If a switch “does nothing”, check for project-level opencode.json overrides or OPENCODE_CONFIG pointing elsewhere.
Quick start
npm i -g @clovapi/cli
clovapi add --name my-gateway
clovapi switch --cli opencode my-gateway
During add, confirm the API style (Anthropic-compatible, OpenAI-compatible, Gemini, …). switch maps it into OpenCode’s provider layout. Keep multiple profiles and swap by name.
Alongside other CLIs
OpenCode is one supported CLI among several:
clovapi switch --cli claude-code deepseek
clovapi switch --cli codex openrouter-prod
clovapi switch --cli opencode my-gateway
clovapi list shows the active profile per CLI and the API-style matrix.