# OpenAI Codex CLI Custom Provider: Responses Config Guide

> Configure OpenAI Codex CLI with a custom model_providers entry in config.toml, choose wire_api responses or chat, keep env_key off disk, and test patch loops.

_Published 2026-10-03 · Updated 2026-10-03 · [KeepRouter Editorial](https://keeprouter.com/editorial-policy#editorial-team) · 6 minute read_

![Protocol decision matrix for Responses API and Chat Completions integrations](https://keeprouter.com/editorial/blog/responses-api-vs-chat-completions.png)

_Validate the request contract and the application outcome when moving an integration. Conceptual illustration._

Configure OpenAI Codex CLI to use KeepRouter by defining a named entry under `model_providers` in `~/.codex/config.toml`, setting `base_url = "https://keeprouter.com/v1"`, referencing your credential by variable name with `env_key`, and selecting the `wire_api` protocol required by your chosen catalog model. Always match `wire_api` to the model's documented tool contract before starting a multi-step repository edit.

Codex CLI is designed around terminal patch generation, file inspection and local test execution. That makes protocol selection far more visible than in a plain chat box: if the wire format does not carry structured function calls and reasoning items properly, the agent fails on its first file read.

## Define a clean custom provider in config.toml

The official [OpenAI Codex CLI repository](https://github.com/openai/codex) documents `config.toml` provider blocks, `env_key` credential lookup and `wire_api` selection. Keep literal secrets out of `config.toml` so dotfiles remain safe to back up or review.

For Responses-first coding models such as [gpt-6.1-sol](/models/gpt-6.1-sol), whose [official model documentation](https://developers.openai.com/api/docs/models/gpt-6.1-sol) requires `POST /v1/responses` for function calling, set `wire_api = "responses"`:

```toml
model = "gpt-6.1-sol"
model_provider = "keeprouter"

[model_providers.keeprouter]
name = "KeepRouter"
base_url = "https://keeprouter.com/v1"
env_key = "KEEPROUTER_API_KEY"
wire_api = "responses"
```

Export `KEEPROUTER_API_KEY` in your shell session before launching `codex`:

```bash
export KEEPROUTER_API_KEY="kr_live_replace_with_your_scoped_key"
codex "Read package.json and list the test script name without editing any files."
```

Note that `env_key` takes the **environment variable name** (`"KEEPROUTER_API_KEY"`), never the secret value itself. If Codex reports a missing key on startup, verify `printenv KEEPROUTER_API_KEY` in the exact terminal pane where `codex` runs.

## Choose wire_api by model contract, not guesswork

| Catalog model type | Recommended wire_api | Why the distinction matters |
| --- | --- | --- |
| Responses-native coding models (for example [gpt-6.1-sol](/models/gpt-6.1-sol)) | `"responses"` | Preserves Responses tool calls, `function_call_output` items and reasoning state |
| Chat Completions models without a Responses route | `"chat"` | Sends `POST /v1/chat/completions` instead of failing on an unsupported Responses route |
| Anthropic Messages-only models | Use Claude Code on `/v1/messages` | Do not force Messages-only models through an OpenAI wire format |

Check each candidate's preferred endpoint in the [live model catalog](/models) and review the [Responses versus Chat Completions guide](/blog/responses-api-vs-chat-completions) when switching between model families. Keep separate `[model_providers.*]` blocks or profile overrides if you test both `"responses"` and `"chat"` models so you never leave a mismatched protocol active.

## Verify read, patch and approval boundaries in order

Keep Codex CLI's approval prompts enabled and work inside a clean Git repository with no production secrets in the directory tree. Run three progressive checks rather than starting with a broad refactor:

1. **Read-only inspection.** Ask Codex to read one small source file and report an exact constant or function signature. Confirm in your terminal that a real tool call executed rather than a guessed answer.
2. **Scoped single-file patch.** Ask for one deterministic edge-case fix and its unit test on a disposable branch. Inspect `git diff` before approving any shell command.
3. **Targeted test execution.** Allow Codex to run only the single test file covering that change, then confirm the exit code yourself.

| Failure mode | First boundary to inspect | Avoid |
| --- | --- | --- |
| Immediate missing-key error | `env_key` contains literal `sk-...` instead of env var name | Writing secrets directly into `config.toml` |
| HTTP 404 on first turn | `base_url` has duplicated `/v1` or operation suffix | Changing prompts before fixing `base_url` |
| Plain text works, first tool call fails | `wire_api` mismatch with the selected catalog model | Disabling sandbox approvals to bypass API errors |
| Incomplete turn on reasoning models | Output token cap exhausted by reasoning + patch | Retrying identical tight limits in a loop |

## Reconcile full-loop spend across terminal sessions

Terminal coding agents resend repository context, tool outputs and test stderr across turns within a task. A five-step fix that compiles and passes on the first try can cost less in total than a cheaper per-token model that loops through four failed patches.

Track billed input, cached input and output tokens in the KeepRouter usage log per task, estimate candidate budgets with the [API cost calculator](/tools/api-cost-calculator), and compare editor-based workflows in the [Cursor custom base URL guide](/blog/cursor-custom-openai-base-url) or [quickstart](/docs/quickstart) before standardizing a team configuration.

## Frequently asked questions

### Should env_key in config.toml contain my literal API key?

No. Set env_key to the name of an environment variable such as KEEPROUTER_API_KEY, and export the secret value in your shell environment.

### When should wire_api be set to responses versus chat?

Use responses for models such as gpt-6.1-sol whose tool contract runs on POST /v1/responses, and use chat for routes documented on POST /v1/chat/completions.

### What is a safe first verification command in Codex CLI?

Run a read-only prompt in a disposable Git repository that asks Codex to inspect one file and report a known line before testing file edits or shell commands.

## Sources reviewed

_Article last reviewed 2026-10-03_

1. [OpenAI Codex CLI repository and configuration](https://github.com/openai/codex)
2. [OpenAI · GPT-6.1 Sol](https://developers.openai.com/api/docs/models/gpt-6.1-sol)

## Related guides

- [gpt 6.1 sol](https://keeprouter.com/models/gpt-6.1-sol.md)
- [Cursor Custom OpenAI Base URL: Setup, Models and Debug](https://keeprouter.com/blog/cursor-custom-openai-base-url.md)
- [Aider with an OpenAI-Compatible API: Setup and Edit Tests](https://keeprouter.com/blog/aider-openai-compatible-api.md)
- [claude code](https://keeprouter.com/use-cases/claude-code.md)

## Check this model's price and API

See the current customer rate, supported endpoint and setup example for the model discussed here.

[View model and pricing](https://keeprouter.com/models/gpt-6.1-sol)

[Create a key to test the free model](https://keeprouter.com/login?returnTo=%2Fconsole%2Fkeys%3Fmodel%3Dfree)

The free test uses the free model. Other paid models require sufficient prepaid credit.

[All posts](https://keeprouter.com/blog.md) · [Models & pricing](https://keeprouter.com/models.md)
