OpenAI-compatible relay with slot-aware routing for Codex-backed requests, using local runtime state and no external database.
Designed to pair with codex-utils:
codex-utils-> client helperscodex-slot-relay-> backend relay + multi-account slot management
Goal: a maintainable multi-account Codex backend you can run independently.
Target flow:
User -> codex-utils -> codex-slot-relay
With built-in slot selection and automatic rolling to the best available account based on usage/health.
- OpenAI-compatible endpoints
GET /v1/modelsPOST /v1/chat/completionsPOST /v1/responses
- SSE streaming for both API styles
- slot-aware routing based on usage + cooldown + health
- structured JSON request logging with request-id and slot-id tracing headers
- built-in admin/observability endpoints
GET /healthzGET /admin/slotsGET /admin/statsGET /admin/dependency-mapGET /admin/configPOST /admin/refresh-usage
- configurable slot selection policy
best-week-then-5h(default)best-5h-then-weekleast-recently-used
- relay-managed slot lifecycle
- native login (
slot-login) - auth import/copy (
slot-auth-import-file,slot-auth-copy-profile) - usage management (
refresh-usage,slot-usage-set,slot-usage-copy-main) - enable/disable/remove slot
- native login (
- optional legacy bridge to OpenClaw when needed
Default runtime is standalone-first:
auth.backend = nativeusage.backend = codex-apirunner.backend = codex-direct
This means the default path does not require OpenClaw for auth, usage refresh, or runner execution.
Legacy fallback backends remain available for migration/compatibility:
auth.backend = openclawusage.backend = openclawrunner.backend = openclaw
git clone https://github.com/IndraLawliet13/codex-slot-relay.git
cd codex-slot-relay
pip install .codex-slot-relay initcodex-slot-relay slot-login --slot 1 --label your-email@example.comThe command prints an OAuth URL. Open it, complete login, then paste callback URL/code back to terminal.
codex-slot-relay refresh-usage
codex-slot-relay slot-listcodex-slot-relay serveQuick sanity check:
curl -sS http://127.0.0.1:8787/healthz
curl -sS http://127.0.0.1:8787/admin/stats -H 'Authorization: Bearer relay-dev-token'Default local API target:
- base URL:
http://127.0.0.1:8787/v1 - API key:
relay-dev-token
Use relay-selftest for plumbing-only verification, or gpt-5.4 for a real slot-backed request.
curl -sS -X POST http://127.0.0.1:8787/v1/chat/completions \
-H 'Authorization: Bearer relay-dev-token' \
-H 'Content-Type: application/json' \
--data '{"model":"relay-selftest","messages":[{"role":"user","content":"hello"}]}'Defaults are aligned for local pairing:
CODEX_BASE_URL=http://127.0.0.1:8787/v1CODEX_API_KEY=relay-dev-token
So after relay is up, CodexClient() can work without extra config.
Main commands:
codex-slot-relay initcodex-slot-relay setup(legacy convenience bootstrap)codex-slot-relay sync-slots(legacy bridge import)codex-slot-relay slot-import-main(clearer alias forsync-slots)codex-slot-relay slot-login --slot 2 --label account@example.comcodex-slot-relay slot-auth-import-file --slot 2 --label imported@example.com --auth-file /path/to/auth-profiles.jsoncodex-slot-relay slot-auth-copy-profile --slot 3 --label copied@example.com --source-profile codex-slot-relaycodex-slot-relay slot-listcodex-slot-relay slot-enable --slot 2codex-slot-relay slot-disable --slot 2codex-slot-relay slot-remove --slot 2codex-slot-relay slot-usage-set --slot slot-2 --usage5h '95% left · resets 3h' --usageWeek '84% left · resets 6d 23h'codex-slot-relay slot-usage-copy-main --slot slot-2codex-slot-relay refresh-usagecodex-slot-relay healthcodex-slot-relay dependency-mapcodex-slot-relay test-runner --slot slot-2 --prompt "Reply with exactly pong"codex-slot-relay serve
docs/QUICKSTART.mddocs/ARCHITECTURE.mddocs/CODEX_UTILS.mddocs/OPERATOR_GUIDE.mddocs/DEPENDENCY_MAP.md
- Relay is stateless by design.
/v1/chat/completionsoncodex-directis translated over Codex Responses API.toolsonchat/completionspath is intentionally limited in current version.- Every HTTP response now includes lightweight tracing headers:
X-Relay-VersionX-Relay-Request-IdX-Relay-Slot-Id(when a slot-backed request is selected)
MIT