CanalAPI
Community tools

OpenCode setup

Connect OpenCode 1.x to CanalAPI with a custom provider, an environment key and manual approvals.

For terminal-based coding agents, install OpenCode using the official instructions, then run opencode --version.

Checked on 2026-11-03. This uses the 1.x configuration format, with v1.19.5 as the release reference. Official configuration was reviewed; a real CanalAPI call has not been tested. The 2.x provider format differs; do not mix the two.

Configure a provider

  1. Prepare a key and model ID. Coding tasks need a Chat Completions model with tool support.
  2. Set CANALAPI_API_KEY in the environment that launches OpenCode. Follow the Windows / macOS / Linux instructions in the API quickstart. Keep secrets out of the project repository.
  3. Merge the fields below into ~/.config/opencode/opencode.json. ~ means your user home directory. Back up existing settings rather than replacing the whole file.
{
  "$schema": "https://opencode.ai/config.json",
  "model": "canalapi/YOUR_MODEL_ID",
  "provider": {
    "canalapi": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "CanalAPI",
      "options": {
        "baseURL": "https://api.canalapi.com/v1",
        "apiKey": "{env:CANALAPI_API_KEY}"
      },
      "models": {
        "YOUR_MODEL_ID": { "name": "CanalAPI coding model" }
      }
    }
  },
  "permission": { "edit": "ask", "bash": "ask" }
}

Replace both occurrences of YOUR_MODEL_ID with the same full model ID. canalapi is the custom provider identifier; the top-level model prefix must match it. OpenCode resolves {env:CANALAPI_API_KEY} from the environment; keep the real key out of shared examples.

@ai-sdk/openai-compatible uses Chat Completions here. Do not switch SDKs based only on a model name; other protocols, including Responses, need separate verification. Configure context and output limits from the actual model specification.

Verify and start using it

  1. Launch opencode from the configured terminal and select the CanalAPI model with /models.
  2. Send “Reply only OK”, then confirm the request in CanalAPI usage logs.
  3. Ask it to explain a file in a test project without editing it. Check the reply, tool calls and approval prompts.

The example asks before edits and Bash actions. A successful chat does not validate tools, long context or multi-turn coding tasks; test features individually.

Common issues

  • Missing model: check the provider ID, the models key and the top-level model; replace every placeholder.
  • Settings seem ignored: a project's opencode.json may override user settings. Check the current directory and config precedence.
  • Empty key: a desktop launcher, different terminal or IDE may not inherit the environment. Restart the process that launches OpenCode.
  • Chat works but actions fail: distinguish permission prompts, model tool support and service errors before changing approvals.

To undo the setup, remove the added provider and default-model fields or restore the backup. Revoke an unused dedicated key in the console.

Official references: providers, configuration, permissions. For API errors, see troubleshooting.

On this page