OpenCode
Add PleumRouter as a custom provider in OpenCode, the open-source terminal coding agent.
OpenCode is an open-source coding agent for the terminal (TUI) that can add an OpenAI-compatible endpoint as a custom provider. PleumRouter connects over the OpenAI Chat Completions format (/v1/chat/completions).
Quick start#
Install OpenCode
Skip this if it is already installed.
install.shmacOS and Linux.
curl -fsSL https://opencode.ai/install | bash opencode --versionThe package is `opencode-ai`.
npm install -g opencode-ai opencode --versionCreate an API key
In the dashboard's API keys page, create a key that starts with
plm_and copy it. Set daily, weekly or monthly budgets on it while you are there.Connect to PleumRouter
Pick one of the three. OpenCode reads a custom endpoint only from the provider block in
opencode.json, not from environment variables.pleum launchLeaves your `opencode.json` alone and applies the provider config to this run only. PleumRouter models are, however, added to OpenCode's model favorites (`model.json`) and stay there.
npm i -g pleumrouter pleum login # sign in with the browser pleum launch opencode # temporary provider config for this run onlyFirst `export` your key as the `PLEUM_API_KEY` environment variable in your shell. The key is read through `{env:PLEUM_API_KEY}`.
{ "$schema": "https://opencode.ai/config.json", "model": "pleum/gpt-6-sol", "provider": { "pleum": { "npm": "@ai-sdk/openai-compatible", "name": "PleumRouter", "options": { "baseURL": "https://apirouter.pleum.ai/v1", "apiKey": "{env:PLEUM_API_KEY}" }, "models": { "gpt-6-sol": {}, "claude-sonnet-5": {}, "deepseek-ai/DeepSeek-V4.1-Flash": {} } } } }`/connect` stores only the key. The address and models still belong in `opencode.json`.
# 1) in OpenCode: run /connect, choose Other, enter provider id "pleum", paste your plm_ key # (stored in ~/.local/share/opencode/auth.json) # # 2) opencode.json — same block as above, but without "apiKey": # provider.pleum.options = { "baseURL": "https://apirouter.pleum.ai/v1" }Pick a model and check
Run
opencodeand choose a PleumRouter model in/models. Ifopencode.jsonhas a top-levelmodelset topleum/<model id>, OpenCode starts with that model. A reply to one prompt means you are connected.Terminalcd your-project opencode # inside OpenCode, pick a PleumRouter model /models
Why use PleumRouter with OpenCode?#
- Pay only for what you use from prepaid credits. Credits are deducted separately from the tool maker's subscription.
- Set budgets and limits per key. Daily, weekly and monthly budgets, model allow-lists and team budgets help you manage what an agent spends.
- One key, many models. Pick Claude, GPT, Gemini or open models; automatic retries and fallback cover provider outages; usage shows up in the dashboard.
How it works#
OpenCode uses the @ai-sdk/openai-compatible adapter to send OpenAI Chat Completions requests to {baseURL}/chat/completions. PleumRouter accepts them, handles streaming (SSE) and tool calls as they are, and forwards them to the provider of the model you chose. Auth sends your plm_ key as Authorization: Bearer. In provider.pleum, pleum is the provider ID, and models are referenced as pleum/<model id>.
Configuration reference#
| Setting | Notes |
|---|---|
| modelpleum/gpt-6-sol | Optional. Default model at startup (provider id/model id). |
| provider.pleum.npm@ai-sdk/openai-compatible | The OpenAI-compatible Chat Completions adapter. |
| provider.pleum.namePleumRouter | The name shown in the model picker. |
| options.baseURLhttps://apirouter.pleum.ai/v1 | Ends at /v1. Do not append /chat/completions. |
| options.apiKey{env:PLEUM_API_KEY} | Reads the key from an environment variable. Omit it if you stored the key with /connect. |
| models{ "gpt-6-sol": {} } | The model IDs to show in /models. Only the ones listed here appear. |
| models.<id>.limit{ "context": 1050000, "output": 128000 } | Optional. Context and output limits, so compaction happens at the right time. |
| Config file location./opencode.json | Per project. For all projects, use ~/.config/opencode/opencode.json. |
| Key storage~/.local/share/opencode/auth.json | Where a key entered with /connect is stored. |
Choosing models#
Only the IDs you list in models appear in /models. Look up exact IDs in the model catalog or with GET /v1/models. Adding limit.context and limit.output per model lets OpenCode compact at the right time, and name is the label shown in the picker. Add -latest (as in claude-sonnet-latest) to always get the newest release of a family. To skip the picker on startup, set a top-level model to pleum/<model id>. It applies to the terminal, the desktop app and opencode run. OpenCode 2 does not accept opencode --model, so this setting decides the starting model, while opencode run accepts --model pleum/<model id>.
{
"provider": {
"pleum": {
"models": {
"gpt-6-sol": {
"name": "GPT-6 Sol",
"limit": { "context": 1050000, "output": 128000 }
},
"claude-sonnet-latest": { "name": "Claude Sonnet (latest)" }
}
}
}
}OpenCode is built for many providers. Tool-calling quality can vary by model.
Compatibility#
| Feature | Status | Notes |
|---|---|---|
| Streaming (SSE) | Yes | Chat Completions streaming is used as is. |
| Tool calling | Yes | OpenAI-format tools pass through. The model must support tool calls. |
| Image input | Yes | Works only when the selected model accepts images. |
| Automatic model list | Partial | OpenCode does not fetch a custom provider's list, so you list models in models yourself. |
Desktop app and IDE extensions#
The OpenCode desktop app and IDE extensions read the same opencode.json and auth.json as the terminal. Once you are connected in the terminal, just pick a model — no extra setup. After editing the config, fully quit and reopen the app; the provider list is read only at startup.
Troubleshooting#
| Symptom | Cause and fix |
|---|---|
| 401 Unauthorized | {env:PLEUM_API_KEY} is empty or the key is wrong. Run echo $PLEUM_API_KEY in the same shell, and if you stored it with /connect, check the key in auth.json. |
| Not sure the key was saved | Run opencode auth list to see stored credentials. If pleum is missing, run /connect again. |
| A model you added is not in the list | Fully quit and reopen OpenCode (including the desktop app). Providers and models are read only at startup. |
PleumRouter models are missing from /models | Check that you listed the IDs under models in opencode.json and that the provider ID (pleum) matches what you entered in /connect, then restart OpenCode. |
I only ran /connect and nothing works | /connect stores only the key. provider.pleum.options.baseURL and models must be written in opencode.json. |
| 404 Not Found | Check that baseURL is https://apirouter.pleum.ai/v1. Do not append /chat/completions. |
| model not found | An ID listed under models is not in the catalog. Confirm exact IDs with GET /v1/models. |
| Where should the config file go? | Use ./opencode.json in the project root for one project, or ~/.config/opencode/opencode.json for all projects. |
Cost & security tips#
- Set a budget on the key. A coding agent calls the model many times per task and resends long context. Daily, weekly or monthly budgets on your API key make costs easier to predict.
- Keep the key out of git. Make sure a key in your shell profile or config file never gets committed, and if you suspect a leak, revoke it in the dashboard and issue a new one.
- Check where sensitive code goes. Prompts and code are sent to the provider of the model you pick. Use Data residency and PII masking to control that.