A LAN OpenAI-compatible relay server.
Project description
codex-relay-server
A LAN relay server for OpenAI-compatible HTTP APIs.
Use this when one computer can reach the upstream model provider, but other computers on the LAN can only reach that computer. LAN clients point their OpenAI SDKs at this relay; the relay forwards requests to your configured upstream API root and streams the upstream response back.
Features
- Bind to any local IP and port, such as
0.0.0.0:8000or a specific LAN adapter IP. - Use any upstream API root URL. The upstream does not need to use
/v1. - Configure the local client-facing base path, such as
/,/v1,/openai, or/api/openai. - Forward all endpoints with the same path rules, including
/chat/completions,/responses,/models, and future API paths. - Pass through normal JSON responses and streaming SSE responses.
- Support two API key modes:
direct: forward the incomingAuthorizationheader unchanged.transform: map client-visible keys to upstream keys, with an optional default upstream key.
Installation
pip install codex-relay-server
Configuration
Copy the example config:
cp config.example.json config.json
Edit config.json:
{
"server": {
"host": "0.0.0.0",
"port": 8000
},
"relay": {
"upstream_url": "https://your-upstream.example/custom-api",
"local_base_path": "/",
"strip_local_base_path": true
},
"auth": {
"mode": "direct"
}
}
With that config, an incoming LAN request to /responses is forwarded to:
https://your-upstream.example/custom-api/responses
The default local_base_path is /, so the relay accepts requests from the root path. Set local_base_path explicitly if you want clients to use a specific base URL such as /v1 or /openai.
Set strip_local_base_path to false if you want the full local path appended to the upstream URL.
You can expose any local base path:
{
"relay": {
"upstream_url": "https://your-upstream.example/not-v1",
"local_base_path": "/openai",
"strip_local_base_path": true
}
}
LAN clients can then use this base URL:
http://<relay-lan-ip>:8000/openai
Transform Mode
{
"auth": {
"mode": "transform",
"key_map": {
"client-visible-key-a": "real-upstream-key-a",
"client-visible-key-b": "real-upstream-key-b"
},
"default_key": "real-default-upstream-key"
}
}
In transform mode, if the client sends:
Authorization: Bearer client-visible-key-a
The upstream receives:
Authorization: Bearer real-upstream-key-a
If the client key is not in key_map and default_key is configured, the relay uses default_key. If no default key is available, the relay returns 401.
Keep real upstream keys in local config.json or Python-provided configuration. Do not commit them. This repository ignores config.json, *.local.json, and *.secrets.json.
Python Configuration
You can also provide configuration from Python code instead of a JSON file:
from codex_relay_server import create_app, load_settings
settings = load_settings(
{
"server": {"host": "0.0.0.0", "port": 8000},
"relay": {
"upstream_url": "https://your-upstream.example/custom-api",
"local_base_path": "/openai",
"strip_local_base_path": True,
},
"auth": {"mode": "direct"},
}
)
app = create_app(settings)
Run
codex-relay-server --config config.json
You can temporarily override the bind address, port, upstream URL, and local base path:
codex-relay-server \
--config config.json \
--host 0.0.0.0 \
--port 8000 \
--upstream-url https://your-upstream.example/custom-api \
--local-base-path /openai
LAN client settings:
base_url = http://<relay-lan-ip>:8000/<your-local-base-path>
api_key = <client-key>
Tests
python -m pytest
Tests use a local mock upstream and do not need a real API key.
Security Notes
- Do not expose this service to the public internet, especially in
transformmode withdefault_keyenabled. - If you bind to
0.0.0.0, make sure your firewall only allows trusted LAN clients. - The project does not store private keys in tracked files. Put real keys in ignored local config files or Python-provided configuration.
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_relay_server-0.1.2.tar.gz.
File metadata
- Download URL: codex_relay_server-0.1.2.tar.gz
- Upload date:
- Size: 12.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.4.1 CPython/3.11.15 Windows/10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9cbf194f14c819ebcc53b3eacae6e8c667755cd7541d39c4171981346d851491
|
|
| MD5 |
b143b888ea559b077201930d6c4509e2
|
|
| BLAKE2b-256 |
a17328103a80863e9fcf1bc9cda52624cb577ac2257b16c65c9405239e4feab2
|
File details
Details for the file codex_relay_server-0.1.2-py3-none-any.whl.
File metadata
- Download URL: codex_relay_server-0.1.2-py3-none-any.whl
- Upload date:
- Size: 9.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.4.1 CPython/3.11.15 Windows/10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
86bb43bc687c110c1a2a7ce81d2c44a9fa4ea006bf5e70a15d8b1bff48c94af5
|
|
| MD5 |
9c26a25765698799664adb28923236ba
|
|
| BLAKE2b-256 |
d23e52fed1f3aed1d7cc8fba98135893f5e0afbea0ba2a80e6938709e7a9a11b
|