UniRoute
Docs

OpenCode

Install OpenCode and generate native UniRoute provider configurations from the current model catalog.

OpenCode · pay-as-you-go API

Generate a native UniRoute provider in OpenCode and select a default model. The setup tool picks the matching adapter and base URL from the model protocol.

Best for: Developers who switch between model providers in a terminal coding workflow.

Quick setup

Sign in to create a key and fill it in automatically Sign in

bash
UNIROUTE_API_KEY=YOUR_UNIROUTE_API_KEY npx -y uniroute-setup@latest configure opencode --model claude-sonnet-5-5

Requires Node.js 22+ for the setup tool. Add --dry-run to preview the file changes without writing; --home /path/to/test-home uses an isolated home. Existing changed files are backed up and unrelated settings are preserved.

Manual configuration

1. Locate and back up the files

macOS / Linux: ~/.config/opencode/opencode.jsonc. Windows: $HOME\.config\opencode\opencode.jsonc. The tool uses an existing opencode.json instead when present. Keep one of these two files, then back it up.

2. Merge the provider settings

json
{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "uniroute-anthropic": {
      "npm": "@ai-sdk/anthropic",
      "name": "UniRoute",
      "options": {
        "baseURL": "https://api.uniroute.app/v1",
        "apiKey": "YOUR_UNIROUTE_API_KEY"
      },
      "models": {
        "claude-sonnet-5-5": {
          "name": "Claude Sonnet 5.5"
        },
        "claude-fable-5-2": {
          "name": "Claude Fable 5.2"
        }
      }
    }
  },
  "model": "uniroute-anthropic/claude-sonnet-5-5"
}

To choose Claude Fable 5.2 when it appears in your key’s model catalog, set the top-level model to "uniroute-anthropic/claude-fable-5-2".

3. Match the adapter to the protocol

ProtocolAdapterBase URL
Messages@ai-sdk/anthropichttps://api.uniroute.app/v1
Responses@ai-sdk/openaihttps://api.uniroute.app/v1
Chat Completions@ai-sdk/openai-compatiblehttps://api.uniroute.app/v1
Gemini@ai-sdk/googlehttps://api.uniroute.app/v1beta

OpenCode loads these provider adapters. No oh-my-opencode installation is required. The setup tool adds catalog model IDs without inventing context or output limits.

4. Restart and choose the provider

opencode

What these fields do

FieldPurpose
providerDefines a named UniRoute provider for each protocol.
npmThe OpenCode adapter package for the selected protocol.
baseURL / apiKeyThe adapter endpoint and your UniRoute credential.
modelThe default in provider/model-ID format.

Choose a model

Confirm the connection

Check status with /models to inspect the active model and service.

Send a short test: opencode run "Reply only: hello"

Open usage logs to review the model, request status and charge. The test is a real, billed API request.

Match its time, model, and actual charge in the usage log. Keep the key in private configuration and out of repositories.

Switch back / restore a backup

Quit OpenCode, restore the printed opencode.jsonc or opencode.json backup, then reopen it. For a manual rollback, remove only the UniRoute provider you added and restore the previous default model.

If a file was new and has no backup, remove only the fields added by this setup and preserve settings added later.

Not installed yet?

Follow the official OpenCode documentation. For npm installation:

npm install -g opencode-ai
opencode --version

FAQ

Can I keep existing providers and plugins?

Yes. The tool merges its provider and model fields, preserving unrelated configuration.

What if project settings override the model?

Inspect the project opencode.json(c) and .opencode settings described in the official configuration guide.

Troubleshooting

401 / authentication failed

The active credential is incomplete, revoked, or still points to another provider.

Paste a valid UniRoute key and check the active authentication method.

404 / wrong endpoint

The base URL and adapter path do not match.

Use the address shown above and remove duplicated /v1 or /v1beta segments.

Model missing / 403

The selected model, key permissions, or wallet funds need attention.

Check the model ID, key restrictions, and wallet in the console, then restart the client.

Changes did not take effect

A running process or a different config directory is still in use.

Quit the client completely, check its effective configuration path, then reopen.

Related links

Manage API keys

· Protocols and addresses ·

Model prices

· Usage records · Setup Skill