Codex CLI 是 OpenAI 的代码生成命令行工具,专为编程任务优化。本指南将帮助你配置 Codex CLI 以使用 Du's API。
Codex CLI 使用两个配置文件:
~/.codex/config.toml(macOS/Linux)或 %userprofile%\.codex\config.toml(Windows)~/.codex/auth.json(macOS/Linux)或 %userprofile%\.codex\auth.json(Windows)macOS/Linux 路径:~/.codex/config.toml
Windows 路径:%userprofile%\.codex\config.toml
配置内容:
model: 默认使用的模型,可以改为其他 GPT 或 Codex 模型model_context_window: 模型的上下文窗口大小model_auto_compact_token_limit: 自动压缩的 token 限制base_url: Du's API 的基础 URL(系统会自动添加 /v1)
:::macOS/Linux 路径:~/.codex/auth.json
Windows 路径:%userprofile%\.codex\auth.json
配置内容:
:::warning 重要提示
请将 your-api-key-here 替换为你在 Du's API 控制台创建的实际 API Key。
WebSocket 配置可以提供更好的性能和实时响应。
配置完成后,运行以下命令验证:
然后尝试一个简单的代码生成任务:
如果配置正确,Codex 应该会生成相应的代码。