# 如何在 Crush 里使用 Unlid

把 Crush 接到 Unlid：创建一个 API key，把 Crush 指向下面的 base URL，再选一个模型 id。所有 Unlid 模型都用同样的设置。

## 在你的应用中使用 Unlid

任何允许添加 **OpenAI-compatible** 提供商的应用都能使用 Unlid 的所有模型。你始终只需要这三样：

|  |  |
| --- | --- |
| Base URL | `https://api.unlid.ai/v1` |
| API key | 在 [账户 → API keys](https://unlid.ai/account/keys) 中创建。以 `ul-` 开头，只显示一次。 |
| 模型 | [模型](https://unlid.ai/models.md?lang=zh) 页面中的 id，例如 `glm-5.3-flash-uncensored`。大多数应用会自动拉取模型列表。 |

下面三条规则能解决几乎所有配置问题：

- Base URL **要带** `/v1`，**不要带** `/chat/completions`，应用会自己加上。（Janitor AI 和 goose 例外，见下文。）
- 应用让你选 API 类型时，选 **OpenAI Compatible / Chat Completions**。这是 Unlid 的原生协议。Anthropic（`/v1/messages`）和 OpenAI Responses（`/v1/responses`）端点是为只支持这两种协议的 [Claude Code](https://unlid.ai/docs/clients/claude-code.md?lang=zh) 和 [Codex](https://unlid.ai/docs/clients/codex-cli.md?lang=zh) 准备的；它们会被转换成 Chat Completions，支持的功能更少。
- 如果应用有 **上下文窗口** 设置，按模型页面填写（glm-5.3-flash-uncensored：262,144 token）。默认值太小会截断长对话；太大则会报 `context_length_exceeded`。

不确定 key 能不能用？先在同一台电脑上运行下面的命令，这是区分应用问题和网络问题最快的办法：

```
curl https://api.unlid.ai/v1/models -H "Authorization: Bearer ul-…"
```

## Crush

在 `~/.config/crush/crushrc`（或项目级的 `./.crushrc`）中：

```
provider add unlid --type completions \
  --base-url "https://api.unlid.ai/v1" \
  --api-key "$UNLID_API_KEY"

model add unlid/glm-5.3-flash-uncensored \
  --name "GLM 5.3 Flash · Uncensored" \
  --context-window 262144 \
  --default-max-tokens 32768
```

使用 `--type completions`；`responses` 和 `messages` 分别对应 OpenAI Responses 和 Anthropic API。旧的 `crush.json` 格式配合 `"type": "openai-compat"` 依然可用。

遇到问题？看 [故障排查](https://unlid.ai/docs/clients.md?lang=zh#troubleshooting)，或 [配置其他应用](https://unlid.ai/docs/clients.md?lang=zh)。
