Connect Codex CLI to WanAPIs
WanAPIs is an OpenAI-compatible gateway. Point a Codex CLI model provider's base_url at WanAPIs and you can use the GPT family and other models, pay per token, with automatic failover and keep-alive heartbeats on long-lived connections.
Setup steps
- 1
Sign up and create an API key
Create an account in the WanAPIs console and generate an API key starting with sk-. New accounts get free trial credit.
- 2
Add a model provider to Codex
Edit ~/.codex/config.toml, add a provider that points at WanAPIs, and set it as the default.
~/.codex/config.tomlmodel = "gpt-5.5" model_provider = "wanapis" [model_providers.wanapis] name = "WanAPIs" base_url = "https://api.wanapis.com/v1" wire_api = "responses" env_key = "OPENAI_API_KEY" - 3
Export the key and launch
Export your API key, then run codex.
shellexport OPENAI_API_KEY="sk-xxx" codex
FAQ
Will long reasoning runs (high/xhigh) get cut off?
WanAPIs sends SSE heartbeats while the model is thinking, which greatly reduces the chance of a long run being dropped mid-way. If your own network is unstable, consider lowering reasoning effort.
What should wire_api be?
Codex uses /v1/responses, so set it to responses. If your client speaks the Chat Completions protocol instead, use chat.
How is this different from an official subscription?
There is no usage cap like a monthly plan — you pay per token. The same key also works with Claude, Gemini, DeepSeek and other models, not just OpenAI's.
Connect Codex to WanAPIs now
One API key for GPT, Claude, Gemini, DeepSeek, Kimi, GLM and more — pay only for the tokens you use.