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

# ZCode

> Connect ZCode to HaiRoute

ZCode is an AI coding assistant from Zhipu AI that supports custom providers compatible with the `OpenAI` and `Anthropic` protocols. For HaiRoute, 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 HaiRoute API key
* HaiRoute OpenAI-compatible address: `https://api.hairoute.ai/v1`
* HaiRoute Claude / Anthropic-compatible address: `https://api.hairoute.ai`
* At least one available model ID, such as `gpt-5.4`

<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/_6nNjs176oTbHvVD/images/zcode/PixPin_2026-08-17_17-29-40.png?fit=max&auto=format&n=_6nNjs176oTbHvVD&q=85&s=2981e3cbe24bea0aa70c53c1bc9a641a" alt="Open ZCode model settings and configure the HaiRoute provider" width="1200" height="868" data-path="images/zcode/PixPin_2026-08-17_17-29-40.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 HaiRoute Configuration

In the provider configuration form, enter the following:

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

<Warning>
  HaiRoute supports both OpenAI Chat Completions and OpenAI Responses. If the Base URL field displays a `/responses` suffix after you select an OpenAI option, ZCode will use `POST /v1/responses`, which is supported. Select an OpenAI option without `/responses` only when you specifically need Chat Completions (`POST /v1/chat/completions`).
</Warning>

<Note>
  If you choose the `Anthropic` path, do not enter `https://api.hairoute.ai/v1`. This path should use the Anthropic-style gateway prefix `https://api.hairoute.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 HaiRoute model ID you want to use, such as `gpt-5.4`. 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 HaiRoute 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                                                                                                                                                                                |
| --------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| A `/responses` suffix appears in the Base URL | This selects `POST /v1/responses`, which HaiRoute supports. Keep it for Responses-compatible clients; choose an OpenAI option without `/responses` only when you need Chat Completions. |
| Endpoint is reported as invalid               | Make sure the Base URL is `https://api.hairoute.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.hairoute.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 HaiRoute.                                                                                                         |
| 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)
