TemprTempr
Docs
Guides

Codex CLI

Last updated

Codex CLI is OpenAI's own tool, and out of the box it only talks to OpenAI models. Add Tempr Gateway as a model provider in its config and Codex CLI can run Claude, Gemini, DeepSeek (anything on your gateway allowlist) with the same codex commands and workflow you already use.

How it works

Codex CLI speaks OpenAI's Responses API, and Tempr Gateway serves it at /v1/responses. OpenAI models, and your Azure OpenAI deployments, pass straight through to their own Responses API. Every other model is translated to its provider's API and back, so Codex's shell and apply_patch tools, and its sub-agents, work on Claude the same way they do on GPT.

  1. Create a virtual key

    In the Portal, create a Gateway virtual key. Keys are prefixed tvk_ and shown once at creation.

  2. Add a provider key

    Gateway is BYOK: add a key for at least one provider from the supported list.

  3. Edit the config file

    Create or edit ~/.codex/config.toml, adding Tempr Gateway as a model provider:

# Codex CLI, running on Claude instead of an OpenAI model
model = "anthropic/claude-sonnet-5"
model_provider = "tempr"

[model_providers.tempr]
name = "Tempr Gateway"
base_url = "https://api.temprhq.io/v1"
env_key = "TEMPR_API_KEY"
wire_api = "responses"

Then put your virtual key in the environment variable env_key names, and start Codex CLI as usual:

export TEMPR_API_KEY="tvk_..."
codex

The example's anthropic/claude-sonnet-5 needs an Anthropic key in the Portal; with an OpenAI key, use openai/gpt-5.3-codex, or any model from GET /v1/models. Signed in to ChatGPT? Use your plan instead.

Tell Codex about your models

Codex decides which tools to offer from its own catalog of models, and the models you use through Tempr aren't in it, not even OpenAI's codex models. For a model it doesn't know, Codex warns Model metadata for … not found, leaves out its apply_patch tool, so edits fall back to shell commands, and assumes a 272K-token context window. To get the full toolset, give Codex a catalog of your models. This command copies the details of a model Codex ships with, gpt-5.5, under each of your model ids. Change the list to the models you use and their context windows:

codex debug models --bundled | node -e '
const windows = { "anthropic/claude-sonnet-5": 200000, "openai/gpt-5.3-codex": 272000 };
let json = "";
process.stdin.on("data", d => json += d).on("end", () => {
  const base = JSON.parse(json).models.find(m => m.slug === "gpt-5.5");
  const models = Object.entries(windows).map(([slug, window]) =>
    ({ ...base, slug, display_name: slug, priority: 1, context_window: window, max_context_window: window }));
  console.log(JSON.stringify({ models }));
});' > ~/.codex/tempr-models.json

Then point config.toml at the file, by its full path:

model_catalog_json = "/home/you/.codex/tempr-models.json"
  • The catalog replaces Codex's own, so list every model you use through Tempr. Run the command again after upgrading Codex, to keep the copied instructions current.
  • The copied details include reasoning levels, so /model offers low to xhigh effort on every model. Tempr maps the level onto each provider's own reasoning settings.

Model ids: not just OpenAI's

Use the fully-qualified provider/model form: anthropic/claude-sonnet-4-5, deepseek/deepseek-chat, or any other id from GET /v1/models. OpenAI's own models work too, codex models included: an openai/… model goes straight through to OpenAI's Responses API, reasoning and all. So does an Azure OpenAI deployment: azure-openai/your-deployment-name goes to your resource's own Responses API. A bare id such as gpt-5-codex also works; the gateway resolves it against the providers you've added keys for.

What changes on other models

Codex's tools work on every model: its shell tools, the freeform apply_patch tool once Codex knows the model, and sub-agents, including the tool search Codex loads them with. A few OpenAI-only features don't carry over to other providers:

  • Hosted tools, such as web search, run only on OpenAI's side. Tempr drops them for other models rather than failing the request, and names what it dropped in the x-tempr-unsupported-tools response header.
  • Encrypted reasoning is OpenAI-specific and isn't sent to other providers. The reasoning effort is: Tempr maps it onto the provider's own reasoning settings.
  • previous_response_id isn't available on other models, because Tempr doesn't store responses. Codex sends the whole conversation on each turn, so it isn't affected.

Use your ChatGPT plan

If you pay for ChatGPT (Plus, Pro, Business, Enterprise or Edu), Codex can keep its ChatGPT sign-in and still go through Tempr, so your plan pays for OpenAI's models rather than an API key. This is the setup OpenAI's Codex docs describe as signing in with ChatGPT through a gateway. Sign in with codex login, then add a provider that sends that login to Tempr, with your virtual key in its own header:

model_provider = "tempr-chatgpt"

[model_providers.tempr-chatgpt]
name = "Tempr Gateway (ChatGPT plan)"
base_url = "https://api.temprhq.io/backend-api/codex"
requires_openai_auth = true
wire_api = "responses"
env_http_headers = { "x-tempr-key" = "TEMPR_API_KEY" }
  • Your login stays yours. Tempr relays Codex's requests to ChatGPT's own Codex backend on your login and keeps nothing of it.
  • No catalog file. The model list comes from ChatGPT, so Codex knows its models and their tools without the catalog above.
  • Your key still applies. Requests are logged, checked by your guardrails, and counted against your key's limits and model allowlist like any other. The cost shows as $0, with what the tokens would have cost at API prices beside it, and your plan's usage headers come back to Codex.
  • OpenAI models only. A ChatGPT login only ever goes to ChatGPT. For other providers' models, use the provider at the top of this page.
  • Organizations. Personal keys accept a login sent this way by default. An organization's keys accept it once an owner or admin turns it on.

OpenAI documents this setup for workspaces that run their own gateway. Its docs don't yet say whether a hosted gateway may carry Plus or Pro logins, so check OpenAI's terms for your plan before relying on it. Claude and coding plans: Your AI plans.

On a coding plan

To run Codex on a coding plan, such as the Z.AI GLM Coding Plan or Kimi Code, use one of the plan's models, named by the plan: zai-coding/glm-5.3. Tempr can get the plan's key two ways:

  • Stored in Tempr. Add the plan's key under Provider keys in the Portal, and keep Codex's settings as they are, with your virtual key.
  • Sent with each request. Read the plan's key from an environment variable with env_key, which Codex sends as the bearer token, and add your virtual key with env_http_headers: Tempr sends the plan's key only to that plan, and never stores it. An organization's keys take a key sent this way once an owner or admin turns on Plan logins.
model = "zai-coding/glm-5.3"
model_provider = "tempr"

[model_providers.tempr]
name = "Tempr Gateway"
base_url = "https://api.temprhq.io/v1"
env_key = "PLAN_KEY"
wire_api = "responses"
env_http_headers = { "x-tempr-key" = "TEMPR_API_KEY" }

Several plans are sold only for the coding tools they support, and some refuse other tools, telling them apart by the identity each tool sends. Tempr passes Codex's own along and never sends another, so check which tools each plan supports before you subscribe.

Ask Codex about your Gateway

Codex can also read your Gateway through the Gateway's own MCP server: usage and cost, request logs and one request's routing, keys, plan, and providers cooling down. Ask it "why did my last few requests fail?" or "which key spent the most this week?" without leaving the terminal. It comes with the Gateway Pro, Scale and Enterprise plans.

  1. Create a management key

    In the Portal, under Gateway → Keys → Management keys (or Organization → Org keys for an organization's Gateway). A management key reads and manages the Gateway but can't call models, so it's separate from the tvk_ virtual key Codex uses for its model. Tick what Codex may do: Read usage, Read request logs and List keys to read; Create, change and revoke keys as well if Codex may change keys.

  2. Add the server to Codex

    In ~/.codex/config.toml, beside your model provider:

[mcp_servers.tempr-gateway]
url = "https://api.temprhq.io/mcp/admin"
bearer_token_env_var = "TEMPR_MANAGEMENT_KEY"

Then put the management key in that variable, check that Codex sees the server, and ask away:

export TEMPR_MANAGEMENT_KEY="tmk_..."
codex mcp list
codex "Which of my Gateway requests failed today, and why?"
  • The key's permissions decide the tools. Without Read request logs, Codex gets the usage, plan and key tools but not the logs.
  • Changes also need the account to allow them: turn on Changes by AI agents on the Portal's MCP connectors page. Codex can then make changes that only tighten, such as creating a key that expires within 90 days or revoking one, and propose any that would loosen, such as a higher budget, for you to approve in the Portal. A new key's secret never reaches Codex: it gets a one-time Portal link for you to copy the key from.
  • Or sign in instead of a key. Leave out bearer_token_env_var and run codex mcp login tempr-gateway: Codex signs you in to Tempr in the browser. Signed in this way it reads your own Gateway, or your organization's if you're an owner or admin; to let it make changes too, tick Also let it make changes on Tempr's consent page.

What's next