配置 Codex
通过 Responses API 让 Codex 调用 OneKeyLLM。
OneKeyLLM 提供 POST /v1/responses,这是 Codex 应通过专用 provider 调用的端点。
推荐配置位置是 ~/.codex/config.toml。
1. 导出密钥
不要把密钥写进仓库。
export ONEKEYLLM_API_KEY="sk-lazytech-..."2. 添加 provider
# ~/.codex/config.toml
model = "gpt-5.4"
model_provider = "onekeyllm"
[model_providers.onekeyllm]
name = "OneKeyLLM"
base_url = "https://api.tokapi.ai/v1"
env_key = "ONEKEYLLM_API_KEY"
wire_api = "responses"env_key 告诉 Codex 从哪个本地环境变量读取 bearer。wire_api = "responses"
会选择 /v1/responses 需要的请求格式。
3. 启动 Codex
codex如果只想临时测试,不修改持久配置:
codex \
--config model='"gpt-5.4"' \
--config model_provider='"onekeyllm"' \
--config 'model_providers.onekeyllm={ name="OneKeyLLM", base_url="https://api.tokapi.ai/v1", env_key="ONEKEYLLM_API_KEY", wire_api="responses" }'备选:覆盖 OpenAI provider
Codex 也提供 openai_base_url,可把内置 OpenAI provider 指向自定义 base URL。
建议只在用户配置中使用,不要放在项目 .codex/config.toml 中,因为项目配置不会重定向凭据。
# ~/.codex/config.toml
openai_base_url = "https://api.tokapi.ai/v1"快速验证
curl https://api.tokapi.ai/v1/responses \
-H "Authorization: Bearer $ONEKEYLLM_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model":"gpt-5.4","input":"Reply with ok"}'来源:Codex advanced configuration 和 Codex environment variables。