Codex CLI
Connect OpenAI's terminal coding agent Codex CLI to PleumRouter's Responses API.
Codex CLI is OpenAI's coding agent that reads and edits code and runs commands from the terminal. Codex dropped the Chat Completions path and speaks only the Responses API (/v1/responses), so your config needs wire_api = "responses". For the desktop app, see Codex Desktop.
Quick start#
Install Codex CLI
Skip this if it is already installed.
Terminalnpm i -g @openai/codex codex --versionCreate an API key
In the dashboard's API keys page, create a key that starts with
plm_and copy it. Set daily, weekly or monthly budgets on it while you are there.Connect to PleumRouter
Pick one of the three.
pleum launchLeaves `~/.codex` alone and uses a temporary config for this run only.
npm i -g pleumrouter pleum login # sign in with the browser pleum launch codex # applies the PleumRouter provider for this run onlyThe key comes from a shell variable. It is the file in your home folder, not one inside a project.
model = "gpt-6-sol" model_provider = "pleum" model_reasoning_effort = "high" [model_providers.pleum] name = "PleumRouter" base_url = "https://apirouter.pleum.ai/v1" # stops at /v1 — Codex appends /responses env_key = "PLEUM_API_KEY" wire_api = "responses" supports_websockets = false # then set the key — # macOS · Linux (add to ~/.zshrc or ~/.bashrc): # export PLEUM_API_KEY="plm_xxxxxxxxxxxxxxxx" # Windows (user-wide, then fully restart Codex): # setx PLEUM_API_KEY "plm_xxxxxxxxxxxxxxxx"Writes a dedicated `plm_` key and the provider block into `~/.codex/config.toml`, the same file the desktop app reads.
npm i -g pleumrouter pleum login pleum wire codex # writes the provider block into ~/.codex/config.tomlRun it and check
A reply to one prompt means you are connected. A 401 points at the key; a 404 points at the
/v1inbase_url.Terminalcd your-project codex
Why use PleumRouter with Codex CLI?#
- Pay only for what you use from prepaid credits. Credits are deducted separately from the tool maker's subscription.
- Set budgets and limits per key. Daily, weekly and monthly budgets, model allow-lists and team budgets help you manage what an agent spends.
- One key, many models. Pick Claude, GPT, Gemini or open models; automatic retries and fallback cover provider outages; usage shows up in the dashboard.
How it works#
Codex CLI posts OpenAI Responses API requests (POST /v1/responses) to {base_url}/responses. PleumRouter accepts them, converts function tools, input images and reasoning effort, forwards them to the provider of the model you chose, and returns Responses-format output, including streaming SSE. Auth is the variable named by env_key, or a plm_ key in the Authorization: Bearer header under http_headers.
Configuration reference#
| Setting | Notes |
|---|---|
| modelgpt-6-sol | A model ID from the PleumRouter catalog. |
| model_reasoning_effort"high" | Reasoning effort (low, medium, high, xhigh). Applies where the model supports it. |
| model_provider"pleum" | Points at the [model_providers.pleum] block below. |
| base_urlhttps://apirouter.pleum.ai/v1 | Ends at /v1. Codex appends /responses, so dropping /v1 or doubling it gives a 404. |
| wire_api"responses" | Chat Completions was removed from Codex; only Responses is used. |
| env_key"PLEUM_API_KEY" | Name of the shell variable that holds the key. For a CLI started from a shell. |
| http_headers.Authorization"Bearer plm_xxxxxxxxxxxxxxxx" | Puts the key in the file directly. This is what pleum wire codex writes. |
| supports_websocketsfalse | PleumRouter does not support the Responses WebSocket transport, so turn it off. |
Choosing models#
Put a PleumRouter catalog ID in model. Look up exact IDs in the model catalog or with GET /v1/models. Add @provider (as in gpt-6-sol@openai) to send to that provider only — this turns off automatic fallback to other providers. For reference, pleum launch codex does not pin a model unless you pass --model, so Codex follows its own model setting. pleum wire codex writes gpt-6.1-sol as model.
These steps assume OpenAI models. Other makers' models connect over the Responses format too, but tool-calling quality can vary by model.
Compatibility#
| Feature | Status | Notes |
|---|---|---|
| Streaming (SSE) | Yes | Emits response.output_item.done and response.completed events. |
| Function tool calling | Partial | Only function tools are converted; other tool types are skipped. |
| Image input | Yes | input_image is converted. The model must accept images. |
| Reasoning effort | Yes | The model_reasoning_effort value is passed on and applies where the model supports it. |
| Built-in tools (web_search etc.) | No | Not supported; they are skipped in the request. |
Server compact (/v1/responses/compact) | No | Always returns 501. Use Codex's local compact. |
| WebSocket transport | No | Keep supports_websockets = false. |
Troubleshooting#
| Symptom | Cause and fix |
|---|---|
| 401 Unauthorized | The variable named by env_key is empty, or the key in http_headers is wrong. Run echo $PLEUM_API_KEY in your shell and check it is a plm_ key. |
| 401 on Windows | Set the user-wide variable with setx, then fully quit and reopen Codex (including the desktop app). Terminals and apps that were already open do not see the new variable. |
| 404 Not Found | Check that base_url is https://apirouter.pleum.ai/v1. Most of the time /v1 is missing or doubled. |
| model not found / Unknown model | model is not in the catalog. Confirm the exact ID with GET /v1/models. |
A Model metadata … not found warning appears | The ID is not in Codex's built-in model list, so it falls back to default metadata. It still works, but values such as context length use defaults and performance can suffer. |
| The connection keeps dropping or shows reconnecting | supports_websockets = false may be missing. Add it to the provider block and run again. |
| The config is ignored | Put the provider settings in ~/.codex/config.toml in your home folder, not in a file inside the project. pleum launch passes a temporary config, so it applies to that run only and is not saved to ~/.codex/config.toml. |
| The web search tool does not work | Built-in tools such as web_search are not supported. Use an MCP server or a shell tool for web access. |
| Conversation compaction fails | Server compact returns 501. Use Codex's local compact. |
Cost & security tips#
- Set a budget on the key. A coding agent calls the model many times per task and resends long context. Daily, weekly or monthly budgets on your API key make costs easier to predict.
- Keep the key out of git. Make sure a key in your shell profile or config file never gets committed, and if you suspect a leak, revoke it in the dashboard and issue a new one.
- Check where sensitive code goes. Prompts and code are sent to the provider of the model you pick. Use Data residency and PII masking to control that.