BETA
Instructions
How to connect OpenCode to Apily
OpenCode is an open-source terminal agent. Its provider system uses @ai-sdk/openai-compatible, which speaks the standard OpenAI chat protocol — exactly what Apily serves.
Tool
OpenCode OpenAI-compatible
Base URL
https://apily.pro/v1Key
apily_your-api-keyConfig file
opencode.json (project or ~/.config/opencode/)Configuration
Declare the provider in opencode.json — in the project root or globally in ~/.config/opencode/opencode.json:
opencode.json
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"apily": {
"npm": "@ai-sdk/openai-compatible",
"name": "Apily",
"options": {
"baseURL": "https://apily.pro/v1",
"apiKey": "{env:APILY_API_KEY}"
},
"models": {
"gpt-5.6-sol": { "name": "GPT-5.6 Sol" },
"claude-opus-5": { "name": "Claude Opus 5" },
"deepseek-v4-flash-0731": { "name": "DeepSeek V4 Flash" }
}
}
}
}- Add the block above to
opencode.json, keeping your key out of the file —{env:APILY_API_KEY}reads it from the environment. - Export the key: terminal
export APILY_API_KEY=apily_your-api-key - Restart
opencode. The models you listed appear in the model picker under Apily.
Switching models
Add or remove entries under models and pick one in the TUI. The @ai-sdk/openai-compatible driver targets /v1/chat/completions, which Apily serves for the whole catalog — check the current list on the Models page or with GET /v1/models.
Common errors and how to fix them
| Symptom | Cause | Fix |
|---|---|---|
401 Invalid API key | Key not exported, or wrong value. | Export APILY_API_KEY in the same shell and restart. |
| Provider not found / npm error | The @ai-sdk/openai-compatible package is not resolvable. | Ensure npm: "@ai-sdk/openai-compatible" is set exactly; OpenCode fetches it on demand. |
404 Not found | Base URL missing /v1. | Base URL: https://apily.pro/v1 — every request must land on a path Apily serves (/chat/completions, /responses, /models, …). |
503 Model temporarily unavailable | The model exists, but no upstream provider is reachable right now. | Retry in a moment — it usually recovers within a minute. Switch models if it keeps happening. |