A local forwarding service that lets you call your upstream model API with standard OpenAI-style requests, without setting extra_headers on every call.
It forwards /v1/* requests to your upstream endpoint and automatically injects:
X-Api-Key: <upstream.x_api_key>
cd /mnt/d/Github/glm-openai-forwarder
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
cp config.example.toml config.tomlEdit config.toml:
[server]
host = "127.0.0.1"
port = 8010
[upstream]
base_url = "http://7.150.8.95:28082/glm5/v1"
x_api_key = "sk-your-upstream-x-api-key"
timeout_seconds = 300Run:
./run.shHealth check:
curl -s http://127.0.0.1:8010/healthzOptional: use a non-default config path via env:
FORWARDER_CONFIG=/path/to/my-forwarder.toml ./run.shimport os
from openai import OpenAI
# optional: disable system proxy
os.environ["http_proxy"] = ""
os.environ["https_proxy"] = ""
client = OpenAI(
api_key="sk-your-openai-style-api-key", # sent as Authorization: Bearer ...
base_url="http://127.0.0.1:8010/v1",
)
completion = client.chat.completions.create(
model="glmmoedsa",
messages=[{"role": "user", "content": "hi"}],
)
print(completion.choices[0].message.content)- Keep
upstream.base_urlwith/v1suffix to match path forwarding. - The proxy keeps your original
Authorizationheader and addsX-Api-Keyautomatically. - Streaming requests (
stream=True) are supported.