# Codex with AnyRouter — free models, one API key

> Run Codex through AnyRouter with anyrouter/free or any model on one sk-ar- key.


# Codex

Run [Codex](https://developers.openai.com/codex/cli) through AnyRouter with one `sk-ar-` key, request logs and no code changes. Flags, profiles and `--dry-run` are in the [Codex CLI setup](/cli/codex).

## Set it up

::::tabs

:::tab{label="AnyRouter CLI"}

```bash
curl -fsSL https://anyrouter.dev/cli.sh | bash
anyr codex
```

First run: paste an `sk-ar-` key or log in at anyrouter.dev. The config is saved to `~/.anyrouter/config.yaml` and also powers `anyr claude`. Anything after `--` goes to Codex:

```bash
anyr codex --model auto --effort xhigh -- exec
```

:::

:::tab{label="Manual setup"}

Create a key in the [dashboard](https://anyrouter.dev/dashboard/keys), then:

```bash
export OPENAI_BASE_URL="https://anyrouter.dev/api/v1"
export OPENAI_API_KEY="sk-ar-your-anyrouter-key"
```

:::

::::

Check [request logs](https://anyrouter.dev/dashboard/logs): the call appears within a second or two with model, tokens and cost.

## Model ids

| Model id | What it does |
|---|---|
| `anyrouter/free` | Best free model available now, with fallback. No credits. Needs Go ($2/mo, or free when you donate one working provider key); no daily cap. See [Free Tier](/features/free-tier). |
| `anyrouter/auto` | Top models (free and paid) with health-aware failover. Paid members use credits. |

```bash
anyr codex --model anyrouter/free
```

Own provider keys (BYOK) are billed by your provider: see [Use your own provider keys](/guides/byok-provider-keys).

## MCP tools

`anyr codex` connects the AnyRouter MCP gateway when **Auto-connect in coding agents** is on in the [dashboard](https://anyrouter.dev/dashboard/mcp). Turn it off with `--no-mcp`, `anyr mcp auto off`, or the dashboard.

## Troubleshooting

| Symptom | Fix |
|---|---|
| 401 or 403 | Key inactive, or `OPENAI_API_KEY` is not a valid `sk-ar-` key. Check [Keys](https://anyrouter.dev/dashboard/keys). |
| Model not found | Use an exact id from [Chat-Completions-compatible models](https://anyrouter.dev/models?endpoint=chat-completions). |
| `400 no_eligible_models` | Privacy or routing settings (Zero Data Retention, blocked providers) excluded every candidate. Relax them or pick a specific model. |


## Related

- [anyr codex](/docs/cli/codex.md)
- [Free Tier](/docs/features/free-tier.md)
- [Get a provider API key](/docs/guides/byok-provider-keys.md)
- [Claude Code with AnyRouter — free models, one API key](/docs/guides/claude-code.md)
- [OpenCode with AnyRouter — free models, one API key](/docs/guides/opencode.md)
- [Cline with AnyRouter — free models, one API key](/docs/guides/cline.md)
- [AnyRouter CLI](/docs/cli.md)
