---
title: "Codex CLI Integration"
description: "Configuration method for integrating OpenAI Codex CLI with 1折AI (model_providers in ~/.codex/config.toml), calling GPT models via the Responses API."
headingIds: {"Configuration File":"section-1","Installing Codex":"section-2","FAQ":"section-3"}
---

<aside className="docs-publication" data-pagefind-ignore>

Documentation maintained by [1ZheAI](https://1zheai.com/en/editorial/#publisher). [Sources and corrections](https://1zheai.com/en/editorial/).

Found an error? [Contact support](mailto:support@1zheai.com) with the page address and a description. Do not send API keys or account credentials.

</aside>
OpenAI / GPT models are now live. Codex CLI uses the OpenAI Responses API (`/v1/responses`) and connects using the API key from this site. For available models and pricing, see the [model catalog](https://1zheai.com/model-catalog).

First, let's clarify how to configure a custom provider for Codex. The format comes from the [official Codex configuration documentation](https://developers.openai.com/codex/config-reference).

## Configuration File

Codex's configuration lives in `~/.codex/config.toml`. Custom providers can only be written in this user-level file; the `.codex/config.toml` setting `model_provider` in a project will be ignored.

```toml title="~/.codex/config.toml"
model_provider = "onezhe"
model = "gpt-6-astra"

[model_providers.onezhe]
name = "1折AI"
base_url = "https://1zheai.com/v1"
env_key = "ONEZHE_API_KEY"
wire_api = "responses"
```

The example uses `gpt-6-astra`, which can be replaced with any other GPT model ID supported by your key.

Meaning of each field:

| Field | Description |
|---|---|
| `model_provider` | Which provider to use, corresponding to the id under `[model_providers.<id>]` below. `openai`, `ollama`, `lmstudio` are reserved names and cannot be used |
| `base_url` | Must include `/v1` |
| `env_key` | Codex reads the API key from this environment variable; the name must exactly match what you export |
| `wire_api` | The official documentation states that currently only `responses` is supported; it is also the default when omitted |

Then put the API key into an environment variable:

<CodeGroup>
```bash title="macOS / Linux"
export ONEZHE_API_KEY="sk-你的Key"
```
```powershell title="Windows PowerShell"
[Environment]::SetEnvironmentVariable("ONEZHE_API_KEY", "sk-你的Key", "User")
```
</CodeGroup>

## Installing Codex

The following commands come from the official Codex documentation:

<CodeGroup>
```bash title="npm"
npm install -g @openai/codex
```
```bash title="Homebrew"
brew install --cask codex
```
```bash title="macOS / Linux 脚本"
curl -fsSL https://chatgpt.com/codex/install.sh | sh
```
```powershell title="Windows"
powershell -ExecutionPolicy ByPass -c "irm https://chatgpt.com/codex/install.ps1 | iex"
```
</CodeGroup>

## FAQ

<AccordionGroup>
<Accordion title="401？">

The variable name in `env_key` does not match what you actually exported, or you opened the terminal before setting the environment variable. Double-check the names on both sides, then reopen the terminal and try again.

</Accordion>
<Accordion title="Can I change wire_api to chat?">

No. The official Codex configuration documentation states that `wire_api` only accepts `responses`. Services that only provide a Chat Completions API need an additional protocol conversion tool to connect to Codex.

</Accordion>
<Accordion title="How do I choose a GPT model?">

Check the current models in the [model catalog](https://1zheai.com/model-catalog) and fill the model ID into `model`. After starting Codex, make a short request and verify the model and status in the [call log](/en/docs/usage-logs/).

</Accordion>
</AccordionGroup>
