OpenCode Integration
OpenCode Integration Guide - Call AI Models via Routin API Platform
Introduction
This guide explains how to install and configure OpenCode to call AI models through the Routin API platform. OpenCode is a powerful AI programming assistant that supports multiple programming languages and development environments.
Install OpenCode
# Install via npm
npm install -g opencode
# Or via Homebrew (macOS)
brew install opencodeConfigure OpenCode
Method 1: Add Custom Provider via /connect Command
OpenCode supports any OpenAI-compatible provider. Run the /connect command to add Routin API:
Step 1: Run the connect command
/connectStep 2: Select provider type
Scroll down in the provider list and select "Other":
┌ Add credential
│
◆ Select provider
│ ...
│ ● Other
└Step 3: Enter provider ID
Enter a unique provider ID, such as routin:
┌ Add credential
│
◇ Enter provider id
│ routin
└Tip: Choose an easy-to-remember ID as you'll use it in the configuration file.
Step 4: Enter API Key
Enter the API Key you obtained from the Routin platform:
┌ Add credential
│
▲ This only stores a credential for routin - you will need to configure it in opencode.json, check the docs for examples.
│
◇ Enter your API key
│ sk-...
└Method 2: Configure opencode.json File
Create or update the opencode.json file in your project directory, or create it at ~/.config/opencode/opencode.json:
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"routin": {
"npm": "@ai-sdk/openai-compatible",
"name": "Routin API",
"options": {
"baseURL": "https://api.routin.ai/v1"
},
"models": {
"gpt-4o": {
"name": "GPT-4o"
},
"claude-sonnet-4-20250514": {
"name": "Claude Sonnet 4"
},
"deepseek-chat": {
"name": "DeepSeek Chat"
}
}
}
}
}Configuration Options:
| Option | Description |
|---|---|
npm | AI SDK package name, use @ai-sdk/openai-compatible for OpenAI-compatible providers |
name | Display name in the interface |
options.baseURL | API endpoint URL |
options.apiKey | Optional, set API Key directly if not using authentication |
options.headers | Optional, set custom request headers |
models | List of available models |
Advanced Configuration Example
Here's a complete configuration example with apiKey, headers, and limit options:
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"routin": {
"npm": "@ai-sdk/openai-compatible",
"name": "Routin API",
"options": {
"baseURL": "https://api.routin.ai/v1",
"apiKey": "{env:ROUTIN_API_KEY}",
"headers": {
"X-Custom-Header": "custom-value"
}
},
"models": {
"gpt-4o": {
"name": "GPT-4o",
"limit": {
"context": 128000,
"output": 16384
}
},
"claude-sonnet-4-20250514": {
"name": "Claude Sonnet 4",
"limit": {
"context": 200000,
"output": 65536
}
},
"deepseek-chat": {
"name": "DeepSeek Chat",
"limit": {
"context": 64000,
"output": 8192
}
}
}
}
}
}Advanced Configuration Options:
| Option | Description |
|---|---|
apiKey | Read from environment variable using {env:ENV_VAR_NAME} syntax |
headers | Custom headers sent with each request |
limit.context | Maximum input tokens the model accepts |
limit.output | Maximum tokens the model can generate |
Tip: The limit field helps OpenCode understand your remaining context space. Standard providers automatically pull this information from models.dev.
Configure Native Anthropic Provider
If you want to use the Anthropic official API directly (or a third-party compatible service), you can configure it using the @ai-sdk/anthropic package:
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"anthropic": {
"npm": "@ai-sdk/anthropic",
"name": "Routin Claude",
"options": {
"baseURL": "https://api.routin.ai/v1",
"apiKey": "{env:ANTHROPIC_API_KEY}"
},
"models": {
"claude-sonnet-4-5-20250929": {
"name": "Claude Sonnet 4.5"
},
"claude-haiku-4-5-20251001": {
"name": "Claude 4.5 Haiku"
},
"claude-opus-4-5-20251101": {
"name": "Claude 4.5 Opus"
}
}
}
}
}Anthropic Configuration Options:
| Option | Description |
|---|---|
npm | Use @ai-sdk/anthropic native SDK |
options.baseURL | Routin API endpoint or other third-party compatible service URL |
options.apiKey | Read API Key from environment variable |
Configure Environment Variable:
Windows (PowerShell)
setx ANTHROPIC_API_KEY "sk-your-api-key-here"macOS / Linux
export ANTHROPIC_API_KEY="sk-your-api-key-here"Configure OpenAI Codex Provider
If you want to use OpenAI Codex models, you can configure it using the @ai-sdk/openai package:
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"codex": {
"name": "routin Codex",
"npm": "@ai-sdk/openai",
"models": {
"gpt-5.2-codex": {
"name": "gpt-5.2-codex",
"variants": {
"high": {
"reasoningEffort": "high",
"textVerbosity": "low"
},
"xhigh": {
"reasoningEffort": "xhigh",
"textVerbosity": "medium"
}
}
}
},
"options": {
"apiKey": "your-api-key",
"baseURL": "https://api.routin.ai/v1"
}
}
}
}If you are using a subscription plan, use the following URL:
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"codex": {
"name": "routin Codex",
"npm": "@ai-sdk/openai",
"models": {
"gpt-5.2-codex": {
"name": "gpt-5.2-codex",
"variants": {
"high": {
"reasoningEffort": "high",
"textVerbosity": "low"
},
"xhigh": {
"reasoningEffort": "xhigh",
"textVerbosity": "medium"
}
}
}
},
"options": {
"apiKey": "your-api-key",
"baseURL": "https://api.routin.ai/plan/v1"
}
}
}
}Codex Configuration Options:
| Option | Description |
|---|---|
npm | Use @ai-sdk/openai native SDK |
variants | Model variant configuration, supports different reasoning intensities |
reasoningEffort | Reasoning intensity, options: high or xhigh |
textVerbosity | Output verbosity level, options: low or medium |
Configure API Key
Store your API Key in system environment variables to avoid storing it in local files.
Windows (PowerShell)
setx ROUTIN_API_KEY "sk-your-api-key-here"macOS / Linux
export ROUTIN_API_KEY="sk-your-api-key-here"Replace sk-your-api-key-here with the API Key you obtained from the Routin platform. After updating, reopen your terminal or append the command to ~/.zshrc / ~/.bashrc for persistence.
Verify Configuration
After configuration, run the /models command to see your custom provider and models in the selection list:
/modelsIf configured correctly, you'll see Routin API and its configured models in the list.
FAQ
Configuration File Location
The opencode.json file should be placed in your project root directory. OpenCode will automatically detect and load the configuration.
How to Get API Key
Please refer to the "Get API Key" section in the Claude Code Integration Guide.
Models Not Showing
If models don't appear in the list, check:
- Is the
opencode.jsonfile format correct (JSON syntax)? - Is
baseURLcorrectly set tohttps://api.routin.ai/v1? - Is the API Key configured correctly?
Get Help
- Online Platform: https://routin.ai