← Blog
By the apillms team · Published 2026-10-03 · Codex CLI · config.toml · API setup

Codex CLI config.toml: use a custom provider and base URL

Codex CLI reads its provider and model settings from a config.toml file. Point that file at apillms and you can run Codex against gpt-6-astra or any other model on the platform, without changing how you use the CLI day to day.

What you need first

Sign up at apillms (new accounts get 50 free credits) and open the API keys page. Your account has exactly one API key, created automatically — there's no "create key" step, only Show key and Roll key if you ever need to rotate it.

On the API keys page, click the Codex tab. It shows the same base URL and key you'll use below, already filled in, plus the one-line installer command and copy-paste code examples in Python, Node, cURL and the Anthropic SDK (for other integrations).

Fastest path: the one-line installer

If you just want Codex working, run the installer from the Codex tab or the integration guide at /integrations?app=codex:

curl -fsSL 'https://apillms.com/v1/setup-codex' | bash

This writes ~/.codex/config.toml for you with your key already filled in, so you can skip straight to the verification step below. If you want to understand what it's doing — or edit the config later, swap models, or add a second machine — walk through the manual steps below instead.

Manual config.toml walkthrough

Codex CLI's config file lives at ~/.codex/config.toml. Create the file and the .codex folder if they don't exist yet:

mkdir -p ~/.codex
touch ~/.codex/config.toml

Open it in your editor and add a provider entry pointing at apillms:

[model_providers.apillms]
name = "apillms"
base_url = "https://apillms.com/v1"
env_key = "APILLMS_API_KEY"

[profile]
model = "gpt-6-astra"
model_provider = "apillms"

The base URL is the OpenAI-compatible endpoint: https://apillms.com/v1. Codex talks to it the same way it talks to any OpenAI-compatible provider — chat completions in, tokens out. (If you ever wire up an Anthropic-SDK-based tool against apillms instead, note the Anthropic-compatible base URL is different: https://apillms.com, no /v1 suffix. For Codex CLI you only need the OpenAI-compatible one above.)

Set the key as an environment variable, matching the env_key name above, before launching Codex:

export APILLMS_API_KEY="your-api-key-here"
codex

Grab the key value from the API keys page (click Show key). Keep it out of version control — export it in your shell profile (~/.zshrc or ~/.bashrc) so it persists across terminal sessions, rather than typing it every time:

echo 'export APILLMS_API_KEY="your-api-key-here"' >> ~/.zshrc
source ~/.zshrc

If you'd rather keep secrets per-project, put the same export line in a local .env file and load it with your shell's dotenv tooling, as long as the file is in .gitignore.

Verify it's working

Start Codex and ask it something trivial, like "what model are you running on?" or a one-line code fix:

codex
> write a bash one-liner that lists files modified in the last 24 hours

If a response comes back, the config is correct. You can also check the Connect page in the console to test your key directly before touching Codex at all, and the Usage page afterward to confirm requests are landing under your account — filter by type or status, or export the raw numbers as CSV.

Troubleshooting

If Codex can't reach the API, work through these in order:

If none of that resolves it, the installer (curl -fsSL 'https://apillms.com/v1/setup-codex' | bash) will overwrite the config with a known-good version, which is a quick way to rule out a typo in your manual edits.

Switching models

Codex isn't locked to one model. Change the model line in config.toml to try others — claude-sonnet-5, claude-opus-5-5, gpt-5.5, or deepseek-v4-flash are all available on apillms, and the full list with capability filters is on the /models page. There's no need to touch the provider block, only the model name.

Different models have different costs per agent turn. For reference, one agent turn (100,000 cache-read tokens + 5,000 fresh input + 1,000 output) costs:

ModelCost per turnCost per 1,000 turns
gpt-6-astra$0.03$30.25
claude-sonnet-5$0.021$20.99
claude-opus-5-5$0.041$41.07
gpt-5.5$0.013$13.45
deepseek-v4-flash$0.006$5.88

For shorter, non-cached interactions — a quick question rather than a long agent session with repo context — the per-message cost is lower across the board. One chat message (1,000 input + 500 output tokens) with gpt-6-astra costs $0.001, or $0.719 per 1,000 messages. Prompt caching is on by default for every account (per-user cache keys), so repeated context in a Codex session — like your repo's system prompt — gets billed at the lower cache-read price automatically. No extra config needed for that part.

How the per-token prices compare

If you want to see the raw per-token rates behind those turn costs, here's gpt-6-astra and claude-sonnet-5 on apillms next to OpenRouter's listed rates for the same models (per 1M tokens):

Modelapillms inputapillms outputOpenRouter inputOpenRouter output
gpt-6-astra$1.06$5.32$10$50
claude-sonnet-5$0.274$1.37$2$10

apillms is cheaper on both models shown above. A full, live comparison across all models is on /compare, and per-pack token estimates for turning a credit pack into expected usage are on /pricing.

Why this setup makes sense

apillms is pay-as-you-go: credits never expire, and failed requests aren't billed, so a bad config or a dropped connection doesn't cost you anything while you're troubleshooting. Payment is by PayPal or card on the Billing page, and packs run from Starter ($5, 1,000 credits) up to Scale ($100, 23,000 credits), with token-per-pack tables shown there too.

If you also use other coding agents, the same account and key work across them — see the Claude Code setup guide or the VS Code Chat guide for the equivalent walkthroughs. If you're trying to decide which model to run Codex against in the first place, the Claude vs GPT vs DeepSeek vs Grok comparison covers that trade-off in more detail.

Takeaway

Add a [model_providers.apillms] block to ~/.codex/config.toml with the apillms base URL, set your key as an env var matching env_key, and point model at gpt-6-astra (or any model from /models). Verify with a trivial Codex prompt and check the Usage page for matching requests. Or skip the manual steps entirely with the one-line installer on the Codex integration guide.

Try apillms

One API key for Claude, GPT, Grok, DeepSeek and Kimi. OpenAI- and Anthropic-compatible, prompt caching included, pay-as-you-go from $5 with PayPal or card. Credits never expire.

Get an API key Compare prices

FAQ

Where do I find my apillms API key for Codex?

Go to the API keys page in the apillms console and click Show key. There's only one key per account — use Roll key if you need to replace it.

Is the one-line installer safe to use instead of editing config.toml by hand?

Yes, it writes the same config.toml entries with your key already filled in. Manual editing is only needed if you want to customize or understand the setup further.

Can I use a model other than gpt-6-astra with Codex?

Yes, change the model line in config.toml to any model id listed on /models, such as claude-sonnet-5 or deepseek-v4-flash.

What happens if a Codex request fails?

Failed requests are not billed, so a misconfigured base URL, typo in the env var name, or dropped connection won't use up your credits.