# OpenAI Codex

> One table in config.toml, shared by the Codex CLI, the IDE extension and the app.

Source: https://www.nexus402.dev/docs/developers/mcp-clients/codex/

You are connecting Codex to the Nexus402 gateway, one remote MCP server reached over streamable HTTP. You install nothing and host nothing. The Codex CLI, its IDE extension and the desktop app read the same configuration, so one entry serves all three. If you want to build and sell a tool instead, see [Build a Server](https://www.nexus402.dev/docs/creators/build-a-server/).

## Prerequisites

- Codex installed and signed in.
- A Nexus402 account with the developer role, and a funded wallet or trial credit. See [Funding and spend](https://www.nexus402.dev/docs/developers/wallet/).
- An API key (`nx_dev_…`, **shown once**) with its own 24-hour spend cap. See [Keys, caps and rotation](https://www.nexus402.dev/docs/developers/keys/).

## Configure the connection

Add a server table to `~/.codex/config.toml`. `env_http_headers` maps a header to the *name* of an environment variable, so the key never sits in the file:

**~/.codex/config.toml**

```toml
[mcp_servers.nexus402]
url = "https://api.nexus402.dev/v1/mcp"
env_http_headers = { "X-Nexus-Api-Key" = "NEXUS402_API_KEY" }
# A creator's tool may run for up to two minutes through the gateway;
# Codex's own default per-tool limit is 60 seconds.
tool_timeout_sec = 130
```

**Set the key before starting Codex**

```bash
export NEXUS402_API_KEY="nx_dev_..."
```

- **Edit the file rather than using `codex mcp add`.** Its `--url` form has a flag for a bearer token but none for a custom header, and the gateway's key is a custom header.
- **Do not use `bearer_token_env_var`.** It sends the key as `Authorization: Bearer`, and the gateway refuses an `nx_dev_` key there with `400 Authorization_Rejected`, because `Authorization` is passed through to creators.
- **If the variable is unset or empty, Codex silently sends no header.** The gateway then answers 401, which Codex reports as a login problem (below).
- `http_headers = { "X-Nexus-Api-Key" = "nx_dev_..." }` also works, with the key in the file. Keep that file private.
- A project `.codex/config.toml` is read only in a project you have marked trusted.

## Verify the connection

**Check it**

```bash
codex mcp list            # nexus402 should be listed and enabled
codex mcp get nexus402    # its URL and settings
```

In the Codex TUI or the app, `/mcp` shows each server and its tools. To rule Codex out, ask the gateway directly; `tools/list` is never billed:

**Check the key without Codex**

```bash
curl -s https://api.nexus402.dev/v1/mcp \
  -H "X-Nexus-Api-Key: $NEXUS402_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc":"2.0","id":1,"method":"tools/list"}'
```

## Use the tools

Ask Codex for what you need, or name the tool. Codex names each tool `mcp__nexus402__…` and replaces every character other than letters, digits and `_` with `_` — hyphens included — so `acme/weather/forecast` appears as `mcp__nexus402__acme_weather_forecast`. The call still reaches the original name, and the gateway accepts the tool's listed name, `acme_weather_forecast`, as well. Two names that clean to the same text get a short hash suffix to tell them apart.

- Each call is billed once at the tool's fixed price to the wallet behind the key; a tool with free calls costs nothing until they run out.
- `enabled_tools` and `disabled_tools` in the server table narrow what Codex offers the model, by the gateway's tool name. For a limit the gateway enforces, scope the key instead.
- `enabled = false` switches the server off without deleting it.

## Common errors

| What you see | Likely cause | Fix |
| --- | --- | --- |
| "The nexus402 MCP server is not logged in. Run `codex mcp login nexus402`." | The gateway answered 401. It does not use OAuth, so `codex mcp login` will not help: the key is missing, wrong, revoked or expired, or the variable was not set | Run the curl check. Export `NEXUS402_API_KEY` in the shell Codex starts from |
| "timed out after N seconds" | The connection did not finish within `startup_timeout_sec` (10 s by default) | Check the network path to `api.nexus402.dev`; raise `startup_timeout_sec` if it is only slow |
| A tool call times out after 60 seconds | Codex's default `tool_timeout_sec` is shorter than the gateway's two minutes | Set `tool_timeout_sec` as in the example |
| `Authorization_Rejected` (400) | The key was sent as a bearer token | Use `env_http_headers`, not `bearer_token_env_var` |
| `Budget_Exhausted` (402) | The wallet cannot cover the call, or the key's 24-hour cap would be exceeded | Add funds or raise the cap. Nothing was charged |
| `Upstream_Unavailable` (502) | The creator's endpoint failed or timed out | Retry later. You were not charged |

> **If the server is ready but the model sees no tools**
>
> Codex has open reports of a streamable HTTP server that connects and lists tools while the agent is offered none. If `/mcp` lists the gateway's tools, the gateway side is working; update Codex and restart it.
