OpenCode
Configure OpenCode CLI to use OhMyGPT as the API provider.
OpenCode is an open-source AI coding agent available as a terminal interface, desktop app, or IDE extension. This guide connects it to OhMyGPT using the OpenAI-compatible provider.
Installation
curl -fsSL https://opencode.ai/install | bashConfiguration
OpenCode uses a global JSON config file. Create or edit the file at:
| Platform | Path |
|---|---|
| Linux / macOS | ~/.config/opencode/opencode.json |
| Windows | %APPDATA%\opencode\opencode.json |
OpenCode relies on the Vercel AI SDK for provider compatibility. Use the @ai-sdk/openai-compatible package to connect to OhMyGPT.
Claude Models via OhMyGPT
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"ohmygpt": {
"npm": "@ai-sdk/openai-compatible",
"name": "OhMyGPT",
"options": {
"apiKey": "<your-ohmygpt-api-key>",
"baseURL": "https://apic1.ohmycdn.com/api/v1/ai/openai/cc-omg/v1"
},
"models": {
"claude-sonnet-4-5": {
"name": "Claude Sonnet 4.5",
"limit": {
"context": 200000,
"output": 64000
}
},
"claude-haiku-4-5": {
"name": "Claude Haiku 4.5",
"limit": {
"context": 200000,
"output": 64000
}
}
}
}
}
}OpenAI Models via OhMyGPT
GPT-5.2 Codex currently has parameter compatibility issues with OpenCode. See anomalyco/opencode#5421 for status.
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"ohmygpt-openai": {
"npm": "@ai-sdk/openai-compatible",
"name": "OhMyGPT (OpenAI)",
"options": {
"apiKey": "<your-ohmygpt-api-key>",
"baseURL": "https://apic1.ohmycdn.com/v1"
},
"models": {
"gpt-5.2-codex": {
"name": "GPT-5.2 Codex",
"limit": {
"context": 400000,
"output": 128000
}
}
}
}
}
}Combined Configuration
You can define multiple providers in a single config to switch between models:
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"ohmygpt-claude": {
"npm": "@ai-sdk/openai-compatible",
"name": "OhMyGPT Claude",
"options": {
"apiKey": "<your-ohmygpt-api-key>",
"baseURL": "https://apic1.ohmycdn.com/api/v1/ai/openai/cc-omg/v1"
},
"models": {
"claude-sonnet-4-5": {
"name": "Claude Sonnet 4.5",
"limit": {
"context": 200000,
"output": 64000
}
},
"claude-haiku-4-5": {
"name": "Claude Haiku 4.5",
"limit": {
"context": 200000,
"output": 64000
}
}
}
},
"ohmygpt-openai": {
"npm": "@ai-sdk/openai-compatible",
"name": "OhMyGPT OpenAI",
"options": {
"apiKey": "<your-ohmygpt-api-key>",
"baseURL": "https://apic1.ohmycdn.com/v1"
},
"models": {
"gpt-5.2-codex": {
"name": "GPT-5.2 Codex",
"limit": {
"context": 400000,
"output": 128000
}
}
}
}
}
}Configuration Reference
| Field | Description |
|---|---|
npm | AI SDK package to use. Use @ai-sdk/openai-compatible for OhMyGPT |
name | Display name shown in OpenCode UI |
options.apiKey | Your OhMyGPT API key (can also use {env:VAR_NAME} syntax) |
options.baseURL | OhMyGPT endpoint URL |
models.<id>.name | Display name for the model |
models.<id>.limit.context | Maximum context window (tokens) |
models.<id>.limit.output | Maximum output length (tokens) |
Using Environment Variables
Instead of hardcoding your API key, reference an environment variable:
{
"options": {
"apiKey": "{env:OHMYGPT_API_KEY}",
"baseURL": "https://apic1.ohmycdn.com/api/v1/ai/openai/cc-omg/v1"
}
}Then set the environment variable in your shell profile:
export OHMYGPT_API_KEY="<your-ohmygpt-api-key>"Verification
Start OpenCode in your project directory:
cd /path/to/project
opencodeRun /init to initialize OpenCode for the project, then use /model to select your configured OhMyGPT model.
Troubleshooting
| Symptom | Cause | Solution |
|---|---|---|
| Provider not listed | Config file not found | Verify config path matches your platform |
| "Invalid API key" | Key not set or incorrect | Check apiKey value or environment variable |
| Model parameter errors | SDK compatibility issue | Check OpenCode issues for model-specific bugs |
| JSON parse error | Syntax error in config | Validate JSON format (no trailing commas, proper quoting) |
How is this guide?
Last updated on
