Local OpenAI-compatible HTTP proxy backed by Codex/OpenAI credentials
Project description
codex-api-proxy
Local OpenAI-compatible HTTP proxy backed by Codex/OpenAI credentials.
The proxy has one runtime path: it reads credentials from ~/.codex/auth.json or CODEX_HOME/auth.json, then forwards requests to the upstream OpenAI/Codex API. It no longer runs local codex exec, starts codex app-server, manages workspaces, or exposes sandbox/agent/fast engine settings.
Product Scope
This package is intentionally narrow:
- expose OpenAI-compatible local endpoints for clients such as OpenClaw;
- reuse the user's existing Codex/OpenAI login credentials;
- support
/v1/chat/completions,/v1/responses, and/v1/models; - convert Chat Completions to Responses API when using ChatGPT Codex credentials;
- otherwise transparently forward OpenAI API-key requests to OpenAI's native
/chat/completions.
Out of scope:
- local command execution;
- workspace read/write control;
- Codex sandbox configuration;
- app-server workers;
- simulated tool-call wrapping;
- custom model execution engines.
Tool calls and function calls are handled by the upstream OpenAI-compatible API response, not by local prompt wrapping.
Install
pip3 install codex-api-proxy
For local development from this checkout:
python3 -m pip install -e '.[dev]'
Credentials
The proxy reads Codex credentials from:
~/.codex/auth.json
or, when CODEX_HOME is set:
$CODEX_HOME/auth.json
Supported auth shapes:
OPENAI_API_KEY: forwarded tohttps://api.openai.com/v1;- Codex/ChatGPT
tokens.access_token: forwarded tohttps://chatgpt.com/backend-api/codex.
For Codex/ChatGPT token auth, the proxy refreshes tokens automatically:
- before a request when the access token JWT expires within 5 minutes;
- before a request when
last_refreshis older than 8 days and the access token has no parseable expiry; - after an upstream
401, then it retries the original request once.
Refreshed tokens are written back to auth.json with 0600 permissions when supported by the platform.
Outbound upstream proxy settings are controlled by environment variables:
CODEX_API_PROXY_HTTPS_PROXYHTTPS_PROXYhttps_proxy
When none are set, the proxy defaults to http://127.0.0.1:8118.
You can also set the upstream proxy explicitly at startup:
codex-api-proxy start --proxy=http://127.0.0.1:8118
Run
Start in the background:
codex-api-proxy start
Run in the foreground with debug logs:
codex-api-proxy start --foreground --log-level debug
Bind to all interfaces with local bearer auth:
codex-api-proxy start --host 0.0.0.0 --api-key local-secret
Start with an explicit upstream proxy:
codex-api-proxy start --proxy=http://127.0.0.1:8118
Restart using the last saved start settings:
codex-api-proxy restart
Stop:
codex-api-proxy stop
Status:
codex-api-proxy status --verbose
CLI Options
--host: bind host, default127.0.0.1--port: bind port, default8765--api-key: require client requests to sendAuthorization: Bearer <key>--proxy: upstream HTTP(S) proxy URL for OpenAI/Codex API calls--log-level:debug,info,warning, orerror--pid-file: daemon pid file, default~/.codex-api-proxy/codex-api-proxy.pid--log-file: daemon log file, default~/.codex-api-proxy/codex-api-proxy.log--state-file: daemon state file, default~/.codex-api-proxy/codex-api-proxy.state.json--foreground: run without daemonizing
Environment variables for the local server:
CODEX_PROXY_HOSTCODEX_PROXY_PORTCODEX_PROXY_API_KEYCODEX_API_PROXY_HTTPS_PROXYCODEX_PROXY_LOG_LEVEL
Token refresh compatibility variables:
CODEX_REFRESH_TOKEN_URL_OVERRIDE: override the OAuth refresh endpointCODEX_APP_SERVER_LOGIN_CLIENT_ID: override the OAuth client id
API
Health:
curl -sS http://127.0.0.1:8765/health
Models:
curl -sS http://127.0.0.1:8765/v1/models
Chat completion:
curl -sS http://127.0.0.1:8765/v1/chat/completions \
-H 'Content-Type: application/json' \
-d '{"model":"gpt-5.5","messages":[{"role":"user","content":"Reply with exactly: pong"}]}'
Streaming chat completion:
curl -N http://127.0.0.1:8765/v1/chat/completions \
-H 'Content-Type: application/json' \
-d '{"model":"gpt-5.5","stream":true,"messages":[{"role":"user","content":"Reply with exactly: pong"}]}'
Responses API passthrough:
curl -sS http://127.0.0.1:8765/v1/responses \
-H 'Content-Type: application/json' \
-d '{"model":"gpt-5.5","input":"Reply with exactly: pong"}'
When --api-key is configured:
curl -sS http://127.0.0.1:8765/v1/chat/completions \
-H 'Authorization: Bearer local-secret' \
-H 'Content-Type: application/json' \
-d '{"model":"gpt-5.5","messages":[{"role":"user","content":"Reply with exactly: pong"}]}'
Operations
/health checks that credentials can be loaded and shows the upstream mode without exposing secrets.
/ready is an alias of /health.
/metrics returns local request counters:
requests_totalrequests_okrequests_errorerrors_by_statusuptime_seconds
When --log-level debug is set, chat completions log input messages and output messages through codex_api_proxy.messages and the daemon's uvicorn.error log stream. Streaming output is logged after the stream finishes. These logs can contain prompt and response data; use debug logging only in trusted environments.
Latency summaries are logged through codex_api_proxy.latency.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file codex_api_proxy-0.1.2.tar.gz.
File metadata
- Download URL: codex_api_proxy-0.1.2.tar.gz
- Upload date:
- Size: 26.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f359fdf7a48999d46e54dccaeff268721f77b8a1536502a87f8da1d37cd0f7e4
|
|
| MD5 |
87fa1e6ae006e2e5bcb5948be6993dfc
|
|
| BLAKE2b-256 |
074565c1a205ea7b8200436c029551e130a19a829543cb65ffc76f2d67714e54
|
File details
Details for the file codex_api_proxy-0.1.2-py3-none-any.whl.
File metadata
- Download URL: codex_api_proxy-0.1.2-py3-none-any.whl
- Upload date:
- Size: 20.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
32595f12d0d1d6785788b8f5bb625a834d789260070d91bc9cadb001c6be7d3f
|
|
| MD5 |
feaf57c5c405031b6f9eaaacb8b8044f
|
|
| BLAKE2b-256 |
ba7ee5a4e70b49082491f9d765906c2e01a14746b1a38ef6dc3f1f37beed32b8
|