OpenCode

Connect OpenCode to APIClaw with an OpenAI-compatible provider in opencode.json.

Prerequisites

  1. Create an API key in the API Keys dashboard.
  2. Copy a full model ID from the model hub.

Install

bash
curl -fsSL https://opencode.ai/install | bash
opencode --version

On Windows, or if you prefer npm: npm install -g opencode-ai.

Configure opencode.json

Create or edit ~/.config/opencode/opencode.json (project-level opencode.json also works):

json
{
  "$schema": "https://opencode.ai/config.json",
  "model": "apiclaw/YOUR_MODEL_ID",
  "provider": {
    "apiclaw": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "APIClaw",
      "options": {
        "baseURL": "https://apiclaw.biz/v1",
        "apiKey": "{env:APICLAW_API_KEY}"
      },
      "models": {
        "YOUR_MODEL_ID": {
          "name": "YOUR_MODEL_ID",
          "limit": { "context": 200000, "output": 16384 }
        }
      }
    }
  }
}

Set limit to the model's real context and output sizes; OpenCode has no catalog entry for APIClaw models, so without it the context window is unknown to the client.

Then supply the key. Either export the variable the config refers to:

bash
export APICLAW_API_KEY="sk-your-apiclaw-key"

or store it in OpenCode instead with opencode auth login, choosing Other and entering apiclaw as the provider id. The two are alternatives; you do not need both.

SettingValue
Provider npm package@ai-sdk/openai-compatible
Base URLhttps://apiclaw.biz/v1
Modelapiclaw/<full model ID from the model hub>

Configure with /connect

Inside OpenCode, /connect stores credentials: pick Other, enter apiclaw as the provider id, and paste your key. It does not ask for a Base URL or model, so you still need the opencode.json block above.

Verify

Run /models to confirm your model appears, then send a test prompt. Check logs if the request does not show up.

Troubleshooting

  • Provider id in opencode auth login must match the key under provider (for example apiclaw).
  • Model key must be the exact hub ID, not a display name.
  • Use @ai-sdk/openai-compatible for Chat Completions. Only switch to @ai-sdk/openai if you need the Responses API.