Codex CLI

Route the OpenAI Codex CLI through sference with a custom provider in ~/.codex/config.toml.

Codex CLI

The Codex CLI reads providers from ~/.codex/config.toml. Add sference as a custom provider and select it as the active model provider.

Configure

Add to ~/.codex/config.toml:

model = "zai-org/GLM-5.3"
model_provider = "sference"

[model_providers.sference]
name = "Sference"
base_url = "https://api.sference.com/v1"
env_key = "SFERENCE_API_KEY"
wire_api = "chat"

Then export the key and run Codex:

export SFERENCE_API_KEY="sk_..."
codex

env_key names the environment variable Codex reads for the bearer token, so the key never lives in the config file.

`wire_api`: chat or responses

wire_api = "chat" uses /v1/chat/completions; wire_api = "responses" uses /v1/responses. sference serves both. Use responses if your Codex version supports it — it is the surface Codex is built around and it unlocks background steps.

Choosing a model

model = "zai-org/GLM-5.3"          # general coding turns
# model = "zai-org/GLM-5.3-Flash"  # fast edits, 0.20 / 0.60 per 1M
# model = "moonshotai/Kimi-K3"     # hard planning, 3.00 / 15.00 per 1M

Live ids and rates: GET https://api.sference.com/v1/models.

Switching providers

Keep your existing OpenAI configuration and switch by editing one line:

model_provider = "sference"   # or "openai"

Both providers stay configured, so you can move between them per session.

Cost control

  • Prefix caching. Codex resends the system prompt and tool definitions every turn. Keep them stable and first so they bill at the cached rate. See Prompt caching.
  • max_output_tokens on reasoning models covers hidden reasoning, so cap it to avoid burning budget before the agent acts.
  • Per-engineer attribution. One key per engineer shows up separately in GET /control/v1/usage/by-key. See Usage & analytics.

It is a compatibility layer

Open models plan differently and call tools less reliably than frontier closed models on long repo work. Validate on your own repository before committing a workflow. See SferenceCode for what to expect.