# Connect Codex CLI to WanAPIs

> Point OpenAI Codex CLI's base_url at WanAPIs to use GPT-5.5 and other models. OpenAI-compatible, pay per token, with SSE keep-alive for long reasoning runs.

Web page: https://wanapi.ai/docs/codex

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.toml**

```
model = "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.

**shell**

```
export 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.

---

Generated by the WanAPIs website and kept in sync with the web page. All guides in Markdown: https://wanapi.ai/docs/index.md
