Chinese version: README_zh.md
Codex Gateway is a Rust HTTP/SSE gateway for running isolated Codex sessions behind a small API and browser UI.
Generated Qoder documentation may exist under .qoder/; it is generated output and should not be edited by hand or committed as source documentation. This README is the maintained human entry point.
All Gateway sessions use the embedded runtime:
- A client creates a session through the Rust gateway.
- The session owns a
CodexAppServerBridge. - The bridge starts and manages one
codex app-serversubprocess over stdio. - App-server notifications are folded into session state and streamed to the client over SSE.
Brain deployment tasks use the same embedded runtime, but expose a polling-only task API instead of the interactive session API. Gateway does not create or manage Devbox runtimes for deployment requests.
If deployment work runs in Devbox, an external system is responsible for creating the Devbox and starting this gateway inside it before calling the Brain Deployment API.
POST /api/brain/deployments is a Brain application API. It is not intended to describe a general deployment product surface.
The endpoint creates a local embedded Codex task that installs the deployment skill if needed, builds the repository image, pushes it to GHCR, generates a Sealos template, and reports a machine-readable deployment result containing both the image reference and template content. It does not expose intermediate Codex output or accept follow-up user turns.
GET /healthzGET /readyzPOST /api/sessionsGET /api/sessions/:id/stateGET /api/sessions/:id/eventsPOST /api/sessions/:id/turnPOST /api/sessions/:id/turn/interruptPOST /api/sessions/:id/thread/newPOST /api/sessions/:id/thread/resumeDELETE /api/sessions/:idGET /api/threadsGET /api/threads/:threadIdPOST /api/brain/deploymentsGET /api/brain/deployments/:threadId
Legacy single-session routes such as /api/state, /api/events, /api/turn, and /api/thread/new are removed and return 410 Gone.
Start the gateway:
CODEX_GATEWAY_OPENAI_API_KEY=sk-... \
CODEX_GATEWAY_OPENAI_BASE_URL=https://example-openai-compatible-endpoint.test \
CODEX_GATEWAY_JWT_SECRET=replace-with-your-hs256-secret \
cargo run --bin codex-gatewayOpen:
http://127.0.0.1:1317
Quick API smoke test:
curl -X POST http://127.0.0.1:1317/api/sessions \
-H 'Content-Type: application/json' \
-d '{}'Gateway-owned settings use the CODEX_GATEWAY_ prefix.
CODEX_GATEWAY_HOST: bind address. Defaults to0.0.0.0.CODEX_GATEWAY_PORT: bind port. Defaults to1317.CODEX_GATEWAY_CWD: working directory passed tothread/start.CODEX_GATEWAY_CODEX_BIN: path to thecodexexecutable.CODEX_GATEWAY_MODEL: preferred default model.CODEX_GATEWAY_OPENAI_API_KEY: API key used at startup forcodex login --with-api-key.CODEX_GATEWAY_OPENAI_BASE_URL: upstream OpenAI-compatible base URL.CODEX_GATEWAY_JWT_SECRET: optional HS256 JWT secret.CODEX_GATEWAY_MAX_SESSIONS: maximum live sessions. Defaults to12.CODEX_GATEWAY_SESSION_TTL_MS: idle session TTL. Defaults to1800000.CODEX_GATEWAY_SESSION_SWEEP_INTERVAL_MS: cleanup sweep interval. Defaults to60000.
Devbox lifecycle is external to this gateway. If the gateway is running in Devbox, configure the process with the normal gateway settings above.
cargo fmt --check
cargo test