> ## Documentation Index
> Fetch the complete documentation index at: https://docs.haitoken.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# ZCode

> Connect ZCode to HaiToken

ZCode is an AI coding assistant from Zhipu AI that supports custom providers compatible with the `OpenAI` and `Anthropic` protocols. For HaiToken, the `OpenAI` path is usually the most stable and broadly compatible choice; if you explicitly want the Claude / Anthropic ecosystem, you can also use the `Anthropic` path.

## What you need

* A HaiToken API key
* HaiToken OpenAI-compatible address: `https://api.haitoken.ai/v1`
* HaiToken Claude / Anthropic-compatible address: `https://api.haitoken.ai`
* At least one available model ID, such as `deepseek-v4-flash`

<Note>
  ZCode is configured entirely through the GUI, so the steps are essentially the same on Windows, macOS, and Linux. If menu placement or dialog layout differs slightly on your system, follow the actual UI — the API key, Base URL, and model ID values remain the same.
</Note>

## Setup Steps

### Choose the protocol first

In ZCode, the two common choices are:

* `OpenAI`: recommended first, broader compatibility, and the main flow in this guide
* `Anthropic`: also common, useful when you explicitly want the Claude / Messages ecosystem

If you do not have a strong reason, start with `OpenAI`.

### Step 1: Open Model Settings

In the ZCode main interface, click **Model Settings** in the left sidebar to open the model provider management page.

<img src="https://mintcdn.com/hai-token/ispw4laipa3cbnL7/images/zcode/PixPin_2026-07-10_10-10-24.png?fit=max&auto=format&n=ispw4laipa3cbnL7&q=85&s=b1a5f9ef49efd1eb5bd978a20367fb2e" alt="Open ZCode model settings" width="1200" height="800" data-path="images/zcode/PixPin_2026-07-10_10-10-24.png" />

### Step 2: Add a Custom Provider

In the **Custom Providers** area of the model settings page, click the **+ Add Provider** button to open the provider configuration form.

### Step 3: Fill in HaiToken Configuration

In the provider configuration form, enter the following:

| Field         | Value                                                                                                   |
| ------------- | ------------------------------------------------------------------------------------------------------- |
| Provider name | `haitoken` (customizable)                                                                               |
| Base URL      | Use `https://api.haitoken.ai/v1` for `OpenAI`; use `https://api.haitoken.ai` for `Anthropic`            |
| API Key       | Your HaiToken API key                                                                                   |
| API format    | Prefer `OpenAI`; choose `Anthropic Messages (/v1/messages)` if you explicitly want the Claude ecosystem |

<Warning>
  If selecting `OpenAI` as the API format causes a `/responses` suffix to appear below the Base URL field, the current configuration uses the Responses API path. HaiToken is compatible with the Chat Completions path (`/v1/chat/completions`). Select an `OpenAI` option that does not include `/responses` to ensure the correct request path.
</Warning>

<Note>
  If you choose the `Anthropic` path, do not enter `https://api.haitoken.ai/v1`. This path should use the Anthropic-style gateway prefix `https://api.haitoken.ai`, and the client should call `/v1/messages` through that gateway.
</Note>

### Step 4: Add Models

In the **Model List** area, click **+ Add Model** and enter the HaiToken model ID you want to use, such as `deepseek-v4-flash`. You can add multiple models.

### Step 5: Save the Provider

After filling in the fields, click the **Add Provider** button at the bottom of the form to save the configuration.

### Step 6: Verify Connectivity

After saving, switch to the newly configured HaiToken model in the ZCode chat or coding panel, and send a simple message (such as `hello`) to verify connectivity.

## Notes

| Item                   | Details                                                |
| ---------------------- | ------------------------------------------------------ |
| Recommended protocol   | OpenAI Chat Completions                                |
| Common request path    | `POST /v1/chat/completions`                            |
| Claude-compatible path | `POST /v1/messages`                                    |
| Auth header            | `Authorization: Bearer YOUR_API_KEY`                   |
| Model switching        | Use the model picker in the ZCode chat or coding panel |

If you need to configure advanced parameters such as temperature, max output length, or system prompt, keep the defaults for your first test and verify connectivity first.

## FAQ

| Question                                           | Solution                                                                                                                                                                                              |
| -------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Model list loads successfully but invocation fails | Check whether the API format is using the Responses API (URL suffix shows `/responses`). HaiToken is compatible with Chat Completions — select an `OpenAI` option that does not include `/responses`. |
| Endpoint is reported as invalid                    | Make sure the Base URL is `https://api.haitoken.ai/v1` without appending `/chat/completions` — ZCode appends the path automatically.                                                                  |
| I want to use the Claude / Anthropic mode          | Switch the API format to `Anthropic Messages (/v1/messages)`, and change the Base URL to `https://api.haitoken.ai` without `/v1`. This path should call `POST /v1/messages`.                          |
| `401` or authentication failed                     | Make sure the API key is valid and that ZCode is using OpenAI-compatible Bearer authentication.                                                                                                       |
| `model not found`                                  | Make sure the model ID in ZCode exactly matches a model ID exposed by HaiToken.                                                                                                                       |
| Model was added but still cannot be used           | After saving the provider, re-select the model once and, if needed, restart ZCode before testing again to avoid using a cached configuration.                                                         |

## Next

* See [Get API Key](/docs/en/quickstart/get-api-key)
* See [OpenAI format API](/docs/en/api-reference/chat/openai-format)
* See [List models](/docs/en/api-reference/models/list-models)
