For AI agents, the documentation index lists all pages. Append .md to a documentation URL for Markdown, or request text/markdown.

Skip to Content
spare inference

Codex CLI

Add Spare as a model provider in Codex to run on DeepSeek V4.1 Flash, or keep your OpenAI model with the CLI's Router.

3 min readEdit this page
Codex CLIEndpoint/v1/responsesConfig~/.codex/config.toml

Codex talks to model providers over the OpenAI Responses API, which Spare serves at /v1/responses. You add Spare as a provider in ~/.codex/config.toml, then pick one of two setups:

Before you start

  • A Spare API key, exported in your shell profile:

    export SPARE_API_KEY="sk-spare-..."
  • For the Router: the CLI, signed in to your OpenAI model with an OpenAI key or a ChatGPT Plus or Pro subscription.

Provider settings must go in your user config, ~/.codex/config.toml. Codex ignores model_providers in a project's .codex/config.toml.

Run on DeepSeek V4.1 Flash

~/.codex/config.toml
model = "deepseek-v4.1-flash"
model_provider = "spare"
model_context_window = 1000000

[model_providers.spare]
name = "Spare Inference"
base_url = "https://api.spareinference.ai/v1"
env_key = "SPARE_API_KEY"
wire_api = "responses"
  • env_key names the environment variable Codex reads your key from; the key itself stays out of the file.
  • model_context_window tells Codex the model's context size, which it uses to decide when to compact history.

Fallbacks

If a provider fails, the request moves to the next provider serving DeepSeek V4.1 Flash on its own. To fall back to your OpenAI model instead of failing, chain the two models in the CLI; see Fall back to a different model.

To run a routing preset instead of a fixed model, set model = "@<name>".

Keep your OpenAI model, add the Router

Spare's API runs the model you name and doesn't route between models; the Router runs in the CLI on your machine. Set it up once, following Cost routing, with your OpenAI model as the strong route and deepseek-v4.1-flash as the economy route. Then start Codex through the CLI:

spare codex --model spare/auto

You don't need the spare provider block for this: the CLI talks to Spare and to OpenAI for you.

Switch back and forth

To keep your normal setup as the default, put the Spare settings in a profile file instead, ~/.codex/spare.config.toml, and start Codex with it when you want Spare:

codex --profile spare

Check it works

Run one prompt non-interactively:

codex exec "Reply with OK"

Then find the request on the console's Activity page, or send one directly to get a request id for settlement:

curl -si https://api.spareinference.ai/v1/responses \
  -H "Authorization: Bearer $SPARE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"deepseek-v4.1-flash","input":"Reply with OK"}' \
  | grep -i '^x-bitrouter-request-id'

Good to know

  • Spare's Responses API is stateless. previous_response_id isn't supported, so each request carries its history.
  • OpenAI-hosted tools aren't available on DeepSeek V4.1 Flash, like web search. Codex's local tools, shell commands and file edits, work as usual.
  • Reasoning effort settings are accepted and ignored by DeepSeek V4.1 Flash.

How is this guide?