Notice: Kling 4.0 is here: text-to-video and image-to-video are 20% off for a limited time. Try it now
HiAPI
Tutorials
On this page

OpenCode

Import with CC Switch or edit the config file to use DeepSeek, Claude and other models in OpenCode through HiAPI.

OpenCode is an open-source AI coding tool that runs in the terminal. You can connect it to HiAPI with a CC Switch import or by editing the config file manually; choose one of the two. The steps below use deepseek-v4.1-flash as the example; HiAPI uses the OpenAI Chat Completions protocol. This tutorial was verified on Windows 11 with OpenCode 1.19.4. Prepare a HiAPI API key before you start; if you import with CC Switch, first install a version that supports OpenCode as described in CC Switch install and one-click import.

1. Install OpenCode

On Mac / Linux, run this in a terminal:

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

If you already have Node.js (see Node.js setup), you can also install with npm. On Windows, use the install script above inside WSL, or run this in a local terminal:

Terminal
npm install -g opencode-ai

After installing, reopen the terminal and check the version:

Terminal
opencode --version

Seeing the version number is enough.

2. Configure HiAPI

Option 1: one-click import with CC Switch

  1. Open the HiAPI OpenCode connect page, choose the model and HiAPI API key, and click Prepare import.

Import interface on the connect page

  1. In the “Confirm provider import” window in CC Switch, check the items below, then click Import:
FieldExpected value
App typeOpenCode
API endpointhttps://api.hiapi.ai/v1
ModelThe same model name you chose on the connect page
API keyThe HiAPI API key you chose, filled in and hidden

Confirm the provider import

Option 2: edit the config file manually

Open the global config file ~/.config/opencode/opencode.json and add a HiAPI provider (OpenAI Chat Completions protocol). Create the file if it doesn’t exist; if you already have other configuration, only merge the provider.hiapi and model fields below. Set the Base URL to https://api.hiapi.ai/v1, without adding /chat/completions.

JSON
{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "hiapi": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "HiAPI",
      "options": {
        "baseURL": "https://api.hiapi.ai/v1",
        "apiKey": "{env:HIAPI_API_KEY}"
      },
      "models": {
        "deepseek-v4.1-flash": {
          "name": "DeepSeek V4.1 Flash"
        },
        "claude-opus-5-5": {
          "name": "Claude Opus 5.5"
        }
      }
    }
  },
  "model": "hiapi/deepseek-v4.1-flash"
}

{env:HIAPI_API_KEY} is how OpenCode reads an environment variable; leave it as is. Then set that variable in the terminal, replacing YOUR_HIAPI_API_KEY with your HiAPI API key and keeping the quotes:

Terminal
export HIAPI_API_KEY="YOUR_HIAPI_API_KEY"
PowerShell
$env:HIAPI_API_KEY = "YOUR_HIAPI_API_KEY"

The environment variable only applies to the current terminal, so start OpenCode in the same terminal after setting it; if you reopen the terminal, set it again, or add it to your shell startup file (such as ~/.zshrc) to make it permanent.

The example sets hiapi/deepseek-v4.1-flash as the default model. To switch models, change both the model definition under provider.hiapi.models and the model field.

3. Verify

Go to your project directory and start OpenCode in the terminal where you set the environment variable:

Terminal
opencode

Type /models and choose a model under the HiAPI provider, for example deepseek-v4.1-flash. Send “Hello, introduce yourself in one sentence.” A normal reply means the connection works.

Verify with a chat

The provider name may differ between the two import methods; just check the currently selected provider, model name and Base URL. You can also confirm in Request logs in the HiAPI console that requests go through HiAPI.

4. Troubleshooting

Only issues specific to OpenCode are listed here. For common errors such as 401, 404 and 429, see Common errors.

ErrorCauseFix
No HiAPI model in /modelsThe provider configuration was not loaded, or the models field doesn’t contain this modelCheck the syntax and model definitions in opencode.json; if you used CC Switch, confirm the import worked, then restart OpenCode
CC Switch does not open after clicking Prepare importCC Switch is not installed, or the current version doesn’t support this import flowInstall or update CC Switch and retry, or use the manual configuration instead
Requests still go to the original providerThe current session has not switched to the HiAPI modelUse /models to choose a model under the HiAPI provider, then send a test message
It says the API key is missingThe terminal starting OpenCode did not read the environment variableConfirm the variable name is HIAPI_API_KEY and start OpenCode in the same terminal where you set it