Get your API key

Terminal coding agent · setup guide

Connect Codex CLI to AllModelAPI

OpenAI's open-source coding agent for the terminal. It edits files and runs commands in your project. You can point it at any AllModelAPI model.

About 10 minutesWindows · macOS · LinuxUses the Responses APIChecked 19 November 2026
1 · Your computer
Stays in this browser tab. It is never saved or sent anywhere. No key yet? Create one.

Pick the easy way

Easiest

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.
One paste

Do it in your terminal

Install Codex CLI (step 3 below), save your key (step 4), then paste this one command into PowerShell. It backs up your old settings and writes the complete new file.

Or edit the file yourself: open %USERPROFILE%\.codex\config.toml, delete everything inside, paste the full file, and save.

No key pasted above, so copied text contains PASTE_YOUR_ALLMODELAPI_KEY_HERE. Paste your key at the top first, or replace that text later.

Step by step, for Windows

Never used a terminal before? That's fine. Follow each step in order. Every grey “Why?” box explains what you just did.

  1. Get your AllModelAPI API key

    Sign in, open API Keys and create a key. Copy it and keep it private: anyone with the key can spend your credit. You will see it only once.

    Why? An API key is like a password for apps. It lets a tool use AI models on your account, and your usage is billed to it.

    Create your key here: https://allmodelapi.com/customer/api-keys

  2. Open a terminal

    Press the Windows key, type PowerShell and press Enter. A blue or black window opens. That is your terminal. Use PowerShell, not Command Prompt.

    Why? A terminal is a window where you type commands instead of clicking buttons. Every command on this page is pasted there.

    To paste in a terminal: Ctrl + V in PowerShell, Cmd + V on Mac, Ctrl + Shift + V on Linux. Then press Enter.

  3. Install Codex CLI

    Paste this command and press Enter. Wait until it finishes. Then close the terminal and open a new one so it can find Codex CLI.

    Why? This downloads the tool from its official website and adds it to your computer.

    Install (PowerShell)
    powershell -ExecutionPolicy ByPass -c "irm https://chatgpt.com/codex/install.ps1 | iex"
    Check it installed: this should print a version number
    codex --version

    Already installed? Skip to the next step.

  4. Save your API key on this computer

    Run the command below once. Replace PASTE_YOUR_ALLMODELAPI_KEY_HERE with your key first, or paste your key in the box at the top of this page. The check should print your key.

    Why? An environment variable is a named value your computer remembers. Codex reads your key from ALLMODELAPI_API_KEY, so the key never sits inside a config file you might share by mistake.

    Save your key (PowerShell)
    [Environment]::SetEnvironmentVariable("ALLMODELAPI_API_KEY", "PASTE_YOUR_ALLMODELAPI_KEY_HERE", "User")
    Close PowerShell, open a new one, then check
    echo $env:ALLMODELAPI_API_KEY

    The new value only appears in terminals you open after running the command.

  5. Save the Codex CLI settings file

    Paste this one command and press Enter. It creates the folder if needed, keeps a backup of any old file (.bak), and writes the complete settings file. Prefer doing it by hand? Use "Copy full config file" at the top, open the file in a text editor, select everything, paste, and save.

    Why? Codex CLI reads its settings from %USERPROFILE%\.codex\config.toml. This file tells it to send requests to AllModelAPI and which model to use.

    Write the settings file
    $file = Join-Path $HOME ".codex\config.toml"
    New-Item -ItemType Directory -Force -Path (Join-Path $HOME ".codex") | Out-Null
    if (Test-Path $file) { Copy-Item $file "$file.bak" -Force; Write-Host "Backup saved: $file.bak" }
    [System.IO.File]::WriteAllText($file, @'
    # 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"
    
    '@)
    Write-Host "Saved: $file"

    Your old file had other settings you care about? Use the agent prompt instead. It merges instead of replacing.

  6. Check that it works

    You should see a short reply such as OK. If you see an error instead, look it up in "Something went wrong?" below.

    Why? This sends one tiny request, so you know the key, the address and the model are all correct before you start a real project.

    Check the install
    codex --version
    Ask one question without opening the app
    codex exec "Reply with just: OK"
    Test your key directly (PowerShell)
    Invoke-RestMethod -Method Post -Uri "https://api.allmodelapi.com/v1/chat/completions" `
      -Headers @{ Authorization = "Bearer $env:ALLMODELAPI_API_KEY" } `
      -ContentType "application/json" `
      -Body '{"model":"deepseek-v4-pro","max_tokens":20,"messages":[{"role":"user","content":"Reply with just: OK"}]}'
  7. Start building

    Open a terminal in your project folder and type codex. If it offers to sign in with ChatGPT, skip it: your AllModelAPI key is already set.

The complete settings file

This is the whole file. Every line matters, so copy it with the button instead of selecting it by hand.

%USERPROFILE%\.codex\config.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"

Something went wrong?

wire_api = "chat" is no longer supported

Codex removed that option. Every provider block in config.toml must use wire_api = "responses". Copy the full file from this page again.

Missing environment variable ALLMODELAPI_API_KEY

Save the key again (step above), then close the terminal and open a new one.

My model setting is ignored

In TOML, model and model_provider must be at the very top, above the first line that starts with [. The file on this page already does that.

401 / invalid API key

The key is missing, mistyped or revoked. Copy it again from https://allmodelapi.com/customer/api-keys and save it again. Keys start with the same prefix you see in your dashboard.

402 / insufficient credit

Your plan credit and pay-as-you-go credit are used up for this request. Add credit or pick a coding plan in Billing, or choose a cheaper model.

400 / unknown model

Model IDs are case-sensitive and must match the AllModelAPI list exactly, for example MiniMax-M3.1-Flash, not minimax-m3.1-flash.

command not found / is not recognized

The tool is not installed, or your terminal was opened before the install finished. Close the terminal, open a new one and try again.

Still stuck? Copy the agent prompt above into any AI assistant and paste the exact error message after it, or write to support@allmodelapi.com. See all models and IDs in the model list.

Codex CLI is a product of OpenAI. AllModelAPI is an independent service and is not affiliated with or endorsed by OpenAI. The guide only shows how to point the tool at AllModelAPI.

Sources we checked on 19 November 2026. Tools change often; if a step looks different on your screen, follow the official page.