AIRelays: an independent OpenAI-compatible local relay for single-user subscription-backed access.
Project description
AIRelays
AIRelays is an independent local OpenAI-compatible HTTP server backed by a ChatGPT subscription login that AIRelays stores independently. It exposes the verified OpenAI-shaped routes this upstream can support, protects the local relay with its own bearer token, and logs every transit to hourly JSONL files.
POST /v1/responses keeps the general OpenAI Responses envelope, but parameter parity is not complete. Some fields pass through unchanged, some are adapted for the subscription backend, and unsupported fields are rejected or omitted explicitly.
AIRelays does not require a user-supplied OpenAI platform API key for upstream inference. Instead, it uses the same upstream ChatGPT login protocol that Codex uses while keeping AIRelays auth storage separate from Codex storage. Clients that call AIRelays should use the relay bearer token as the local client credential they present to AIRelays.
Independence And Intended Use
- AIRelays is an independent third-party project. It is not affiliated with, endorsed by, or sponsored by OpenAI.
- Provider and product names are used only to describe compatibility targets and upstream behavior.
- AIRelays is designed for a single user running a local relay for personal convenience.
- AIRelays is not presented as a shared, pooled, multi-user, or resale service.
- You are responsible for complying with the terms and usage policies that apply to any upstream account or subscription you use with AIRelays.
See DISCLAIMER.md for the short project notice.
Quick Start
python -m pip install .
airelays init
airelays login
airelays serve --port 8080
If you are installing from a published package instead of a source checkout, use python -m pip install airelays.
If you want a local relay with no client-side bearer auth, use:
airelays init --no-auth
airelays login
airelays serve --no-auth --port 8080
This disables only the AIRelays client token gate. Model routes still require a valid upstream ChatGPT login from airelays login.
Existing local AIRelay state is recognized for compatibility. If you already have singular-path state such as ~/.config/airelay, ~/.airelay, or an older AIRelay Auth keychain entry, AIRelays can continue using it without sharing runtime state with Codex.
Smoke test the public and protected surfaces:
curl http://127.0.0.1:8080/healthz
curl http://127.0.0.1:8080/v1/relay/status \
-H 'authorization: Bearer YOUR_AIRELAYS_TOKEN'
In open local relay mode, the same GET /v1/relay/status request works without the Authorization header.
Verify protected model access and a simple query:
curl http://127.0.0.1:8080/v1/models \
-H 'authorization: Bearer YOUR_AIRELAYS_TOKEN'
curl http://127.0.0.1:8080/v1/chat/completions \
-H 'authorization: Bearer YOUR_AIRELAYS_TOKEN' \
-H 'content-type: application/json' \
-d '{
"model": "gpt-5.5",
"messages": [{"role": "user", "content": "Reply with exactly: AIRelays OK"}]
}'
Verify the same calls in open local relay mode:
curl http://127.0.0.1:8080/v1/models
curl http://127.0.0.1:8080/v1/chat/completions \
-H 'content-type: application/json' \
-d '{
"model": "gpt-5.5",
"messages": [{"role": "user", "content": "Reply with exactly: AIRelays OK"}]
}'
Inspect the resolved relay and upstream-auth state at any point:
airelays status
CLI status and setup commands default to readable terminal output. Use --json on airelays init, airelays status, airelays logout, airelays token show, or airelays token rotate when you need machine-readable output for automation.
Point your client at:
http://127.0.0.1:8080/v1
Use the token generated by airelays init as the client credential when you point an OpenAI-compatible SDK at AIRelays. Standard OpenAI SDKs will then send Authorization: Bearer <relay-token> automatically.
If you launch with --no-auth or AIRELAYS_REQUIRE_BEARER_AUTH=false, clients can call the relay without an Authorization header. If an SDK still requires an api_key field, any non-empty placeholder string works in that mode.
If you want to provide the relay token yourself instead of using the default token file, launch the server with:
AIRELAYS_BEARER_TOKEN='YOUR_AIRELAYS_TOKEN' airelays serve --port 8080
or point AIRelays at a specific token file:
airelays serve --bearer-token-file /path/to/relay-token --port 8080
What AIRelays Does
- Uses the same upstream login protocol as Codex browser login and device-code login.
- Stores upstream auth under AIRelays-owned state instead of reusing
~/.codex. - Generates and persists a separate relay bearer token for client-to-relay access.
- Can run in open local relay mode with bearer auth disabled.
- Protects
/v1/*and/no-tools/v1/*with bearer auth, per-IP rate limits, concurrent-request caps, and temporary blocks after repeated bad tokens. - Exposes OpenAI-compatible routes for:
GET /v1/modelsGET /v1/subscription/statusGET /v1/account/rate_limitsPOST /v1/completionsPOST /v1/responsesPOST /v1/chat/completionsPOST /v1/filesGET /v1/filesGET /v1/files/{file_id}GET /v1/files/{file_id}/contentDELETE /v1/files/{file_id}POST /v1/conversationsGET /v1/conversations/{conversation_id}POST /v1/conversations/{conversation_id}DELETE /v1/conversations/{conversation_id}/no-tools/v1/models/no-tools/v1/completions/no-tools/v1/responses/no-tools/v1/chat/completions
- Logs inbound requests, endpoint rejects, outbound responses, upstream requests, upstream responses, stream lines, and usage summaries to
logs/YYYY/MM/DD-HH.log.
First-Run Flow
airelays init- writes
~/.config/airelays/config.tomlif it does not already exist - creates
~/.airelays/relay-tokenwith0600permissions if a relay token is missing - prints a formatted setup summary and reveals the token only when it was newly created
- writes
airelays init --no-auth- writes
~/.config/airelays/config.tomlwith bearer auth disabled - does not create or require a relay token
- writes
airelays login- creates an AIRelays-owned ChatGPT subscription session
airelays serve --port 8080- starts the protected local endpoint
- fails fast if bearer auth is enabled but no relay token is configured
- prints the client base URL, token file path, and the required
Authorizationheader shape
airelays serve --no-auth --port 8080- starts an open local endpoint with no relay-token check
- keeps the normal per-IP rate limits and concurrency limits
You can show the current relay token at any time:
airelays token show
You can also rotate the relay token later:
airelays token rotate
Example Client Usage
Python with the OpenAI SDK:
from openai import OpenAI
client = OpenAI(
base_url="http://127.0.0.1:8080/v1",
api_key="YOUR_AIRELAYS_TOKEN",
)
response = client.responses.create(
model="gpt-5.4-mini",
input="Summarize the purpose of AIRelays.",
)
print(response.output_text)
Raw curl:
curl http://127.0.0.1:8080/v1/responses \
-H 'authorization: Bearer YOUR_AIRELAYS_TOKEN' \
-H 'content-type: application/json' \
-d '{
"model": "gpt-5.4-mini",
"input": "Summarize the purpose of AIRelays.",
"stream": false
}'
Shell example with a relay-token environment variable:
export OPENAI_BASE_URL='http://127.0.0.1:8080/v1'
export AIRELAYS_TOKEN="$(tr -d '\n' < ~/.airelays/relay-token)"
If your SDK insists on an api_key argument, pass the relay token from AIRELAYS_TOKEN.
Open local relay mode with a placeholder value for SDKs that insist on one:
export OPENAI_BASE_URL='http://127.0.0.1:8080/v1'
export AIRELAYS_CLIENT_PLACEHOLDER='local-open-relay'
Verified Compatibility Boundary
This server is intentionally explicit about what is and is not verified.
- Inference uses
https://chatgpt.com/backend-api/codex. - Subscription status uses
https://chatgpt.com/backend-api/wham/usage. - The upstream requires
stream=true, so non-stream OpenAI responses are reconstructed locally from streamed event sequences. - The upstream requires
store=false, so requests that try to enable upstream storage are rejected with422. - The upstream requires non-empty
instructions, so the compatibility layer injects the minimal verified placeholder"."only when the caller omitted instructions entirely. - Image input is supported.
- Text and JSON-like document input is supported by local inlining up to 1 MB.
- Local file uploads are capped at 32 MiB each and 256 MiB total by default.
- Audio input, embeddings, image generation, realtime sessions, and other unverified routes return explicit
501 unsupported_error.
Security Defaults
- Listener default:
127.0.0.1:8080 - Protected routes:
/v1/*and/no-tools/v1/* - Public routes:
/and a minimalGET /healthz - Protected diagnostics:
GET /v1/relay/status - Relay auth: bearer token required by default
- Token storage:
~/.airelays/relay-token - Default rate limit:
120requests/minute with burst40 - Default concurrent request cap:
8per IP - Default repeated-auth-failure block:
8bad attempts in300seconds ->900second block
See Security for the full behavior.
Configuration
AIRelays reads configuration in this order:
- explicit CLI flags such as
--config,--port, or--auth-storage AIRELAYS_*environment variables- legacy
OPENAI_ENDPOINT_*environment variables where supported as a migration fallback ~/.config/airelays/config.toml- built-in defaults
auth.storage = "auto" prefers the AIRelays keyring namespace and falls back to ~/.airelays/auth.json when keyring access is unavailable.
If earlier AIRelay config or data directories already exist, AIRelays keeps using them for compatibility. In keyring-backed setups, AIRelays also recognizes earlier AIRelay Auth entries and migrates them into the AIRelays-owned namespace when they are encountered.
Important paths:
- config:
~/.config/airelays/config.toml - data dir:
~/.airelays - upstream auth fallback file:
~/.airelays/auth.json - logs:
~/.airelays/logs - relay token:
~/.airelays/relay-token
To override the default token source at launch time:
AIRELAYS_BEARER_TOKENairelays serve --bearer-token-file /path/to/relay-token
To launch without relay auth:
airelays init --no-authairelays serve --no-authAIRELAYS_REQUIRE_BEARER_AUTH=false
See Configuration for field details and a sample config.
Publication Surface
- package name:
airelays - CLI command:
airelays - Python package:
airelays
Documentation
Project details
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 airelays-0.2.3.tar.gz.
File metadata
- Download URL: airelays-0.2.3.tar.gz
- Upload date:
- Size: 73.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e57d0e595b8784d5d599c3cc962aed0e45eabef3a4c65b898dbaf3f4f9a4225b
|
|
| MD5 |
092356298ac7eb11b7bfe69bccdbe1b0
|
|
| BLAKE2b-256 |
ec071aab3fa3c65b4e8c5305264b14ce40bc8e235b412869070b3be404101442
|
Provenance
The following attestation bundles were made for airelays-0.2.3.tar.gz:
Publisher:
release.yml on lpalbou/AIRelays
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
airelays-0.2.3.tar.gz -
Subject digest:
e57d0e595b8784d5d599c3cc962aed0e45eabef3a4c65b898dbaf3f4f9a4225b - Sigstore transparency entry: 1887969725
- Sigstore integration time:
-
Permalink:
lpalbou/AIRelays@ee7f3f4e8ece36242f46a83cab23fdf71fd6010c -
Branch / Tag:
refs/tags/v0.2.3 - Owner: https://github.com/lpalbou
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@ee7f3f4e8ece36242f46a83cab23fdf71fd6010c -
Trigger Event:
push
-
Statement type:
File details
Details for the file airelays-0.2.3-py3-none-any.whl.
File metadata
- Download URL: airelays-0.2.3-py3-none-any.whl
- Upload date:
- Size: 50.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3623a71b3ce330c168ff86c73ca171422136dc6f97a8958579f69e451b26e663
|
|
| MD5 |
948023a8c0db9882bb6ccd1a252c23b5
|
|
| BLAKE2b-256 |
757afa03e75c10f7510e450fcaa6e231c5d01b70aef4caba8f13a04799103ffd
|
Provenance
The following attestation bundles were made for airelays-0.2.3-py3-none-any.whl:
Publisher:
release.yml on lpalbou/AIRelays
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
airelays-0.2.3-py3-none-any.whl -
Subject digest:
3623a71b3ce330c168ff86c73ca171422136dc6f97a8958579f69e451b26e663 - Sigstore transparency entry: 1887969828
- Sigstore integration time:
-
Permalink:
lpalbou/AIRelays@ee7f3f4e8ece36242f46a83cab23fdf71fd6010c -
Branch / Tag:
refs/tags/v0.2.3 - Owner: https://github.com/lpalbou
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@ee7f3f4e8ece36242f46a83cab23fdf71fd6010c -
Trigger Event:
push
-
Statement type: