Let an AI agent do it
Already use an AI coding agent (any one: Codex, OpenCode, Cursor, another assistant)? Copy this prompt, paste it into that agent and press Enter. It installs Codex CLI, writes the settings, saves your key and tests everything. It will ask you for your API key.
See what the prompt says
# Task: connect Codex CLI to AllModelAPI
You are a coding agent on my computer. Set up **Codex CLI** so it uses **AllModelAPI** as its model provider. Work step by step, tell me briefly what you are doing, and ask me before doing anything not listed here.
## Facts
- Service: AllModelAPI, an API gateway for DeepSeek, Qwen, GLM, Kimi and MiniMax models.
- Codex CLI talks to it with the Responses API.
- Base URL: `https://api.allmodelapi.com/v1`
- Main model: `deepseek-v4-pro` (DeepSeek V4 Pro, 1000K context). Fast background model: `deepseek-flash`.
- Model IDs are case-sensitive. Full list: https://api.allmodelapi.com/v1/models
- API key: not included. **Ask me to paste my AllModelAPI API key** (I can create one at https://allmodelapi.com/customer/api-keys).
- Human guide: https://allmodelapi.com/documentation/codex
## Steps
1. Detect my operating system (macOS, Linux or Windows) and shell.
2. Check whether Codex CLI is installed: `codex --version`. If it is not, install it with the official command:
- macOS: `curl -fsSL https://chatgpt.com/codex/install.sh | sh`
- Linux: `curl -fsSL https://chatgpt.com/codex/install.sh | sh`
- Windows (PowerShell): `powershell -ExecutionPolicy ByPass -c "irm https://chatgpt.com/codex/install.ps1 | iex"`
3. Settings file location:
- macOS / Linux: `~/.codex/config.toml`
- Windows: `%USERPROFILE%\.codex\config.toml`
4. If the file exists, copy it to `<file>.bak` first. If it contains other settings, **merge**: keep everything unrelated and only add or replace the keys shown below. If it does not exist, create it with exactly this content:
```toml
# AllModelAPI for Codex CLI. These two lines must stay above any [section].
model = "deepseek-v4-pro"
model_provider = "allmodelapi"
model_context_window = 1000000
[model_providers.allmodelapi]
name = "AllModelAPI"
base_url = "https://api.allmodelapi.com/v1"
env_key = "ALLMODELAPI_API_KEY"
wire_api = "responses"
```
5. API key: Save it as a persistent user environment variable named `ALLMODELAPI_API_KEY`: append `export ALLMODELAPI_API_KEY="<key>"` to ~/.zshrc (macOS) or ~/.bashrc (Linux), or on Windows run `[Environment]::SetEnvironmentVariable("ALLMODELAPI_API_KEY", "<key>", "User")`. Replace an existing line instead of duplicating it.
6. Verify. Run:
```
codex --version
codex exec "Reply with just: OK"
```
A short reply such as "OK" means it works. On 401 re-check the key; on 400 "unknown model" re-check the model ID; on 402 I need more credit.
7. Report: what you changed, where the backup is, and how I start Codex CLI.
## Rules
- Only touch the files named above. Do not remove other providers, models or settings.
- Never print my full API key in your replies or logs, and never put it in a git repository or project file.
- Use TOML that parses: no comments in JSON, no trailing commas.