본문으로 건너뛰기

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#

  1. Install OpenCode

    Skip this if it is already installed.

    install.sh

    macOS and Linux.

    curl -fsSL https://opencode.ai/install | bash
    opencode --version
  2. Create 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.

  3. 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 launch

    Leaves 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 only
  4. Pick a model and check

    Run opencode and choose a PleumRouter model in /models. If opencode.json has a top-level model set to pleum/<model id>, OpenCode starts with that model. A reply to one prompt means you are connected.

    Terminal
    cd 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#

SettingNotes
modelpleum/gpt-6-solOptional. Default model at startup (provider id/model id).
provider.pleum.npm@ai-sdk/openai-compatibleThe OpenAI-compatible Chat Completions adapter.
provider.pleum.namePleumRouterThe name shown in the model picker.
options.baseURLhttps://apirouter.pleum.ai/v1Ends 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.jsonPer project. For all projects, use ~/.config/opencode/opencode.json.
Key storage~/.local/share/opencode/auth.jsonWhere 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>.

opencode.json
{
  "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#

FeatureStatusNotes
Streaming (SSE)YesChat Completions streaming is used as is.
Tool callingYesOpenAI-format tools pass through. The model must support tool calls.
Image inputYesWorks only when the selected model accepts images.
Automatic model listPartialOpenCode 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#

SymptomCause 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 savedRun opencode auth list to see stored credentials. If pleum is missing, run /connect again.
A model you added is not in the listFully quit and reopen OpenCode (including the desktop app). Providers and models are read only at startup.
PleumRouter models are missing from /modelsCheck 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 FoundCheck that baseURL is https://apirouter.pleum.ai/v1. Do not append /chat/completions.
model not foundAn 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.