Codex Gateway
llms.txt ↗An OpenAI-compatible API powered by a ChatGPT subscription.
Overview
This gateway speaks the standard OpenAI wire format. Any library, bot, or tool that talks to OpenAI works here by changing two values — the base URL and the API key. No code changes, no SDK swap.
Authentication
Send your key as a Bearer token on every /v1 request:
Authorization: Bearer sk-cgw-YOUR_KEY
Bearer prefix is optional. A bare key works too, as
does x-api-key: sk-cgw-…. Keys are created in the
dashboard.
Quickstart
Chat completions
POST/v1/chat/completions
The standard endpoint. Supports multi-turn history, system messages, streaming, function calling, and image inputs.
| Field | Type | Notes |
|---|---|---|
model | string | See Models. Ignored if the key is pinned. |
messages | array | Required. system / user / assistant / tool. |
stream | boolean | SSE chunks terminated by data: [DONE]. |
tools | array | Function definitions — see Function calling. |
tool_choice | string/object | auto, none, required, or a named function. |
temperature | number | Passed through. |
max_tokens | number | max_completion_tokens also accepted. |
Response is the usual OpenAI shape:
{
"id": "chatcmpl-…",
"object": "chat.completion",
"model": "gpt-5.4",
"choices": [{
"index": 0,
"message": { "role": "assistant", "content": "Hello!" },
"finish_reason": "stop"
}],
"usage": { "prompt_tokens": 12, "completion_tokens": 3, "total_tokens": 15 }
}
model field in the response is the model that
actually ran. If a key is pinned, or you sent a legacy slug that was
remapped, this is how you tell.
Streaming
Set "stream": true to receive server-sent events.
Each chunk carries a delta; the stream ends with data: [DONE].
data: {"choices":[{"delta":{"content":"Hel"},"finish_reason":null}]}
data: {"choices":[{"delta":{"content":"lo"},"finish_reason":null}]}
data: {"choices":[{"delta":{},"finish_reason":"stop"}]}
data: [DONE]
Function calling
Define tools exactly as you would with OpenAI:
When the model decides to call a tool you get
finish_reason: "tool_calls" and a
tool_calls array. Run the function, then append the result as
a tool message and call again:
{ "role": "tool", "tool_call_id": "call_abc123", "content": "{\"temp\":34}" }
Simple endpoint
POST/v1/ask
For bots and scripts that do not want the chat envelope.
{ "text": "…", "model": "gpt-5.4", "usage": { "total_tokens": 42 } }
Other endpoints
| Endpoint | Purpose |
|---|---|
POST/v1/responses | OpenAI Responses-style shape. |
GET/v1/models | List available models. |
GET/health | No auth. Liveness + link state. |
Models
| Model | Best for |
|---|---|
gpt-5.5 | Highest quality, complex reasoning |
gpt-5.4 | Balanced default; strong multilingual and Arabic |
gpt-5.4-mini | Cheapest and fastest — classification, extraction, structured JSON |
gpt-5.3-codex | Code-tuned |
gpt-5.3-codex-spark | ChatGPT Pro only, research preview |
gpt-4o, gpt-4,
gpt-3.5-turbo, o1, o3 and friends are
auto-mapped to the nearest model above, so existing code runs unchanged.
model
field entirely — useful for third-party tools that hardcode a slug you
cannot edit.
Errors
Errors use the OpenAI envelope, so SDK error handling works unchanged.
| Status | Code | Meaning |
|---|---|---|
| 401 | invalid_api_key | Missing, unknown, revoked, or disabled key. |
| 405 | method_not_allowed | Wrong verb — the Allow header names the right one. |
| 429 | rate_limited | ChatGPT plan quota exhausted. Back off; re-linking will not help. |
| 503 | needs_relink | No linked ChatGPT account, or its session was revoked. Needs a human in the dashboard. |
| 504 | timeout | Upstream took too long. |
Limits
- Capacity is the ChatGPT plan's quota, shared across every key. Treat 429 as a hard backoff signal.
- Requests run with bounded concurrency — bursts queue instead of failing.
- The gateway is stateless: send full message history each call to keep context.
n > 1,logprobs, and embeddings are not supported.
For AI agents
Building with a coding model? Hand it
/llms.txt — a
plain-text spec of this whole API, written to be pasted straight into a
model's context alongside your key.
sk-cgw-… to add AI features to this project."