OpenAI · CLI

Codex CLI

Codex CLI reads model providers from ~/.codex/config.toml. Add one provider block that points at your NextModel base URL, export your key, and every codex run routes through NextModel.

Quick start

  1. Get your NextModel API Key

    Create a key in the NextModel console and copy it — the next step wires it into your shell.

  2. Add a custom model provider to ~/.codex/config.toml

    wire_api = "chat" keeps Codex on the OpenAI-compatible chat completions endpoint NextModel exposes.

    Official docs

    TOML
    model = "claude-sonnet-4-5"
    model_provider = "nextmodel"
    
    [model_providers.nextmodel]
    name = "NextModel"
    base_url = "https://api.nextmodel.app/v1"
    env_key = "NEXTMODEL_API_KEY"
    wire_api = "chat"
  3. Export the key as an environment variable

    Codex reads the key from the variable named by env_key. Keep it in your shell profile, never in committed files.

    Shell
    export NEXTMODEL_API_KEY=<YOUR_API_KEY>
  4. Run a first prompt

    If the reply streams back, the provider is wired up.

    Shell
    codex "Explain what this repository does and list its entry points"

Example prompts

Prompts
Refactor src/utils/date.ts to use Temporal and update the affected tests.
Find the flakiest test in this repo, explain why it flakes, and fix the root cause.

FAQ

Why wire_api = "chat"?

NextModel serves the OpenAI-compatible chat completions endpoint, so the chat wire API matches what your provider block sends.

Where does Codex read the API key from?

From the environment variable named by env_key — NEXTMODEL_API_KEY in the example. The key itself never lands in config.toml.

Can I keep my OpenAI provider too?

Yes. model_provider selects the active provider, so you can switch between nextmodel and openai by editing one line.

Troubleshooting

Codex answers 401 Unauthorized

The variable was not set in the shell that launched Codex. Re-run the export in that same terminal, then start Codex again.

Codex ignores my provider block

Check that model_provider exactly matches the table key after model_providers (nextmodel here), and that the TOML has no duplicate table headers.

Other agents

IDEAnysphere

Cursor

The AI-first IDE, wired to your own endpoint.

Cursor supports bring-your-own-key for OpenAI-compatible endpoints. Paste your NextModel key under Settings → Models and point the OpenAI provider's base URL at NextModel so OpenAI-format requests go there.

Cursor
IDECline

Cline

Autonomous coding inside VS Code, on your own key.

Cline is a VS Code extension that plans and edits code with your approval at each step. Its OpenAI Compatible provider accepts any endpoint, so NextModel is one form away.

Cline
DesktopCherry Studio

Cherry Studio

A desktop chat client that speaks OpenAI out of the box.

Cherry Studio manages model providers as services. Add NextModel once as an OpenAI-compatible provider and it sits next to the services you already use.

Cherry Studio
SDKOpenAI

OpenAI SDK

Any OpenAI SDK, one base_url away.

The official OpenAI SDKs for Python and Node accept a custom endpoint. Set base_url to your NextModel endpoint, keep the key in the environment, and the rest of your code stays unchanged.

OpenAI SDK