OpenCode
Set OpenCode up on OpenDunes once, with a default model and a small one.
Coding agents adds OpenDunes to OpenCode as a provider. This recipe names the model each session starts on, gives OpenCode's side tasks a smaller model, and runs a task from a script.
1. Install OpenCode
| With | Install line |
|---|---|
| the install script | curl -fsSL https://opencode.ai/install | bash |
| npm | npm install -g opencode-ai |
| Homebrew | brew install anomalyco/tap/opencode |
Create an API keyAPI keyThe key you create and send with every request that calls a model.More on API keys → for OpenCode alone, and cap it on API Keys (API keys shows how). Put it in your shell profile, ~/.zshrc or ~/.bashrc, as export OPENDUNES_API_KEY="…".
2. Write the provider and its models
~/.config/opencode/opencode.json holds for every project. An opencode.json in a project is merged over it, key by key.
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"opendunes": {
"npm": "@ai-sdk/openai-compatible",
"name": "OpenDunes",
"options": {
"baseURL": "https://opendunes.com/v1",
"apiKey": "{env:OPENDUNES_API_KEY}"
},
"models": {
"anthropic/claude-sonnet-4.5": {
"name": "Claude Sonnet 4.5",
"limit": { "context": 1000000, "output": 64000 }
},
"anthropic/claude-haiku-4.5": {
"name": "Claude Haiku 4.5",
"limit": { "context": 200000, "output": 64000 }
}
}
}
},
"model": "opendunes/anthropic/claude-sonnet-4.5",
"small_model": "opendunes/anthropic/claude-haiku-4.5"
}| Key | Holds |
|---|---|
npm | @ai-sdk/openai-compatible: OpenCode sends each request to POST /v1/chat/completions |
options.apiKey | {env:OPENDUNES_API_KEY}: OpenCode reads the key from the environment, and the file never holds it |
models | each model OpenCode offers, by its ID in Models, with how much it reads and writes |
model | the model a session starts on: the provider, a slash, then the model IDModel IDThe name a request calls a model by, lab/model, copied from Models.More on Models → |
small_model | the model for side tasks, such as a session's title |
Each model is charged at its own rate, shown on its page in Models.
Don't write the key itself into an opencode.json in a project. The file is committed, and the key goes with it.
Keep {env:OPENDUNES_API_KEY}: the file can be shared, and each person runs it on their own key.
3. Check the setup
opencode models opendunesIt lists the two models. Start opencode in your project: it opens on Claude Sonnet 4.5, and /models switches to another model for the session. Send one task, then open Activity, in the app on opendunes.com: each request is there, with its charge in DADAThe Algerian dinar, the one currency the docs show.More on Balance and charges →.
4. Run it from a script
opencode run sends one task without the interface, prints the answer and exits:
opencode run "List the functions in src/ that have no test."-m opendunes/anthropic/claude-haiku-4.5 runs it on another model. In CI, set OPENDUNES_API_KEY from the CI's secrets, and give that job a key and a cap of its own.
Errors
| Status | Means | Do |
|---|---|---|
| 401 | the key is missing, wrong, paused, revoked or expired | check OPENDUNES_API_KEY in the terminal OpenCode starts from |
| 402 | the balanceBalanceWhat you can spend, in DA.More on Balance and charges → is at zero or below, cannot pay the request's hold, or the key's cap is spent | make a depositDepositMoney entering your balance, by CIB or Edahabia card.More on Balance and charges →, or raise the cap |
| 404 | the model ID is not on sale | copy the ID from Models into models |
Every other status: Errors and retries.
Next: Cursor · MCP servers
Last modified on