ospalabs
Guide · Codex CLI

Cap Codex CLI cost per session

Updated November 2026

The Codex CLI bills whatever API key it is logged into, one Responses API call at a time, and a long session resends a growing transcript. LiteLLM's Codex tutorial shows how to attribute that traffic to a customer after the fact. Attribution tells you who spent it. It does not refuse the next call.

Codex only speaks the Responses API now. wire_api = "chat" is gone. Fuse accepts POST /v1/responses for OpenAI models, prices the call before forwarding it, and returns 402 when the ceiling would be crossed. Put the provider block in ~/.codex/config.toml. A model_providers table in a repo's config is ignored.

  1. 01

    Add a Fuse provider

    Set the base URL to Fuse and env_key to the variable that holds a Fuse key. Keep wire_api on responses. Use an OpenAI model id you have turned on. A custom chat-only provider behind Fuse will 404, because Codex will not call /chat/completions.

    ~/.codex/config.toml
    model = "gpt-4.1"
    model_provider = "fuse"
    
    [model_providers.fuse]
    name = "Fuse"
    base_url = "https://fuse.ospalabs.com/v1"
    env_key = "FUSE_API_KEY"
    wire_api = "responses"
  2. 02

    Export the key in the shell

    Codex reads FUSE_API_KEY from the environment. Leave the secret out of config.toml. One key per person or per repo keeps a local experiment from spending the production ceiling; set a daily cap on that key.

  3. 03

    Confirm the first turn in the log

    Run a one-line prompt and find the request in Fuse. The path should be the Responses API, the model the id you set, and the cost the reservation that was settled from usage. If Codex reports a 404, the base URL is not a Responses endpoint.

  4. 04

    Stop on 402

    A blown ceiling comes back as HTTP 402 with error fuse_blown. End the session. Starting it again repeats the refusal until the period resets.

Questions

Can Codex reach Claude or Gemini through Fuse?
Not on this path. Fuse serves /v1/responses for OpenAI models. Anthropic, Google, and Mistral models are chat completions only, and Codex no longer sends that.
Does this replace OpenAI's organization budget?
No. Keep the organization monthly budget as the outer wall. A Fuse key cap is the per-session stop inside it.