Using Nexith with Codex CLI
The new Codex only speaks the OpenAI Responses protocol (POST /v1/responses). The Nexith gateway
has this adapter: it recognizes Codex by request shape, internally translates the request into the
chat pipeline for execution, and translates the result back into Responses shape — routing, billing,
egress scrubbing, and other protocols all share one path.
Configuration#
Add to ~/.codex/config.toml:
model = "nexith-core"
model_provider = "nexith"
[model_providers.nexith]
name = "Nexith"
base_url = "https://gateway.nexith.ai/v1"
env_key = "NEXITH_API_KEY"
wire_api = "responses"Then:
export NEXITH_API_KEY="nx-你的key"
codex
base_urlmust include/v1(Codex appends/responsesafter it). This is the opposite of Anthropic clients, so don't mix them up.api.nexith.ai/v1also works.
Supported endpoints#
| Endpoint | Purpose |
|---|---|
POST /v1/responses |
Codex's main path; supports streaming and function_call |
POST /v1/chat/completions |
Used when wire_api is set to chat |
GET /v1/models |
Model list |
Tool calling (apply_patch, etc.)#
Verified points:
- Request side:
function_callitems → the assistant'stool_calls;function_call_output→ atoolrole message.call_idis preserved throughout astool_call_id, so pairs are never scrambled. - Response side: upstream
tool_calls→function_callitems inoutput, withargumentskept as strings (Codex consumes strings; no object round trip). - Streaming: argument slices are forwarded as they arrive from the upstream; after concatenation they match the upstream exactly.
Known limitation: built-in tools in Responses requests whose type is not function (such as
Codex's own local_shell, web_search) are currently dropped and not forwarded upstream. When
using Codex, prefer custom function tools.
Billing and long tasks#
- 120-second limit per request (currently); a single turn of a very long agent loop is truncated if it exceeds it — being worked on.
nexith-corerequests over 32k context are automatically escalated to a stronger upstream and billed at the escalated tier.
Troubleshooting#
upstream rejected / 400
Usually incomplete tool-call pairing in the history. The gateway performs an adjacency repair at the
entrance (inserting placeholders or dropping orphans), but the real fix is for the client to
guarantee that function_call and function_call_output come in pairs.
408 / reconnects Upstream timeout. If a particular upstream is frequently slow, the gateway fails over; if this keeps happening, report the specific task type.
401
The environment variable pointed to by env_key is not set, or the key does not start with nx-.