Skip to content

Connect Codex CLI / App

Overview

OpenAI Codex is OpenAI's AI coding assistant, available in two flavors:

  • Codex CLI (@openai/codex): a terminal client that picks up custom backends via the OPENAI_BASE_URL environment variable or a config file.
  • Codex App: a desktop GUI client that only honors custom backends declared in ~/.codex/config.toml under model_providers.

Starting with Codex v0.92, Codex defaults to OpenAI's Responses API (POST /v1/responses); from v0.134 the legacy Chat Completions fallback (wire_api = "chat") was fully removed. Wuliang Open AI ships a complete Responses API adapter, so it works as a drop-in Codex backend.

Prerequisites

  • Codex CLI: npm install -g @openai/codex
  • Codex App: run codex app in your terminal — it will walk you through the desktop installer
  • An API Key created on the Wuliang Open AI platform (create one)

Configuration Steps

⚠️ The Codex App does NOT read OPENAI_BASE_URL. You must declare model_providers in ~/.codex/config.toml. The CLI still honors env vars, but using the config file keeps both clients aligned.

Edit ~/.codex/config.toml (create if missing), replacing your-api-key with your API Key:

toml
model = "gpt-5.5"
model_provider = "wuliang"

[model_providers.wuliang]
name = "Wuliang Open AI"
base_url = "https://open.dieyuyun.com/v1"
env_key = "OPENAI_API_KEY"

Then export the API Key in your shell config (~/.zshrc / ~/.bashrc) so Codex can read it:

bash
export OPENAI_API_KEY="your-api-key"

Reload with source ~/.zshrc (or restart your terminal).

Option B — Environment variables (Codex CLI only)

Codex CLI picks up OPENAI_BASE_URL and OPENAI_API_KEY from the environment. The Codex App ignores these variables.

macOS / Linux

Add the following to ~/.zshrc or ~/.bashrc, replacing your-api-key with your API Key:

bash
export OPENAI_API_KEY="your-api-key"
export OPENAI_BASE_URL="https://open.dieyuyun.com/v1"

Then reload the config:

bash
source ~/.zshrc   # or source ~/.bashrc

Windows

Run in Command Prompt or PowerShell:

cmd
setx OPENAI_API_KEY "your-api-key"
setx OPENAI_BASE_URL "https://open.dieyuyun.com/v1"

Close and reopen your terminal for the variables to take effect.

Launch Codex

Terminal CLI

bash
codex

Desktop App

bash
codex app

or launch the Codex icon from your application list. After startup, deepseek-v4-flash should appear in the model picker — type hi to verify connectivity.

Codex CLI launched successfully

API Endpoint Reference

Wuliang Open AI supports both OpenAI protocols:

ProtocolPathNotes
Responses APIPOST /v1/responsesDefault for Codex CLI / App; recommended for new clients
Chat CompletionsPOST /v1/chat/completionsLegacy protocol; compatible with most OpenAI clients (ChatBox, NextChat, etc.)
FieldValue
Base URLhttps://open.dieyuyun.com/v1
Auth HeaderAuthorization: Bearer your-api-key
FormatJSON

Responses API example:

bash
curl --request POST 'https://open.dieyuyun.com/v1/responses' \
  --header 'Authorization: Bearer your-api-key' \
  --header 'Content-Type: application/json' \
  --data '{
    "model": "gpt-5.5",
    "input": "Introduce yourself.",
    "instructions": "You are a helpful assistant.",
    "temperature": 0.7,
    "max_output_tokens": 1024
  }'

Chat Completions example (legacy):

bash
curl --request POST 'https://open.dieyuyun.com/v1/chat/completions' \
  --header 'Authorization: Bearer your-api-key' \
  --header 'Content-Type: application/json' \
  --data '{
    "model": "gpt-5.5",
    "messages": [
      {"role": "system", "content": "You are a helpful assistant."},
      {"role": "user", "content": "Introduce yourself."}
    ],
    "temperature": 0.7,
    "max_tokens": 1024
  }'

Troubleshooting

Codex App returns Incorrect API key or requests still hit api.openai.com

Cause: The Codex App ignores OPENAI_BASE_URL, so it keeps talking to the official OpenAI endpoint.

Fix: Configure ~/.codex/config.toml with a [model_providers.wuliang] block that explicitly sets base_url (see Option A).

Codex CLI returns 404 /v1/responses not found

Cause: Your Codex CLI is recent enough to default to the Responses API, but the target backend doesn't implement it.

Fix: Upgrade the Wuliang gateway (already supported), or pin an older Codex CLI and set wire_api = "chat" (only honored before v0.92; removed in v0.134).

Model not allowed

Grant the gpt-5.5 model access to your current API Key in the Wuliang console. See Manage API Keys.

Notes

  • Config file first: ~/.codex/config.toml is the unified configuration surface for both Codex CLI and Codex App — prefer it as the default onboarding path.
  • API Key Security: Do not commit config.toml or shell rc files containing real API Keys to version control.
  • Model Override: Pass --model gpt-5.5 on the CLI to temporarily override the configured model.