📖 查看中文版 →
Prerequisites #
- Codex CLI installed —
npm install -g @openai/codex - A WoAiToken account with credits — new.woaitoken.com
- Your NewAPI API key (get it in Step 1)
Step 1 — Get Your API Key #
1. Open the console
Visit new.woaitoken.com/console and sign in.
2. Create a token
Go to 令牌 (Tokens) → Add Token. Give it a name (e.g. "Codex"), set no expiration, then click Submit.
3. Copy the key
Copy the generated key — it starts with sk-. Save it immediately; it is only shown once.
Step 2 — Configure Codex CLI #
NewAPI provides a fully OpenAI-compatible endpoint at https://new.woaitoken.com/v1.
Method A — Environment variables (Recommended) #
macOS / Linux — add to ~/.zshrc or ~/.bashrc:
export OPENAI_API_KEY="sk-your-key-here"
export OPENAI_BASE_URL="https://new.woaitoken.com/v1"
Reload:
source ~/.zshrc
Windows PowerShell:
[Environment]::SetEnvironmentVariable("OPENAI_API_KEY","sk-your-key-here","User")
[Environment]::SetEnvironmentVariable("OPENAI_BASE_URL","https://new.woaitoken.com/v1","User")
Open a new terminal window after running.
Method B — Config file #
Create or edit ~/.codex/config.toml:
model = "claude-sonnet-4-5"
provider = "openai"
[providers.openai]
base_url = "https://new.woaitoken.com/v1"
Set your API key via environment variable:
export OPENAI_API_KEY="sk-your-key-here"
Method C — One-time session (Testing only) #
OPENAI_API_KEY="sk-your-key-here" \
OPENAI_BASE_URL="https://new.woaitoken.com/v1" \
codex
Step 3 — Verify #
codex "print hello world in python"
A response confirms the connection is working.
Troubleshooting #
401 Unauthorized Check your API key is complete with no extra spaces.
Model not found Check available models at new.woaitoken.com/console → Models.
Connection refused Confirm OPENAI_BASE_URL is https://new.woaitoken.com/v1 — the /v1 suffix is required.
429 Too Many Requests Your credits are used up. Top up at woaitoken.com.