Set up Codex CLI with InferSpeed: pay-per-token API
Add an inferspeed provider to ~/.codex/config.toml, put your key in the INFERSPEED_API_KEY environment variable, then run codex. When your subscription allowance runs out, this lets you keep going and pay per token.
Last checked: 2026-10-14 (the date the site verified this config) · Codex CLI 0.162.1
One-command setup
export INFERSPEED_API_KEY="sk-****" # create one at https://inferspeed.ai/keys
curl -fsSL https://inferspeed.ai/setup.sh | sh -s -- codex --model glm-5.3 --dry-run # see what it would change
curl -fsSL https://inferspeed.ai/setup.sh | sh -s -- codex --model glm-5.3
The script changes only ~/.codex/config.toml, backs it up first and shows the diff. If you already have a config, it adds an inferspeed profile: start it with codex --profile inferspeed, and your existing settings stay as they are.
Manual setup
model = "glm-5.3"
model_provider = "inferspeed"
[model_providers.inferspeed]
name = "InferSpeed"
base_url = "https://api.inferspeed.ai/v1"
wire_api = "responses"
env_key = "INFERSPEED_API_KEY"
[tools]
web_search = false # the gateway does not run hosted tools
wire_api = "responses": Codex CLI uses the OpenAI Responses API (POST /v1/responses).- Keep the key in an environment variable, never in project files. Anyone with the key can spend your balance.
- One key calls every live model. To use
kimi-k3, setmodeltokimi-k3; the same key works.
Check that it works
codex exec "print the word ok" < /dev/null
Usage and balance: call GET https://api.inferspeed.ai/v1/usage with your key. It returns today's and total tokens and the amount billed (actual_cost).
Common errors
| Error | Cause | Fix |
|---|---|---|
Warning that there is no metadata for glm-5.3 | Codex does not know this model name | Ignore it; Codex still works |
codex exec never returns | When stdin is not a terminal, it waits for more input | Add < /dev/null to the command |
403 INSUFFICIENT_BALANCE | The balance is used up | Top up, then retry; retrying alone will not work |
Without model = ... Codex asks for its default gpt-* model; that name is routed to glm-5.3, and the response's model field names the model that served it.
Prices (USD per 1M tokens)
| Model | Input | Output | Cache read | Official price (input / output) |
|---|---|---|---|---|
| glm-5.3 | $0.84 | $2.64 | $0.156 | $1.40 / $4.40 |
| kimi-k3 | $1.80 | $9.00 | $0.18 | $3.00 / $15.00 |
All models and live prices: https://inferspeed.ai/model-plaza
FAQ
Will my existing Codex config be changed?
No. With an existing config.toml, the setup script only adds an inferspeed provider and profile and leaves everything else alone; starting Codex without --profile inferspeed uses your original config.
What are the default limits?
30 requests per minute and 5 concurrent requests per account.
How do I check that billing is right?
Call GET https://api.inferspeed.ai/v1/usage with the same key to see tokens and the amount billed. How we check billing (billed amount = billed tokens × published price) and a script to reproduce it: https://inferspeed.ai/benchmarks.md