Tool setup

OpenAI Codex

Add the gateway as a custom model provider in Codex's config.toml.

OpenAI Codex is OpenAI's terminal coding agent. It reads model providers from a TOML config, so you add the gateway as a custom provider and point Codex at it.

What you get

  • Codex running against any model on the gateway, billed to your project's sponsor budget.
  • No ChatGPT subscription or OpenAI API key of your own.

Prerequisites

  • Your project access key and base URL from your project control panel — written here as YOUR_PROJECT_KEY and https://v1.opentokenmarket.dev.

  • A recent Codex CLI (custom model_providers support is required):

    npm i -g @openai/codex
    

    Or: curl -fsSL https://chatgpt.com/codex/install.sh | sh

Configure

Add a provider to ~/.codex/config.toml:

model = "gpt-4o"
model_provider = "opentokenmarket"
model_reasoning_effort = "medium"

[model_providers.opentokenmarket]
name = "OpenTokenMarket"
base_url = "https://v1.opentokenmarket.dev"
env_key = "OPENTOKENMARKET_API_KEY"
wire_api = "responses"
stream_idle_timeout_ms = 7200000
stream_max_retries = 5
request_max_retries = 4

Then export the key. The variable name must match env_key above:

export OPENTOKENMARKET_API_KEY="YOUR_PROJECT_KEY"

Add that line to your shell profile (~/.zshrc / ~/.bashrc) so it persists.

  • model — any name from the model catalog. gpt-4o here is just an example.
  • wire_api = "responses" uses the Responses API. If your chosen model only supports Chat Completions, set wire_api = "chat" instead.

Run

codex

Switch models for a single run:

codex --model claude-sonnet-4-6

Verify

Confirm the gateway answers before launching Codex:

curl https://v1.opentokenmarket.dev/chat/completions \
  -H "Authorization: Bearer YOUR_PROJECT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"gpt-4o","messages":[{"role":"user","content":"ping"}]}'

Troubleshooting

  • 401 / auth errors — the shell variable name doesn't match env_key, or the key is wrong. Re-copy it from your project control panel.
  • Errors mentioning /responses or an unsupported endpoint — the model doesn't speak the Responses API. Set wire_api = "chat" in the provider block.
  • Key ignored by the Codex desktop app (macOS) — the app doesn't inherit shell env. Set it at login scope: launchctl setenv OPENTOKENMARKET_API_KEY YOUR_PROJECT_KEY. A model change there needs a config edit and a new session.
  • model not found — the name isn't on this gateway. Check the model catalog.
  • budget has been exceeded — the project's funded balance is spent. Ask your sponsor to top up.

Which model names to use

model in config.toml (and --model) must match the Model name column in the model catalog exactly.