OpenRouter¶
OpenRouter speaks the OpenAI Chat Completions format at
https://openrouter.ai/api/v1. That path is not among Privyx's default
routes, so add it. Without the route, requests are forwarded unmasked.
Configure¶
# openrouter.yaml
proxy:
routes:
/api/v1/chat/completions: openai
privyx proxy -c openrouter.yaml --upstream https://openrouter.ai
Connect a client¶
The client keeps OpenRouter's /api/v1 in its base URL and its OpenRouter
key, which Privyx relays:
import os
from openai import OpenAI
client = OpenAI(
base_url="http://localhost:8000/api/v1",
api_key=os.environ["OPENROUTER_API_KEY"],
)
reply = client.chat.completions.create(
model="openai/gpt-4o-mini",
messages=[{"role": "user", "content": "Write a short greeting to alice@example.com"}],
)
print(reply.choices[0].message.content)
Optional headers such as HTTP-Referer pass through unchanged.
Good to know¶
proxy.routesreplaces the default map. If the same proxy should also serve the standard paths, list them too; see Routes.- Other OpenRouter paths, such as
/api/v1/models, are forwarded as sent. Setproxy.passthrough_unknown: falseto refuse anything that is not masked. - To check the route, run
privyx audit tailafter a request:session.transformappears only for masked paths, andproxy.requestshowsschema=openai.