No description
- Python 93.3%
- Shell 5.7%
- Dockerfile 1%
| .example.env | ||
| .gitignore | ||
| api_keys.example.json | ||
| docker-compose.yml | ||
| Dockerfile | ||
| gen_api_key.py | ||
| main.py | ||
| README.md | ||
| requirements.txt | ||
| routes.example.yaml | ||
| setup.sh | ||
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
429by 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) mapdata/logs/: proxy logs
Example data/api_keys.json:
{
"api-key-1": "auth1.json",
"api-key-2": ["auth2.json", "auth3.json"]
}
Setup
- Copy
.example.envto.envand adjust values (BIND_PORT, route prefixes, upstreams, etc.). - Put one or more auth files in
data/auth/(for exampleauth1.json,auth2.json). - Create
data/api_keys.json(seeapi_keys.example.json) or run./setup.shto seed/generate it. - Start the container:
docker compose up --build -d
setup.sh also:
- generates one client API key per auth file (if missing)
- sets permissions (
data/auth777, auth files666,data/api_keys.json666)
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.