Connect OpenCode to CyberRouter
Connect OpenCode to CyberRouter with your account key and an enhanced model.
Prepare your connection
Use your CyberRouter models in OpenCode for code review, explanations, and development work. OpenCode connects to your CyberRouter account, which uses your saved provider keys and applies your account’s usage fee.
- Sign in and create an application key on API Keys.
- Connect a provider that serves your chosen model, and check your CyberRouter credits.
- Set
CYBERROUTER_API_KEYin the environment where you start OpenCode. Use your CyberRouter application key here; your upstream provider key stays in CyberRouter.
Install OpenCode using its official instructions. Check opencode --version before choosing a configuration format below.
Build your OpenCode configuration
Choose your OpenCode version and a model, then merge this configuration into your project’s opencode.json. Keep any existing settings you need.
The base URL follows this browser’s CyberRouter connection and includes /v1. When OpenCode runs on another machine or inside a container, replace a localhost address with the reachable CyberRouter address.
Starter settings use text input, up to 32,768 context tokens and 4,096 output tokens. These are conservative client budgets. Adjust them using your model’s endpoint limits and allow room for added CyberRouter context. Tool support depends on the selected provider endpoint.
Check your context budget before increasing the starter limits. Include loaded tool definitions and any security context added by CyberRouter.
Configuration formats follow OpenCode’s v1 custom-provider guide and v2 provider guide. The generated configuration references an environment variable and contains no account key.
Select your model in OpenCode
Start OpenCode from the configured project, run /models, and select the model under CyberRouter. The configuration also sets it as the default. OpenCode’s reference starts with cyberrouter/; the model ID sent to our API retains the :cyberrouter suffix.
To offer more models in OpenCode’s picker, add their entries to the same models object. The configuration does not automatically import the whole CyberRouter catalog. Keep only one top-level default model.
Start with a simple request such as “Explain the purpose of this README.” Find the resulting request and service fee on Usage. OpenCode executes its own local tools and manages its own permissions; CyberRouter handles model requests, routing, and billing.
Troubleshooting
| Symptom | What to check |
|---|---|
| CyberRouter missing from /models | Use the configuration format matching your OpenCode version. Confirm the config file is in the project and the key environment variable is available to the OpenCode process. |
| 401 authentication error | Use an active CyberRouter application key. A provider key or website login does not authenticate the OpenCode process. |
| 402 payment required | Check available CyberRouter credits and account/key spending limits. Your upstream provider also needs sufficient balance. |
| No eligible endpoints | Connect a provider that serves this exact model and review any routing restrictions. |
| 404, HTML response, or JSON parse error | Check the API host and /v1 base path. Choose the OpenAI-compatible chat package shown above; CyberRouter exposes /chat/completions. |
| Context too large or unsupported parameters | Reduce context/output budgets and check the serving endpoint’s supported parameters. |