Suanlimao
← Back to all tutorials

Connect your tools

OpenCode

Add an openai-compatible provider in opencode.jsonc.

About 6 minFor:Developers who use OpenCode in the terminal

Before you start

  • OpenCode is installed and opencode runs
  • A key and a model name copied from the model plaza

Step 1 · STEP 0x01

Write opencode.jsonc

Create opencode.jsonc in the project root (or OpenCode's global config location) and add a provider under providers. The key is the provider ID, and models are referenced as provider-id/model-id:

terminal
$ cd your-project$ $EDITOR opencode.jsonc
jsonc
{
  "$schema": "https://opencode.ai/config.json",
  "providers": {
    "myrelay": {
      "name": "My relay",
      "env": ["MYRELAY_API_KEY"],
      "package": "@opencode/ai/providers/openai-compatible",
      "settings": {
        "baseURL": "https://api.suanlimao.shop/v1"
      },
      "models": {
        "<MODEL_NAME>": { "name": "<MODEL_NAME>" }
      }
    }
  }
}
  • settings.baseURL is https://api.suanlimao.shop/v1; the official examples all include /v1.
  • env lists the environment variables that hold the credential, here MYRELAY_API_KEY. settings.apiKey also works (sent as a Bearer token) but keeping the key out of the file is better.
  • models is keyed by model ID with name as the display name. For Responses-only models set package to @opencode/ai/providers/openai-compatible/responses; for Claude-family models use @opencode/ai/providers/anthropic-compatible with baseURL set to https://api.suanlimao.shop without /v1.
Don't guess the model name: open the model plaza, click “Copy model id” on a model card and paste it. A wrong model name is the most common error.

Open the model plaza →

Step 2 · STEP 0x02

Set the key and start

bash
export MYRELAY_API_KEY=<YOUR_API_KEY>
terminal
$ export MYRELAY_API_KEY=<YOUR_API_KEY>$ opencode> /models   # 选 myrelay/<MODEL_NAME>
  • The variable name must match the one in env. After starting OpenCode use /models to pick myrelay/<model>.
The full key is shown only once, at creation. Missed it? Revoke it and create a new one.

Create a key →

Step 3 · STEP 0x03

Send a message to verify

terminal
> 用一句话介绍这个仓库(模型开始回答,并按需读取文件)
OpenCode's config format has changed (the old shape used provider / npm / options). This follows the current official providers / package / settings shape; if your version reports a config error, compare with the Custom section of the official docs.

✓ How to tell it worked

  • /models lists myrelay/<model> and chat answers.
  • The Usage page shows the request.

FAQ

No credential / 401?

The variable name must match env and be exported before starting opencode.

I get 404.

Check baseURL is https://api.suanlimao.shop/v1 and the models key matches the plaza.

The model stops after one turn or tool calls misbehave.

Use a model marked as tool-calling on the plaza; for Responses-only models switch to the …/openai-compatible/responses package.

Related tutorials

Still stuck?

Read the troubleshooting tutorials first. If that does not help, open a ticket with the request_id, time, model and the exact error (never paste your key).