Skip to main content
Open Code can use HaiToken through an OpenAI-compatible provider. The stable path is a two-part flow: use /connect to store the credential, then use opencode.json to define the provider, Base URL, and models.

Protocol Note

Open Code’s custom provider integration is based on @ai-sdk/openai-compatible, so it only supports the OpenAI Chat Completions protocol; it does not support the Anthropic Messages protocol. This guide therefore only covers the OpenAI mode, with the Base URL fixed to https://api.haitoken.ai/v1.

What you need

  • A HaiToken API key
  • At least one available model ID, such as gpt-5.4
  • HaiToken OpenAI-compatible base URL: https://api.haitoken.ai/v1

Setup Steps

Step 1: Save the HaiToken API key with /connect

Inside Open Code, run /connect and store your HaiToken API key there. This step is mainly for credentials. Do not expect a Base URL input in this dialog.

Step 2: Edit opencode.json

Use your Open Code config file to define the provider, Base URL, and models. A common global path is ~/.config/opencode/opencode.json. You can read that path like this on different systems:
  • Windows: a common equivalent is %USERPROFILE%\\.config\\opencode\\opencode.json
  • macOS: commonly ~/.config/opencode/opencode.json
  • Linux: commonly ~/.config/opencode/opencode.json
Here ~ means your user home directory: usually %USERPROFILE% on Windows, /Users/<your-name> on macOS, and /home/<your-name> on Linux. Example:

Step 3: Make sure the environment variable exists

Windows PowerShell:
macOS / Linux:

Step 4: Restart Open Code and choose the model

After saving opencode.json, restart Open Code if the provider list does not refresh automatically. Then select the HaiToken provider and switch to the model you registered.

Request Mapping

Verification

  1. Open Open Code.
  2. Select the HaiToken provider and one of your configured models.
  3. Send a simple prompt such as hello.
  4. If a normal response comes back, the integration is working.

FAQ

Next