- OpenCode installation
- OpenCode configuration
- OpenCode custom providers
- OpenCode model selection
- OpenCode permissions
Replace each
your-model-id value with a model ID from the
CometAPI Models page. Choose a model that accepts the API
format of the surrounding provider entry.Prerequisites
- Node.js and npm, or another installation method from the OpenCode guide
- A CometAPI account with an active API key from the dashboard
- One or more model IDs from the CometAPI Models page
Understand the API formats
Each provider ID selects one SDK adapter and one API format.
This guide verifies the Gemini streaming operation used during a normal
OpenCode agent turn. The Google adapter appends
:streamGenerateContent?alt=sse to the model path.
Do not add /chat/completions, /responses, /messages, or a Gemini model
path to baseURL. Each adapter appends its required operation path.
Understand runtime permissions
OpenCode runs with the permissions of the process that launches it. Start OpenCode in the intended project directory and keep a rollback path such as git. Use a container or sandbox when you need stronger filesystem, process, network, or API key boundaries.Configure OpenCode
1
Install OpenCode
Install OpenCode with the official npm package:Confirm that the CLI is available:See the OpenCode installation guide
for Homebrew, Windows, Docker, and other installation methods.
2
Set your CometAPI API key
Store your CometAPI API key in the Set the variable in every shell session that launches OpenCode. Do not
commit API keys to version control.
COMETAPI_KEY environment variable.- macOS / Linux / WSL
- Windows PowerShell
Read the API key without displaying it in the terminal:
3
Choose a configuration location
Use one of these supported locations:
- Global configuration:
~/.config/opencode/opencode.json - Project configuration:
opencode.jsonin the project root
4
Add the CometAPI providers
Create the selected configuration file. If the file already contains a
Replace each
provider object, merge these four entries into that object:your-model-id key independently. The four entries can use
different model IDs.The configuration does not set a top-level model. This lets you choose
the required API format and model through /models.5
Select and verify each provider
Start OpenCode in the project that you want it to access:Run To verify Responses from the command line, run:To verify Anthropic Messages from the command line, run:To verify Gemini generateContent from the command line, run:
/models, then select a provider/model entry. In the four verification
runs for this guide, each model turn used the selected entry’s matching API
format. No cross-format request fan-out or automatic API format negotiation
was observed.To verify Chat Completions from the command line, run:Troubleshooting
OpenCode does not show a CometAPI model
OpenCode does not show a CometAPI model
Confirm that the configuration is valid JSON. Each custom entry must be
inside the top-level
provider object, and each model ID must be inside
the matching models object. Restart OpenCode, then open /models again.OpenCode reports an API key or authentication error
OpenCode reports an API key or authentication error
Confirm that
COMETAPI_KEY is set in the shell that launches OpenCode.
An unset {env:COMETAPI_KEY} reference becomes an empty value. Open a new
shell after changing a shell profile.Requests use an incorrect path
Requests use an incorrect path
Keep
baseURL at /v1 for Chat Completions, Responses, and Messages. Use
/v1beta for Gemini. Do not include an operation path in baseURL.One provider works but another provider fails
One provider works but another provider fails
Use a model ID that accepts the selected provider’s API format. Do not
assume that one model ID accepts all four formats.
The project configuration changes a global provider
The project configuration changes a global provider
OpenCode merges global and project configuration. Rename the project
provider ID or remove its conflicting values when you want the global
provider entry to remain unchanged.
OpenCode has more access than expected
OpenCode has more access than expected
OpenCode uses the permissions of the process that launched it. Run OpenCode
in a container or sandbox when you need stronger access boundaries.