---
title: "Codex CLI 中转配置：config.toml 自定义提供方"
canonical: https://relayswitch.io/zh/guides/codex-cli
generated: 2026-11-02T11:22:33.729Z
source: https://api.relayswitch.io/v1/catalog
base_url: https://api.relayswitch.io/v1
---

配置教程 · 核对于 2026-10-27

# Codex CLI 中转配置

在 ~/.codex/config.toml 里加一个 model provider 块，密钥放环境变量，Codex 的每一轮都从预付余额扣费。

## 配置步骤

1.  把下面的块写入 `~/.codex/config.toml`。`openai`、`ollama`、`lmstudio` 是保留 id，表名要用自己的。
2.  `base_url` 填 `https://api.relayswitch.io/v1`，带 `/v1`；Codex 在后面拼 `/responses`。
3.  `env_key` 指向存密钥的环境变量，密钥不写进文件：`export RELAYSWITCH_API_KEY="sk-relay-你的密钥"`，加进 shell 配置文件后再运行 `codex`。
4.  换模型：`codex --model gpt-5.3-codex`，或每个模型一个 `~/.codex/<name>.config.toml` 文件，用 `--profile <name>` 启动。`/model` 菜单列出的是 Codex 内置的 OpenAI 模型，选了会改写 profile 文件，别用它。

toml

1`# ~/.codex/config.toml`

2`model = "gpt-5.5"`

3`model_provider = "relayswitch"`

4

5`[model_providers.relayswitch]`

6`name = "RelaySwitch"`

7`base_url = "https://api.relayswitch.io/v1"`

8`env_key = "RELAYSWITCH_API_KEY"`

9`wire_api = "responses"`

资料来源：Codex 的 [Advanced Configuration](https://learn.chatgpt.com/docs/config-file/config-advanced) 与 [Configuration Reference](https://learn.chatgpt.com/docs/config-file/config-reference)（读取于 2026-10-27）。

## 推荐模型

id 照抄到模型字段。价格渲染时读取自目录；人民币为参考价，计费以美元为准。

| 模型 | 开发商 | 输入 / 百万 | 输出 / 百万 |
| --- | --- | --- | --- |
| [GPT-5.5](https://relayswitch.io/zh/models/gpt-5.5)gpt-5.5 | OpenAI | $1.80≈ ¥12.21 | $9.00≈ ¥61.07 |
| [GPT-5.3-Codex](https://relayswitch.io/zh/models/gpt-5.3-codex)gpt-5.3-codex | OpenAI | $1.75≈ ¥11.88 | $14.00≈ ¥95.00 |
| [GPT-6.1 Sol](https://relayswitch.io/zh/models/gpt-6.1-sol)gpt-6.1-sol | OpenAI | $0.60≈ ¥4.07 | $3.00≈ ¥20.36 |
| [GPT-5.4 Mini](https://relayswitch.io/zh/models/gpt-5.4-mini)gpt-5.4-mini | OpenAI | $0.75≈ ¥5.09 | $4.50≈ ¥30.54 |
| [GPT-6 Luna](https://relayswitch.io/zh/models/gpt-6-luna)gpt-6-luna | OpenAI | $0.0625≈ ¥0.424 | $0.20≈ ¥1.36 |

美元 / 百万 tokens，人民币参考价按 ECB 2026-10-30 汇率

## 一次会话多少钱

一次 40 轮的 Codex 任务：每轮发送 80,000 tokens 的缓存上下文、2,000 新输入 tokens，返回 1,500 输出 tokens。这个大小是假设；控制台的用量页显示每次请求的真实 tokens 和费用。

| 模型 | 一次会话 |
| --- | --- |
| GPT-6 Lunagpt-6-luna | $0.057≈ ¥0.387 |
| GPT-6.1 Solgpt-6.1-sol | $0.42≈ ¥2.85 |
| GPT-5.4 Minigpt-5.4-mini | $0.57≈ ¥3.87 |
| GPT-5.5gpt-5.5 | $1.20≈ ¥8.12 |
| GPT-5.3-Codexgpt-5.3-codex | $1.56≈ ¥10.56 |

按目录实时价计算；人民币参考价按 ECB 2026-10-30 汇率。

## 验证是否接通

先用 curl 列出密钥能调用的模型 id，再在工具里发第一条消息。

bash

1`curl https://api.relayswitch.io/v1/models \`

2 `-H "Authorization: Bearer sk-relay-你的密钥"`

再按 Codex 的格式（Responses API）发一条：

bash

1`export RELAYSWITCH_API_KEY="sk-relay-你的密钥"`

2`curl -i https://api.relayswitch.io/v1/responses \`

3 `-H "Authorization: Bearer $RELAYSWITCH_API_KEY" \`

4 `-H "Content-Type: application/json" \`

5 `-d '{"model": "gpt-5.5", "input": "回复 ok"}'`

两条都通，剩下的问题就在工具的字段里。请求几秒内出现在控制台的用量页。

常见问题

## 常见问题

Codex CLI 接入时最常见的五个问题。

打开控制台

一分钟内拿到密钥

[获取密钥](https://app.relayswitch.io/console)

或发邮件至 [hello@relayswitch.io](mailto:hello@relayswitch.io)

### 

### 

### 

### 

### 

相关页面

-   [全部配置教程](https://relayswitch.io/zh/guides)
-   [文档](https://relayswitch.io/zh/docs)
-   [充值](https://relayswitch.io/zh/pay)
-   [每日真实模型检测](https://relayswitch.io/zh/proof)
-   [模型与价格](https://relayswitch.io/zh/models)
-   [English guide](https://relayswitch.io/guides/codex-cli)

## 在 Codex CLI 里用一个密钥调用全部模型

USDT 充值，按 token 预付，无订阅。Base URL https://api.relayswitch.io/v1。

[模型与价格](https://relayswitch.io/zh/models)[获取密钥](https://app.relayswitch.io/console)

