# Codex Gateway — OpenAI-compatible LLM API An OpenAI-compatible HTTP API. It is backed by a ChatGPT subscription (the OpenAI Codex ChatGPT-account backend), not a paid OpenAI API key, but callers do not need to care: it speaks the standard OpenAI wire format. ## Base URL https://codex.baselembaby.cloud/v1 ## Authentication Every /v1 request needs an API key issued by this gateway. Keys look like `sk-cgw-...`. Authorization: Bearer sk-cgw-YOUR_KEY The `Bearer ` prefix is optional — a bare key in the Authorization header is also accepted. `x-api-key: sk-cgw-...` works too. ## Using it with the official OpenAI SDKs This is a drop-in replacement. Change only base_url and api_key. Python: from openai import OpenAI client = OpenAI(base_url="https://codex.baselembaby.cloud/v1", api_key="sk-cgw-YOUR_KEY") r = client.chat.completions.create( model="gpt-5.4", messages=[{"role": "user", "content": "Hello"}], ) print(r.choices[0].message.content) Node / TypeScript: import OpenAI from 'openai' const client = new OpenAI({ baseURL: 'https://codex.baselembaby.cloud/v1', apiKey: 'sk-cgw-YOUR_KEY', }) const r = await client.chat.completions.create({ model: 'gpt-5.4', messages: [{ role: 'user', content: 'Hello' }], }) console.log(r.choices[0].message.content) LangChain (Python): from langchain_openai import ChatOpenAI llm = ChatOpenAI( base_url="https://codex.baselembaby.cloud/v1", api_key="sk-cgw-YOUR_KEY", model="gpt-5.4", ) n8n / Flowise / LibreChat / any "OpenAI-compatible" field: Base URL: https://codex.baselembaby.cloud/v1 API key: sk-cgw-YOUR_KEY ## Endpoints POST https://codex.baselembaby.cloud/v1/chat/completions Standard OpenAI Chat Completions. Supports streaming (`"stream": true`, served as SSE with `data: [DONE]` termination), `tools` / function calling, `tool_choice`, multi-turn history, system messages, and image parts (`image_url`). POST https://codex.baselembaby.cloud/v1/responses OpenAI Responses-style shape. Returns a completed response object with `output`, `output_text` and `usage`. Non-streaming. POST https://codex.baselembaby.cloud/v1/ask Convenience endpoint for simple bots — no chat envelope. Request: {"prompt": "...", "system": "optional", "model": "optional"} Response: {"text": "...", "model": "...", "usage": {...}} GET https://codex.baselembaby.cloud/v1/models Lists available model slugs. GET https://codex.baselembaby.cloud/health No auth. Returns {"ok":true,...} plus whether a ChatGPT account is currently linked. ## Models gpt-5.5 gpt-5.4 gpt-5.4-mini gpt-5.3-codex gpt-5.3-codex-spark Guidance: gpt-5.5 highest quality, complex reasoning gpt-5.4 balanced default, good multilingual/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 Legacy OpenAI slugs (gpt-4o, gpt-4, gpt-3.5-turbo, gpt-5, o1, o3, ...) are accepted and automatically mapped to the nearest slug above, so existing code does not need editing. The response's `model` field always reports the slug actually used. IMPORTANT: an API key may be pinned to a specific model by the gateway administrator. A pinned key ignores the `model` field in the request body and always uses its pinned model. Check the `model` field in the response to see what actually ran. ## Examples Basic: curl https://codex.baselembaby.cloud/v1/chat/completions \ -H "Authorization: Bearer sk-cgw-YOUR_KEY" \ -H "Content-Type: application/json" \ -d '{"model":"gpt-5.4","messages":[{"role":"user","content":"Hello"}]}' Streaming: curl -N https://codex.baselembaby.cloud/v1/chat/completions \ -H "Authorization: Bearer sk-cgw-YOUR_KEY" \ -H "Content-Type: application/json" \ -d '{"model":"gpt-5.4","stream":true, "messages":[{"role":"user","content":"Write a haiku"}]}' Function calling: curl https://codex.baselembaby.cloud/v1/chat/completions \ -H "Authorization: Bearer sk-cgw-YOUR_KEY" \ -H "Content-Type: application/json" \ -d '{ "model":"gpt-5.4", "messages":[{"role":"user","content":"Weather in Cairo?"}], "tools":[{"type":"function","function":{ "name":"get_weather", "description":"Get current weather for a city", "parameters":{"type":"object", "properties":{"city":{"type":"string"}}, "required":["city"]}}}] }' Returns choices[0].message.tool_calls with finish_reason "tool_calls". Send the result back as a {"role":"tool","tool_call_id":"...", "content":"..."} message to continue. Simple endpoint: curl https://codex.baselembaby.cloud/v1/ask \ -H "Authorization: Bearer sk-cgw-YOUR_KEY" \ -H "Content-Type: application/json" \ -d '{"prompt":"Summarise this in one line: ...","system":"Be terse."}' ## Errors Errors use the OpenAI envelope, so SDK error handling works unchanged: {"error":{"message":"...","type":"...","code":"...","param":null}} 401 invalid_api_key Missing, unknown, revoked or disabled key. 400 bad_model Model not supported (admin endpoints only). 405 method_not_allowed Wrong HTTP verb; the Allow header lists the right one. 429 rate_limited The underlying ChatGPT plan quota is exhausted. Back off and retry later. Re-linking does NOT help. 503 needs_relink No ChatGPT account is linked, or its session was revoked. A human must re-link it in the dashboard. 504 timeout Upstream took too long. ## Notes and limits - Capacity is the ChatGPT plan's message quota, shared by every key on this gateway. Treat 429 as a hard backoff signal. - Requests are processed with limited concurrency; bursts queue rather than fail. - `store` is always false upstream — this gateway is stateless. Send the full message history on every call to maintain context. - `temperature`, `max_tokens` / `max_completion_tokens` are passed through when provided. - `n` > 1, `logprobs` and embeddings are NOT supported.