Command-line toolsAnthropic + OpenAI compatible

How to use OpenCode with a custom Anthropic or OpenAI-compatible provider

Add a custom provider to opencode.json with @ai-sdk/anthropic or @ai-sdk/openai-compatible and baseURL https://www.ccsub.net/api/v1, plus /connect and fixes.

Last updated:OpenCode Official site

Copy-paste configuration

These are the three values the tool needs. Create the API key on the API Keys page of your CCSub dashboard.

baseURL
https://www.ccsub.net/api/v1(same for both packages; must include /v1)
apiKey
sk-your-ccsub-key(or store it with /connect)
model
ccsub/claude-sonnet-5(provider ID / model ID)
~/.config/opencode/opencode.json (Anthropic package)
{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "ccsub": {
      "npm": "@ai-sdk/anthropic",
      "name": "CCSub",
      "options": {
        "baseURL": "https://www.ccsub.net/api/v1",
        "apiKey": "{env:CCSUB_API_KEY}"
      },
      "models": {
        "claude-sonnet-5": { "name": "claude-sonnet-5" }
      }
    }
  },
  "model": "ccsub/claude-sonnet-5"
}

For model, use an ID such as claude-sonnet-5 — the full list of model IDs is on the models page. No key yet? Create an account first.

Steps at a glance

  1. 1

    Install OpenCode and create a CCSub key

    Install OpenCode as described on opencode.ai, then create an sk- key on the API Keys page of the CCSub dashboard.

  2. 2

    Export the key

    Add export CCSUB_API_KEY="sk-your-key" to your shell profile and open a new terminal, or save the key later with /connect.

  3. 3

    Add a provider to opencode.json

    In ~/.config/opencode/opencode.json, add a ccsub entry under provider with npm set to @ai-sdk/anthropic or @ai-sdk/openai-compatible and options.baseURL set to https://www.ccsub.net/api/v1.

  4. 4

    Declare models and set the default

    List the model IDs you want under models (for example claude-sonnet-5) and set the top-level model to ccsub/claude-sonnet-5.

  5. 5

    Run and verify

    Run opencode in your project, send a message, and check the Usage page in the CCSub dashboard.

OpenCode is an open-source coding agent for the terminal. It talks to models through the Vercel AI SDK's provider packages, which means it can reach CCSub over either the Anthropic protocol or the OpenAI-compatible protocol. Everything lives in one JSON file; edit it and restart OpenCode.

Where the config lives

OpenCode file locations
Global config
~/.config/opencode/opencode.jsonApplies to every project. On Windows: %USERPROFILE%\.config\opencode\
Project config
opencode.json in the project rootMerged with the global file; the project wins on conflicts.
Stored credentials
~/.local/share/opencode/auth.jsonWhere /connect saves keys.

Option 1: Anthropic protocol (for Claude model IDs)

{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "ccsub": {
      "npm": "@ai-sdk/anthropic",
      "name": "CCSub",
      "options": {
        "baseURL": "https://www.ccsub.net/api/v1",
        "apiKey": "{env:CCSUB_API_KEY}"
      },
      "models": {
        "claude-sonnet-5": { "name": "claude-sonnet-5" }
      }
    }
  },
  "model": "ccsub/claude-sonnet-5"
}

This URL needs /v1 — unlike Claude Code. @ai-sdk/anthropic appends only /messages to baseURL, and adds /v1 by itself only when the host is the official https://api.anthropic.com. With the bare https://www.ccsub.net, requests go to /messages and fail with a 404. And if you leave baseURL out, the SDK falls back to the ANTHROPIC_BASE_URL environment variable — which, if you set it up for Claude Code, has no /v1 either. Always set baseURL explicitly.

Option 2: OpenAI-compatible protocol (for GPT model IDs)

{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "ccsub-openai": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "CCSub OpenAI",
      "options": {
        "baseURL": "https://www.ccsub.net/api/v1",
        "apiKey": "{env:CCSUB_API_KEY}"
      },
      "models": {
        "gpt-5.5": { "name": "gpt-5.5" }
      }
    }
  },
  "model": "ccsub-openai/gpt-5.5"
}

@ai-sdk/openai-compatible appends /chat/completions to the base URL. You can keep both providers side by side in the same provider object and switch between them with /models inside OpenCode.

What the fields mean

  • The key under provider (ccsub, ccsub-openai) is the provider ID. Name it whatever you like; you will reference it in model names and in /connect.
  • {env:CCSUB_API_KEY} reads the key from an environment variable. Add export CCSUB_API_KEY="sk-your-key" to your shell profile and open a new terminal.
  • models declares the model IDs you want to use. The model field takes IDs such as claude-sonnet-5; every available ID is on the models page. You can add a limit object (context, output) to each model so OpenCode can track how much context is left — without it, OpenCode cannot warn you before the context fills up.
  • The top-level model uses the providerID/modelID form, e.g. ccsub/claude-sonnet-5.

Keeping the key out of the file: /connect

Inside OpenCode, run /connect, choose Other, type the provider ID exactly as it appears in your config (for example ccsub) and paste the key. OpenCode saves it to ~/.local/share/opencode/auth.json, and you can drop apiKey from the config. opencode auth list shows what is stored.

Verify

Run opencode in a project, send a message, and look for the request on the Usage page of your CCSub dashboard. If you manage several tools, CC Switch also has a CCSub preset for OpenCode. For Anthropic's own CLI, see the Claude Code guide.

Common errors and fixes

404, or an HTML page instead of JSON

Cause:The Anthropic baseURL is the bare https://www.ccsub.net, so requests hit /messages; or baseURL is missing and the SDK fell back to an ANTHROPIC_BASE_URL variable without /v1.

Fix:Set options.baseURL explicitly to https://www.ccsub.net/api/v1.

401 authentication_error

Cause:The variable behind {env:CCSUB_API_KEY} is empty, or the provider ID you used in /connect does not match the key under provider.

Fix:echo $CCSUB_API_KEY to check it; make the /connect ID identical to the config key and confirm with opencode auth list.

404 Unknown model

Cause:The model is a display name or lacks the provider prefix.

Fix:Use the provider/model form such as ccsub/claude-sonnet-5, with IDs from the models page.

For more error messages and what they mean, see the error troubleshooting index. Installation and network issues are covered in the troubleshooting docs (Chinese).

FAQ

Why does the Anthropic baseURL need /v1 here?

@ai-sdk/anthropic only appends /messages, and it adds /v1 automatically only for the official api.anthropic.com host. Use https://www.ccsub.net/api/v1 (or https://www.ccsub.net/v1), not the bare domain you would give Claude Code.

@ai-sdk/anthropic or @ai-sdk/openai-compatible?

Both work with CCSub. Use the Anthropic package for claude- model IDs and the OpenAI-compatible package for gpt- IDs; the latter calls /chat/completions.

Do I have to put the key in the config file?

No. Reference an environment variable with {env:CCSUB_API_KEY}, or run /connect, choose Other, enter the provider ID ccsub and paste the key. It is then stored in ~/.local/share/opencode/auth.json.

Which wins, the project opencode.json or the global one?

They are merged and the project file wins on conflicts. Keep keys out of project files that get committed.

What goes in the model field?

provider ID plus model ID, e.g. ccsub/claude-sonnet-5. Declare the model under the provider's models first; the full list of IDs is on the CCSub models page.

See all integration guides

Need a CCSub API key?

Sign up, create a key in the dashboard, and paste the values above into your tool. Pay-as-you-go balance does not expire — you only pay for the tokens you use.