# Codex

> Configure OpenAI Codex to route Responses API calls through HeyEly.

Codex uses the OpenAI Responses API. Register HeyEly as a custom model provider in `~/.codex/config.toml` with a base URL ending in `/v1`; Codex automatically appends `/responses`.

## Set up

1. Create an API key in [Developers](https://heyely.si/keys) and export it as `HEYELY_API_KEY` in the shell where you launch Codex.
2. Add the HeyEly provider block to `~/.codex/config.toml` (or `%USERPROFILE%\.codex\config.toml` on Windows). Make sure the top-level keys stay above the first `[table]` header.

```toml
model = "openai/gpt-5.3-codex"
model_provider = "heyely"
web_search = "disabled"

[model_providers.heyely]
name = "HeyEly"
base_url = "https://heyely.si/v1"
wire_api = "responses"
env_key = "HEYELY_API_KEY"
```

3. Restart Codex so it picks up the new provider.

Because Codex's native web search runs on OpenAI's hosted tool infrastructure, the snippet above disables it.

Keep these Codex-specific rules in mind:

* Codex only honors provider declarations in your user-level config file. Placing `model_provider` or `model_providers` inside a project's `.codex/config.toml` triggers a startup warning and is ignored.
* Provider names `openai`, `ollama`, and `lmstudio` are reserved; pick any other identifier such as `heyely`.
* `wire_api = "responses"` is required and is the only supported wire format.
* `model` must match an exact catalog ID from [Models](https://heyely.si/docs/models).
* `HEYELY_API_KEY` must exist in the environment of the process launching Codex. GUI apps opened from the Dock or Start menu do not inherit shell exports automatically.

## Verify

1. Run `codex doctor` to validate your install, config file, and auth setup.
2. Launch `codex` and run `/status` to confirm the active provider and model.
3. Send `Reply with exactly: gateway-ok`.
4. Open [Credit and usage](https://heyely.si/usage). Your test request appears first under **Spend**, with **From** identifying Codex.

## Pick a model

* Every model in HeyEly's catalog can answer `POST /v1/responses`, though models vary in how reliably they handle Codex's structured message format. Start with a coding-focused model like `openai/gpt-5.3-codex`, and swap models if a session stalls.
* Override the default model for a single command using `codex -m <id>`, or switch mid-session with `/model`.
* For catalog IDs not built into Codex's registry, Codex falls back to default window sizes. Set `model_context_window` and `model_auto_compact_token_limit` at the top level of `config.toml` to specify exact limits.

## Connect the MCP server

Wire up HeyEly's [MCP server](https://heyely.si/docs/coding-tools/mcp) so Codex can inspect your credit, invoke models inside a budget you define, and mint, rotate, or revoke limited keys after signing in once.

## Troubleshooting

| You see                                        | Cause                                                            | Fix                                                         |
| ---------------------------------------------- | ---------------------------------------------------------------- | ----------------------------------------------------------- |
| `stream closed before response.completed`      | The selected model rejected Codex's request shape                | Switch to another model                                     |
| `Unknown model, fallback metadata`             | Codex does not carry built-in metadata for that catalog ID       | Harmless warning; Codex falls back to default limits        |
| Config error mentioning `wire_api`             | `wire_api` was set to the retired `"chat"` value                 | Change it to `wire_api = "responses"`                       |
| `401 missing_api_key`                          | `HEYELY_API_KEY` is missing in the shell running Codex           | Export the variable in that shell and restart Codex         |
| Provider config ignored                        | Placed inside a project file or placed under a `[table]` section | Move it to `~/.codex/config.toml` with top-level keys first |
| `400` citing `store` or `previous_response_id` | HeyEly's Responses route is stateless                            | Keep `store` disabled and pass full conversation state      |
| `402 insufficient_credit`                      | No credit remaining on the account                               | [Add credit](https://heyely.si/credit?step=add)                              |
