Getting started
PrivateRouter is an OpenAI-compatible API gateway backed by self-hosted open models. If you can call the OpenAI API, you can call PrivateRouter — change two lines (base URL and key) and you're done.
This page gets you from zero to a working chat completion in under five minutes.
Step 1 — Get an API key
- Sign up at /signup (free tier — no card required).
- Open /keys in your dashboard.
- Click Create key, give it a label (e.g.
local-dev), and copy thepr-…token. This is the only time the full key is shown. Paste it into your secret manager /.envimmediately.
Keys are scoped to your account and inherit your plan's spend caps and rate limits.
Step 2 — Point your client at PrivateRouter
There are exactly two things to configure:
| Setting | Value |
|---|---|
| Base URL | https://api.privaterouter.com/v1 |
| API key | pr-… (from step 1, as OPENAI_API_KEY) |
Every OpenAI SDK we've tested honours base_url / OPENAI_BASE_URL. No fork
or wrapper required.
Step 3 — Make your first call
curl
curl -fsS https://api.privaterouter.com/v1/chat/completions \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "privaterouter/qwen-pro",
"messages": [
{"role": "user", "content": "Write a haiku about retries."}
]
}'
Python
pip install openai
import os
from openai import OpenAI
client = OpenAI(
base_url="https://api.privaterouter.com/v1",
api_key=os.environ["OPENAI_API_KEY"],
)
resp = client.chat.completions.create(
model="privaterouter/qwen-pro",
messages=[{"role": "user", "content": "Write a haiku about retries."}],
)
print(resp.choices[0].message.content)
Node / TypeScript
npm install openai
import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://api.privaterouter.com/v1",
apiKey: process.env.OPENAI_API_KEY,
});
const resp = await client.chat.completions.create({
model: "privaterouter/qwen-pro",
messages: [{ role: "user", content: "Write a haiku about retries." }],
});
console.log(resp.choices[0].message.content);
Migrating from OpenAI / OpenRouter
There are only two changes:
- Set
base_urltohttps://api.privaterouter.com/v1. - Set
OPENAI_API_KEYto your PrivateRouterpr-…key.
Then swap any openai/gpt-* or openrouter/* model strings for the
privaterouter/* equivalents below. Streaming, tool calls, and JSON mode all
follow the OpenAI wire format unchanged.
Available models
| Model | Best for |
|---|---|
privaterouter/qwen-pro | General chat, long context, reasoning |
privaterouter/qwen-fast | Cheap & quick — drafts, classifiers |
privaterouter/deepseek-code | Code generation, autocomplete |
privaterouter/deepseek-reason | Multi-step reasoning, math |
privaterouter/embed | Embeddings (/v1/embeddings) |
Per-token rates and live availability are on the pricing page.
Streaming
Set stream: true. The response is a standard Server-Sent Events stream of
data: {…chunk…} lines terminated by data: [DONE], exactly as OpenAI emits.
stream = client.chat.completions.create(
model="privaterouter/qwen-pro",
messages=[{"role": "user", "content": "Count to five slowly."}],
stream=True,
)
for chunk in stream:
delta = chunk.choices[0].delta.content or ""
print(delta, end="", flush=True)
Rate limits
- Burst limit: 60 requests per minute per API key on
/v1/*endpoints. Exceeding it returns429 Too Many Requestswith aRetry-Afterheader (seconds). - Spend caps: Each plan has a monthly USD ceiling. Hitting it returns
402 Payment Required; top up at /billing or upgrade your plan. See the billing doc for full details on overage behaviour and Stripe top-ups.
Troubleshooting
| Status | Meaning | What to do |
|---|---|---|
401 | Missing or invalid API key | Re-check the Authorization: Bearer pr-… header. |
402 | Insufficient credits / spend cap reached | Top up at /billing or upgrade your plan. |
429 | Rate limit (60 RPM burst on /v1/*) | Honour the Retry-After header; back off and retry. |
503 | Requested model is temporarily unavailable | Retry shortly, or fall back to privaterouter/qwen-fast. |
Errors follow the OpenAI shape:
{
"error": {
"message": "You have exceeded your monthly spend cap.",
"type": "insufficient_quota",
"code": "spend_cap_reached"
}
}
Next steps
- API quickstart — full endpoint reference for
/v1/chat/completions,/v1/completions, and/v1/embeddings. - Billing & Stripe — plans, top-ups, and how invoicing works.
- Status — live health of the API, database, and GPU fleet.
Questions, bug reports, or stuck on something? Reach us at /contact.