# 在 Codex CLI 中使用 BigModel.io

> 在 Codex CLI 的 config.toml 中把 BigModel.io 添加为模型提供方，base_url 填 https://bigmodel.io/v1、wire_api 填 "responses"，并选用支持 Responses API 的分组。

网页版: https://bigmodel.io/zh-cn/docs/codex-cli · 更新于 2026-10-18

Codex CLI 从 `~/.codex/config.toml` 读取自定义提供方，并且只使用 OpenAI **Responses** API。BigModel.io 在 `https://bigmodel.io/v1/responses` 提供该接口，但不是每个分组都支持，请先检查你的分组。

| 配置项 | 值 |
|---|---|
| `base_url` | `https://bigmodel.io/v1` |
| `wire_api` | `"responses"`（唯一支持的值） |
| `env_key` | `BIGMODEL_API_KEY`（存放 Key 的环境变量名） |
| `model` | [模型目录](https://bigmodel.io/zh-cn/models)中的模型 ID |

> Codex 已不再支持 `wire_api = "chat"`，旧配置会报错 `wire_api = "chat" is no longer supported`。它没有 Chat Completions 回退，所以仅支持 Chat Completions 的分组的 Key 无法用于 Codex。

## 开始之前

1. 在 [API Keys](https://bigmodel.io/keys) 创建 Key。
2. 确认 Key 所在分组对目标模型提供 `/v1/responses`。OpenAI 和 Anthropic 平台的分组支持；GLM、DeepSeek 分组仅支持 Chat Completions，这里会返回 404，即使同一模型在 `/v1/chat/completions` 上可用。

```bash
curl https://bigmodel.io/v1/responses \
  -H "Authorization: Bearer $BIGMODEL_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"glm-5.3","input":"ping"}'
```

返回带 `output` 的 JSON，说明这个分组可以配合 Codex。返回 404 `not_found_error` 并提示平台 "only supports /v1/chat/completions"，说明不行：换一个分组的 Key，或改用 [OpenCode](https://bigmodel.io/zh-cn/docs/opencode)、[Cline](https://bigmodel.io/zh-cn/docs/cline) 等 Chat Completions 工具。

## 配置 config.toml

在 `~/.codex/config.toml` 中加入（没有就新建）：

```toml
model = "glm-5.3"
model_provider = "bigmodel"

[model_providers.bigmodel]
name = "BigModel"
base_url = "https://bigmodel.io/v1"
env_key = "BIGMODEL_API_KEY"
wire_api = "responses"
```

然后在运行 Codex 的终端里 export Key 并启动：

```bash
export BIGMODEL_API_KEY="sk-..."
codex
```

`env_key` 填的是环境变量名，不要把 Key 本身写进 `config.toml`。提供方不要命名为 `openai`、`ollama` 或 `lmstudio`，这些 ID 是保留的。如果 Codex 对上下文长度判断有误，可按模型页设置 `model_context_window`。

## 用 profile 切换模型

profile 是单独的文件，命名为 `~/.codex/<name>.config.toml`，用 `--profile <name>` 选择。例如 `~/.codex/fast.config.toml`：

```toml
model = "glm-5.3-flash"
model_provider = "bigmodel"
```

```bash
codex --profile fast
codex -m kimi-k3 "explain this repository"
```

提供方配置仍放在 `~/.codex/config.toml`。用到的每个模型都必须由 Key 所在分组在 `/v1/responses` 上提供。

## 验证配置

```bash
codex exec "say hi"
```

应返回一句简短回复，并在[用量](https://bigmodel.io/usage)页看到端点为 `/v1/responses` 的请求。

## 常见问题排查

**`wire_api = "chat" is no longer supported`。** 配置来自旧版 Codex，改成 `wire_api = "responses"`。

**404 `not_found_error`：`... platform only supports /v1/chat/completions; /v1/responses is not available`。** Key 所在分组仅支持 Chat Completions（GLM 或 DeepSeek 平台），Codex 无法回退到 chat。换一个支持 Responses 的分组的 Key，或改用 [OpenCode](https://bigmodel.io/zh-cn/docs/opencode)、[Cline](https://bigmodel.io/zh-cn/docs/cline)。

**所有请求都返回 404。** 检查 `base_url`：必须以 `/v1` 结尾，不要带 `/responses`。

**401 `API_KEY_REQUIRED` 或 "missing environment variable"。** 启动 Codex 的终端里没有 `BIGMODEL_API_KEY`。用 `echo ${BIGMODEL_API_KEY:0:5}` 检查，想长期生效就写进 `~/.zshrc` 或 `~/.bashrc`。

**400 `invalid_request_error`，提到 `previous_response_id`。** BigModel.io 不在 HTTP 上保存响应状态，客户端需要每轮发送完整输入。请更新 Codex；仍有问题请到[工单](https://bigmodel.io/support)反馈。

**Codex 仍在使用 OpenAI。** 缺少顶层的 `model_provider = "bigmodel"`，或某个 profile 文件覆盖了它。显式加 `--profile` 运行，排除 profile 混用。

**503 `api_error`：`No available accounts: no available accounts supporting model: ...`。** 模型 ID 拼错，或 Key 所在分组不提供该模型。从模型页复制 ID，并用 `curl https://bigmodel.io/v1/models -H "Authorization: Bearer $BIGMODEL_API_KEY"` 查看可用模型。

**403 `INSUFFICIENT_BALANCE` 或 429 `API_KEY_QUOTA_EXHAUSTED`。** 到[充值页](https://bigmodel.io/purchase)充值或提高 Key 额度。429 `rate_limit_error`（"Concurrency limit exceeded for user"）表示并发过多，Codex 会重试，频繁出现时请降低并发。

## 相关文档

- [Codex、Claude Code、Cursor、Cline 如何配置 Base URL](https://bigmodel.io/zh-cn/blog/configure-base-url-codex-claude-code-cursor)：同一段 `config.toml`。
- [CC Switch](https://bigmodel.io/zh-cn/docs/cc-switch)：可以替你写好 Codex 提供方配置。
- [Claude Code](https://bigmodel.io/zh-cn/docs/claude-code)：Anthropic 协议的终端编程助手。
- [Responses API 参考](https://bigmodel.io/zh-cn/docs/api-responses)。
