No description
  • Python 93.3%
  • Shell 5.7%
  • Dockerfile 1%
Find a file
2026-02-24 09:25:03 +01:00
.example.env allow routing different api keys with different auth credentials (shared routing yaml), handle refresh of multiple tokens, make setup.sh more easy to use 2026-02-22 21:49:56 +01:00
.gitignore initial commit 2026-02-06 06:21:35 +01:00
api_keys.example.json allow multiple backing upstream auth files for one self-generated client api key, with round-robin if one gets rate limited 2026-02-24 09:25:03 +01:00
docker-compose.yml allow routing different api keys with different auth credentials (shared routing yaml), handle refresh of multiple tokens, make setup.sh more easy to use 2026-02-22 21:49:56 +01:00
Dockerfile install deps first, copy main.py later (better docker caching behavior -> faster build times) 2026-02-22 22:02:33 +01:00
gen_api_key.py bigger api keys in setup.sh, api key gen python script 2026-02-22 22:08:43 +01:00
main.py allow multiple backing upstream auth files for one self-generated client api key, with round-robin if one gets rate limited 2026-02-24 09:25:03 +01:00
README.md allow multiple backing upstream auth files for one self-generated client api key, with round-robin if one gets rate limited 2026-02-24 09:25:03 +01:00
requirements.txt add configurable routing to either chatgpt subscription backend or openai api with simple yaml routing config format 2026-02-08 19:50:56 +01:00
routes.example.yaml add configurable routing to either chatgpt subscription backend or openai api with simple yaml routing config format 2026-02-08 19:50:56 +01:00
setup.sh allow multiple backing upstream auth files for one self-generated client api key, with round-robin if one gets rate limited 2026-02-24 09:25:03 +01:00

Codex Subscription API Proxy

Small FastAPI proxy for forwarding client requests to ChatGPT/Codex and OpenAI API endpoints using one or more local Codex auth files.

What It Does

  • Accepts client requests with Authorization: Bearer <client-api-key>.
  • Looks up that client key in data/api_keys.json.
  • Selects the mapped auth file (or auth-file pool) from data/api_keys.json.
  • Forwards the request upstream using credentials from that auth file.
  • Refreshes each auth file independently (chat/Codex OAuth token refresh).
  • If a client key maps to multiple auth files, retries on upstream 429 by rotating to the next auth file.

File Layout

  • data/auth/*.json: one or more Codex auth files (writable; refreshed in place)
  • data/api_keys.json: client key to auth-file (or auth-file list) map
  • data/logs/: proxy logs

Example data/api_keys.json:

{
  "api-key-1": "auth1.json",
  "api-key-2": ["auth2.json", "auth3.json"]
}

Setup

  1. Copy .example.env to .env and adjust values (BIND_PORT, route prefixes, upstreams, etc.).
  2. Put one or more auth files in data/auth/ (for example auth1.json, auth2.json).
  3. Create data/api_keys.json (see api_keys.example.json) or run ./setup.sh to seed/generate it.
  4. Start the container:
docker compose up --build -d

setup.sh also:

  • generates one client API key per auth file (if missing)
  • sets permissions (data/auth 777, auth files 666, data/api_keys.json 666)

Usage

Send requests to your configured ROUTE_PREFIX with a client key from data/api_keys.json.

Example:

curl http://127.0.0.1:8080/codex \
  -H 'Authorization: Bearer api-key-1'

For POST requests, pass the same client key and your normal JSON body; the proxy forwards to the configured upstream route based on routes.yaml.