Codex CLI
Current Codex CLI speaks only the OpenAI Responses wire, which Foglare serves at
/v1/responses. Define a custom provider in
config.toml and Codex runs on the shared pool.
Prerequisites
- Codex CLI installed (
codexon your PATH). No ChatGPT sign-in needed for this provider. - Optional: a Foglare API key (
sk-fog-…) from the dashboard for per-key usage stats. Codex requires theenv_keyvariable to exist either way; without a key, any placeholder works and calls run anonymously. - A model id:
auto:fastto start, or any id fromGET /v1/models.
Configuration
Add to ~/.codex/config.toml
(%USERPROFILE%\.codex\config.toml on Windows). The base URL includes
/v1; Codex appends /responses itself.
~/.codex/config.toml
model = "auto:fast"
model_provider = "foglare"
[model_providers.foglare]
name = "Foglare"
base_url = "https://api.foglare.com/v1"
env_key = "FOGLARE_API_KEY"
wire_api = "responses" | Key | Value | Why |
|---|---|---|
model | auto:fast | Default Foglare model id. |
model_provider | foglare | Matches the [model_providers.foglare] table. The ids openai, ollama and lmstudio are reserved. |
base_url | https://api.foglare.com/v1 | Versioned root; /responses is appended. |
env_key | FOGLARE_API_KEY | Env var holding your sk-fog key from the dashboard. Required for inference. |
wire_api | responses | The only value current Codex accepts. |
Set the variable to your sk-fog key from the dashboard, then launch:
Shell
export FOGLARE_API_KEY="sk-fog-YOUR_KEY"
codex
Switch models per session with a flag, or set model_reasoning_effort in
config.toml to a level the model accepts:
One session on the large tier
codex --model auto:L
Config keys verified against the official Codex configuration reference. Very old Codex releases used
wire_api = "chat" against chat/completions; that value was removed and
current Codex refuses to start with it.
Verify
Check the endpoint from your shell first. You should see named SSE events starting with
response.created and text arriving in
response.output_text.delta frames. Then run
codex and send a prompt.
curl the responses endpoint
curl -N https://api.foglare.com/v1/responses \
-H "Content-Type: application/json" \
-H "Authorization: Bearer sk-fog-YOUR_KEY" \
-d '{"model":"auto:fast","input":"Hello","stream":true}' Expected stream (trimmed)
event: response.created
data: {"type":"response.created","response":{"id":"fglr_...","status":"in_progress",...}}
event: response.output_text.delta
data: {"type":"response.output_text.delta","delta":"Hello",...}
event: response.completed
data: {"type":"response.completed","response":{"status":"completed","usage":{...},...}} List accepted model ids (trimmed response)
curl https://api.foglare.com/v1/models
{
"object": "list",
"data": [
{ "id": "deepseek-v4.1-flash", "object": "model", "created": 1763769600, "owned_by": "foglare" },
{ "id": "qwen4-max", "object": "model", "created": 1763769600, "owned_by": "foglare" },
{ "id": "auto:fast", "object": "model", "created": 1763769600, "owned_by": "foglare" }
]
} Troubleshooting
| Symptom | Fix |
|---|---|
| 404, model not found | The model id is not in the catalog. List accepted ids with GET /v1/models. Tier ids are auto:fast, auto:S, auto:M, auto:L, auto:XL; direct ids carry no suffix. |
| 404 on the endpoint path | The base URL is wrong for this tool. Check whether it expects the root (https://api.foglare.com) or the versioned root (https://api.foglare.com/v1); the configuration table above says which. |
| 503, capacity exhausted | All upstream routes are busy or rate-limited. The error message says when to retry. Retry after that window, or switch to a routing tier so the gateway picks healthy capacity. |
| Output arrives all at once, or the stream hangs | Something between you and the gateway is buffering SSE. Use curl -N, disable proxy buffering (nginx: proxy_buffering off), and read the response as a stream instead of waiting for the full body. |
| Codex refuses to start, wire_api error | Your config still says wire_api = "chat". Current Codex only accepts "responses". Use the config above. |
| Missing environment variable FOGLARE_API_KEY | Codex requires the env_key variable to be set. Export it with your sk-fog key from the dashboard; inference requires a real key. |
| 404 on /responses or /v1/v1/responses | base_url must be exactly https://api.foglare.com/v1. Without /v1 the path is wrong; with /v1/responses already appended it doubles. |
| Provider settings ignored | model_provider and model_providers only apply from the user config (~/.codex/config.toml), not from a project .codex/config.toml. |