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

# OpenClaw setup with LaoZhang API

> Add LaoZhang API to OpenClaw as a custom provider, run GPT over the OpenAI format and Claude, DeepSeek, and GLM over the Anthropic format, and fix compaction, doctor, and gateway errors.

OpenClaw reaches LaoZhang API through two custom providers: `openai-completions` for GPT, and `anthropic-messages` for Claude, DeepSeek, and GLM.

| Item | Details |
| - | - |
| Where | `openclaw onboard` → Custom provider, or `~/.openclaw/openclaw.json` |
| OpenAI-format base URL | `https://api.laozhang.ai/v1` |
| Anthropic-format base URL | `https://api.laozhang.ai` |
| Tokens | `default` group for the OpenAI format, `Claude Code` group for the Anthropic format, both with the Usage first billing mode |
| Recommended models | `gpt-6.1-sol`, `claude-sonnet-5-5`, `deepseek-v4-pro`, `glm-5.2` |
| Last verified | November 4, 2026, OpenClaw 2026.10.10 |

## Install OpenClaw

OpenClaw needs Node.js `>=24.16.0 <25` or `>=26.1.0`. Node 26 is recommended; Node 24 releases before 24.16.0 are not supported.

The install script sets up Node for you if it's missing, then starts the onboarding wizard:

```bash theme={null}
curl -fsSL https://openclaw.ai/install.sh | bash
```

To install without starting the wizard, run `curl -fsSL https://openclaw.ai/install.sh | bash -s -- --no-onboard` instead.

If you'd rather manage Node yourself, install with npm and run the wizard, which also installs the background gateway:

```bash theme={null}
npm install -g openclaw@latest --allow-scripts=openclaw
openclaw onboard --install-daemon
```

With npm 11.15 or earlier, drop `--allow-scripts=openclaw`. On macOS you can also use the desktop app from the [OpenClaw releases](https://github.com/openclaw/openclaw/releases) page.

## Connect with the wizard

**1. Create a LaoZhang API token**

In [Tokens](https://api.laozhang.ai/token), create tokens with the **Usage first** billing mode, one per request format you'll use:

* `default` group for the OpenAI format (GPT).
* `Claude Code` group for the Anthropic format (Claude, DeepSeek, and GLM).

Copy the keys and export them in your shell:

```bash theme={null}
export LAOZHANG_API_KEY="YOUR_DEFAULT_GROUP_KEY"
export LAOZHANG_CLAUDE_API_KEY="YOUR_CLAUDE_CODE_GROUP_KEY"
```

If you only use GPT, the first key is enough.

**2. Run the wizard and pick Custom provider**

Run `openclaw onboard`, choose **Quick start** or **Custom setup**, and select **Custom provider** when asked for a model provider. Then choose the compatibility type and enter the base URL:

* **OpenAI compatible**: `https://api.laozhang.ai/v1`
* **Anthropic compatible**: `https://api.laozhang.ai`

Paste the matching key when prompted: the `default`-group key for OpenAI compatible, or the `Claude Code`-group key for Anthropic compatible. To change these answers later, run `openclaw configure`.

**3. Or run it non-interactively**

The same setup in one command, reading the key from the environment:

```bash theme={null}
openclaw onboard --non-interactive --accept-risk \
  --auth-choice custom-api-key \
  --custom-provider-id laozhang \
  --custom-compatibility openai \
  --custom-base-url "https://api.laozhang.ai/v1" \
  --custom-api-key "$LAOZHANG_API_KEY"
```

Without `--custom-model-id`, OpenClaw reads every model from `/v1/models` on LaoZhang API. For Claude, DeepSeek, or GLM, use the Anthropic format instead with your `Claude Code`-group key. It requires a model ID:

```bash theme={null}
openclaw onboard --non-interactive --accept-risk \
  --auth-choice custom-api-key \
  --custom-provider-id laozhang-anthropic \
  --custom-compatibility anthropic \
  --custom-base-url "https://api.laozhang.ai" \
  --custom-api-key "$LAOZHANG_CLAUDE_API_KEY" \
  --custom-model-id claude-sonnet-5-5
```

**4. Set the default model and check it**

```bash theme={null}
openclaw models set laozhang/gpt-6.1-sol
openclaw models status
```

`openclaw models status` should show `laozhang/gpt-6.1-sol` as the default.

**5. Run a test turn**

Run one agent turn from the terminal. The prompt asks the model to use a tool, so a correct answer shows that chat and tool calls both work:

```bash theme={null}
openclaw agent --local --model laozhang/gpt-6.1-sol \
  -m "How many files are in the current directory? Use a tool to check."
```

* `--local` runs a single turn with the credentials in your config.
* `--model` overrides the model for this run only.
* `--session-id <name>` starts a fresh session if you want a clean history.

The request then appears in your [call logs](https://api.laozhang.ai/log). To chat in the browser instead, run `openclaw dashboard` (optional).

## Configure GPT, Claude, DeepSeek, and GLM in openclaw\.json

To use all four side by side, define both providers in `~/.openclaw/openclaw.json`. The file is JSON5, so comments and trailing commas are allowed. Run `openclaw config file` if you're not sure which file your install reads.

Each provider reads its own key:

* `laozhang` (OpenAI format): `LAOZHANG_API_KEY`, the `default`-group key
* `laozhang-anthropic` (Anthropic format): `LAOZHANG_CLAUDE_API_KEY`, the `Claude Code`-group key

```json5 theme={null}
{
  models: {
    providers: {
      // OpenAI format: GPT
      laozhang: {
        baseUrl: "https://api.laozhang.ai/v1",
        apiKey: "${LAOZHANG_API_KEY}",
        api: "openai-completions",
        models: [
          {
            id: "gpt-6.1-sol",
            name: "GPT-6.1 Sol",
            reasoning: true,
            input: ["text", "image"],
            contextWindow: 200000, // set to the model's real context window
            maxTokens: 32000,
            compat: { supportsUsageInStreaming: true },
          },
        ],
      },
      // Anthropic format: Claude, DeepSeek, and GLM
      "laozhang-anthropic": {
        baseUrl: "https://api.laozhang.ai",
        apiKey: "${LAOZHANG_CLAUDE_API_KEY}",
        api: "anthropic-messages",
        models: [
          {
            id: "claude-sonnet-5-5",
            name: "Claude Sonnet 5.5",
            reasoning: true,
            input: ["text", "image"],
            contextWindow: 200000,
            maxTokens: 32000,
          },
          {
            id: "deepseek-v4-pro",
            name: "DeepSeek V4 Pro",
            reasoning: true,
            input: ["text"],
            contextWindow: 128000, // set to the model's real context window
            maxTokens: 32000,
          },
          {
            id: "glm-5.2",
            name: "GLM-5.2",
            reasoning: true,
            input: ["text"],
            contextWindow: 128000, // set to the model's real context window
            maxTokens: 32000,
          },
        ],
      },
    },
  },
  agents: {
    defaults: {
      model: { primary: "laozhang/gpt-6.1-sol" },
    },
  },
}
```

Run `openclaw config validate` after editing. What each part does:

* **`api`**: `openai-completions` sends Chat Completions requests and is the default when a provider has a base URL but no `api`.
* **`anthropic-messages`**: sends Messages requests and adds the Anthropic auth and version headers itself, so you don't set any headers.
* **`baseUrl`**: include `/v1` for the OpenAI format. For the Anthropic format, use the bare host, as in OpenClaw's own docs.
* **`input`**: models accept text only unless you list `"image"`. Add it only for models that take images.
* **`contextWindow`**: OpenClaw assumes 200,000 tokens when it's missing and uses this value to decide when to compact. Set it to the actual context window from the model vendor's documentation.
* **`maxTokens`**: Claude models on LaoZhang API return at most 32,768 output tokens per response, so keep Claude at or below that. See [Claude model limits](https://docs.laozhang.ai/en/api-reference/claude.md#claude-model-limits).
* **`compat.supportsUsageInStreaming`**: OpenClaw doesn't request token usage in streamed responses from custom OpenAI-format hosts unless you turn this on. LaoZhang API returns usage in streams, and with real counts compaction stops relying on estimates.

### Keep the key out of the file

Each `${...}` reference is replaced with its environment variable when OpenClaw loads the config. The gateway runs as a background service, so it may not see variables exported only in your shell profile. In that case, define both variables in the config's `env.vars` block and keep the references in `apiKey`:

```json5 theme={null}
{
  env: {
    vars: {
      LAOZHANG_API_KEY: "YOUR_DEFAULT_GROUP_KEY",
      LAOZHANG_CLAUDE_API_KEY: "YOUR_CLAUDE_CODE_GROUP_KEY",
    },
  },
}
```

That block holds your full keys, so keep the file out of repositories and screenshots.

### Switch models

Changes to `models.providers`, `agents.defaults.models`, and the model selection reload automatically, with no gateway restart. To switch models:

* **Default for new sessions**: `openclaw models set laozhang-anthropic/claude-sonnet-5-5`, or edit `agents.defaults.model.primary`
* **Current chat only**: send `/model laozhang-anthropic/deepseek-v4-pro`
* **See what's configured**: `openclaw models list --provider laozhang-anthropic`

Model references always take the form `provider/model-id`.

### Request fields for OpenAI-format models

For custom OpenAI-format hosts, OpenClaw sends `max_completion_tokens` and, for models with `reasoning: true`, `reasoning_effort`. LaoZhang API accepts both for `gpt-6.1-sol`. Since November 4, 2026, GPT-6 and GPT-5.6 models also call tools while reasoning, so you don't need to turn reasoning off for agent work.

If a model you add rejects one of these fields, adjust it in that model's `compat` block:

* `maxTokensField` changes which field carries the output limit
* `supportsReasoningEffort: false` stops OpenClaw from sending `reasoning_effort`

## Choose a model

| Model reference | Provider type | Use it for |
| - | - | - |
| `laozhang/gpt-6.1-sol` | `openai-completions` | Everyday assistant work, writing, and agent tasks |
| `laozhang-anthropic/claude-sonnet-5-5` | `anthropic-messages` | Writing and agent tasks when you prefer Claude |
| `laozhang-anthropic/glm-5.2` | `anthropic-messages` | Agent tasks with tool calls |
| `laozhang-anthropic/deepseek-v4-pro` | `anthropic-messages` | Lower-cost everyday use |

All four call tools in OpenClaw agent turns. Other Claude IDs are `claude-opus-5-5` and `claude-haiku-5-5`. Prices are in the [model catalog](https://docs.laozhang.ai/en/models.md).

## FAQ

### "Auto-compaction could not recover this turn"

OpenClaw tried to compact the conversation and it still didn't fit the model's context. Work through these in order:

1. Retry the message once.
2. Send `/compact` to compact the session manually.
3. Send `/new` to start a fresh session.
4. Switch to a model with a larger context window.

To keep it from happening again, set `contextWindow` to the model's real value and turn on `compat.supportsUsageInStreaming` for OpenAI-format models, so OpenClaw works from actual token counts instead of estimates.

### Should I still set reserveTokensFloor?

No. These keys under `agents.defaults.compaction` are retired:

* `reserveTokens`
* `reserveTokensFloor`
* `maxHistoryShare`

Run `openclaw doctor --fix` to remove them from your config, then let compaction work from an accurate `contextWindow` for each model.

### What does openclaw doctor do?

`openclaw doctor` checks your install and config and reports problems. Useful options:

* `--fix` applies the repairs it can, such as removing retired compaction keys
* `--deep` runs a more thorough check
* `--json` prints the report as JSON
* `--generate-gateway-token` creates a new gateway token

Run `openclaw config validate` for a quick check of the config file alone.

### Port 18789 is already in use (EADDRINUSE)

Another process is already listening on the gateway port, often a gateway you installed earlier as a background service. Run `openclaw gateway status` to see whether it's running. If it is, use that gateway instead of starting a second one.

### I get AUTH\_TOKEN\_MISMATCH

The gateway and the client are reading different configs. This usually happens when you edited another copy, for example one selected by `--profile` or the `OPENCLAW_STATE_DIR` variable. Run `openclaw config file` in the same environment the gateway runs in, and make your changes in that file.

### Do I need to restart after editing openclaw\.json?

No, not for providers or models. Changes to `models.providers`, `agents.defaults.models`, and the selected model reload automatically.

### Claude keeps thinking after I set reasoning: false

`reasoning: false` on the model doesn't turn off Claude's adaptive thinking. Send `/think off` in the chat, or set `thinkingDefault` in your config to turn it off by default.

### I get 401, 403, 404, or 503 errors

* **401**: the key is wrong or wasn't copied in full. Check that both `LAOZHANG_API_KEY` and `LAOZHANG_CLAUDE_API_KEY` are set where the gateway runs.
* **403 or 503 "no available channels"**: the token's group doesn't include the model, or the model ID is misspelled. Check that `laozhang` uses a `default`-group key and `laozhang-anthropic` a `Claude Code`-group key. See [Check model availability](https://docs.laozhang.ai/en/faq/model-availability.md).
* **404**: `/v1` is missing from the OpenAI-format `baseUrl` or appears twice.
* **Insufficient balance**: see [Insufficient balance](https://docs.laozhang.ai/en/faq/balance-insufficient.md).

## Related pages

* [Integrations overview](https://docs.laozhang.ai/en/scenarios.md)
* [OpenAI protocol: Chat Completions](https://docs.laozhang.ai/en/api-reference/chat-completions.md)
* [Claude protocol: Anthropic Messages API](https://docs.laozhang.ai/en/api-reference/claude.md)
* [OpenClaw docs](https://docs.openclaw.ai)
* [OpenClaw on GitHub](https://github.com/openclaw/openclaw)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.