# Craft Agent

来源: https://docs.aicentos.com/clients/craft-agent

Language: zh-CN

> 在 Craft Agent 里接入 aicentos —— 自定义 OpenAI 兼容连接，桌面端与 craft-cli 通用

Craft Agent 的 LLM 连接支持 `Custom` 类型，官方描述是「任意 URL，任意 OpenAI 兼容或 Anthropic 兼容端点」。把 Base URL 指向 aicentos，桌面端和 `craft-cli` 都能走。

## 准备工作

先在控制台为 Craft Agent 建一个专用 Key（建议命名 `craft-agent`），方便按 Key 看用量。

* 控制台：[https://aicentos.com](https://aicentos.com)
* 创建 Key：[https://aicentos.com/keys](https://aicentos.com/keys)
* 钱包充值：[https://aicentos.com/wallet](https://aicentos.com/wallet)

安装桌面端：

```bash
curl -fsSL https://thecraftagents.com/install-app.sh | bash
```

也支持 headless server 和纯命令行用法。

## 需要填写的配置

| 字段       | 值                                                                          |
| -------- | -------------------------------------------------------------------------- |
| 连接类型     | Custom（自定义）                                                                |
| 协议       | `openai-completions`，或 `anthropic-messages`                                |
| Base URL | `https://aicentos.com/v1`（OpenAI 兼容）/ `https://aicentos.com`（Anthropic 兼容） |
| API Key  | 控制台创建的 Key                                                                 |
| 模型       | 控制台「模型广场」中的模型名                                                             |

## 配置步骤

桌面端：打开设置里的 LLM 连接，新增一条，类型选 Custom，按上表填写。

命令行等价写法：

```bash
export AICENTOS_API_KEY="sk-你的-API-Key"
craft-cli run --provider openai \
  --base-url https://aicentos.com/v1 \
  --api-key "$AICENTOS_API_KEY" \
  --model 你的模型名 \
  "你好"
```

也可以直接改配置文件 `~/.craft-agent/config.json`：

```json
{
  "llmConnections": [
    {
      "providerType": "pi_compat",
      "baseUrl": "https://aicentos.com/v1",
      "customEndpoint": { "api": "openai-completions" },
      "models": [{ "id": "你的模型名" }],
      "defaultModel": "你的模型名"
    }
  ]
}
```

密钥不写在明文配置里，存在同目录的 `credentials.enc`。用界面填一次即可，不要手改这个文件。

## 测试

```bash
craft-cli run --provider openai \
  --base-url https://aicentos.com/v1 \
  --api-key "$AICENTOS_API_KEY" \
  --model 你的模型名 \
  "用一句话自我介绍"
```

能正常返回即通。再回控制台看用量，确认请求记到了这个 Key 上。

## 注意事项

* `providerType` 保持 `pi_compat`，这是它的自定义端点标识；改成内置 provider 的名字会走官方模型。
* `models` 要手填，它不会自动拉模型列表。名字必须与控制台「模型广场」完全一致（参考 [支持的模型](https://docs.aicentos.com/billing/models-list)）。
* 走 Anthropic 兼容端点时 Base URL 是 `https://aicentos.com`，不带 `/v1`，`--provider` 改成 `anthropic`。
* 桌面端的菜单位置随版本变化，找不到时以 `config.json` 的写法为准。

## 相关链接

* [Craft Agents 文档](https://thecraftagents.com/docs)
* [craft-agents 仓库](https://github.com/craft-ai-agents/craft-agents-oss)