Codex CLI

Point OpenAI's terminal coding agent Codex CLI at AI Nexus and call models through the Responses API.

Codex CLI is OpenAI's coding agent that runs in your local terminal. It edits code, produces patches and runs commands. It speaks the OpenAI-compatible (Responses API) format, i.e. POST /v1/responses, so with AI Nexus you can only use models that support the Responses API.

Pick a model that supports the Responses API

Not every model supports /v1/responses. Pick a model on the model square that supports /v1/responses and use its model ID; models without that endpoint can't be used in Codex CLI. For a terminal tool that uses the Claude-native Messages endpoint, see Claude Code. The Codex CLI client itself has not been tested hands-on against AI Nexus; the settings follow its official documentation.

Install

Install Node.js (LTS recommended), then install globally:

npm install -g @openai/codex
codex --version

On Windows, use it inside WSL2 (wsl --install, reboot, then install Node.js and Codex CLI inside WSL).

Configure

Put your key in an environment variable first:

export MYAIEXP_API_KEY="sk-xxxxxxxx"

To make it permanent, add that line to ~/.zshrc or ~/.bashrc.

Then edit ~/.codex/config.toml (create it if it doesn't exist):

model = "your-model-id"  # replace with a model ID from the model square that supports /v1/responses
model_provider = "myaiexp"

[model_providers.myaiexp]
name = "myaiexp"
base_url = "https://ai.myaiexp.com/v1"
env_key = "MYAIEXP_API_KEY"
wire_api = "responses"

Notes:

  • base_url includes /v1; Codex appends /responses itself.
  • wire_api = "responses" selects the Responses format.
  • env_key is the name of the environment variable holding your key; it must match the variable you exported above.
  • Set model to a model ID from the model square that supports /v1/responses. The name must exactly match GET /v1/models; see the model square for the full list.

Use

cd /path/to/your/project
codex

Once started, type /model to view or switch models (switch only to models that support /v1/responses). You can also pick one at launch:

codex --model your-model-id

Depending on the approval mode you choose, Codex asks for confirmation before editing files or running commands.

With a custom model_provider, every request goes to AI Nexus and is charged to your AI Nexus balance at AI Nexus prices. See the model square.

Troubleshooting

  • An error saying the model is unavailable or doesn't support this endpoint: the model doesn't support /v1/responses; pick one that does on the model square.
  • 401: check that the variable named in env_key is set in the current terminal and that the key is correct.

See Errors for more troubleshooting.

This service is provided for learning and research purposes only. Please follow each model provider's usage policies.

On this page