Quickstart
Make your first RouterBase request.
RouterBase exposes an OpenAI-compatible base URL, so you can use familiar SDKs and request shapes across the supported model catalog.
Before you start
You need a RouterBase API key and a model ID from the live model catalog.
Keep API keys server-side.
Store your key in an environment variable. Never commit it to a repository or expose it in browser code.
export ROUTERBASE_API_KEY="your_api_key"
export ROUTERBASE_MODEL="your_model_id"
Node.js
Install the official OpenAI JavaScript SDK:
npm install openai
Create index.mjs:
import OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.ROUTERBASE_API_KEY,
baseURL: "https://routerbase.com/v1",
});
const response = await client.chat.completions.create({
model: process.env.ROUTERBASE_MODEL,
messages: [{ role: "user", content: "Explain API routing in one sentence." }],
});
console.log(response.choices[0].message.content);
Run it with node index.mjs.
Python
Install the official OpenAI Python SDK:
python -m pip install openai
Create main.py:
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["ROUTERBASE_API_KEY"],
base_url="https://routerbase.com/v1",
)
response = client.chat.completions.create(
model=os.environ["ROUTERBASE_MODEL"],
messages=[{"role": "user", "content": "Explain API routing in one sentence."}],
)
print(response.choices[0].message.content)
Run it with python main.py.
cURL
Call the chat completions endpoint without installing an SDK:
curl https://routerbase.com/v1/chat/completions \
-H "Authorization: Bearer $ROUTERBASE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "'"$ROUTERBASE_MODEL"'",
"messages": [
{"role": "user", "content": "Explain API routing in one sentence."}
]
}'
Find a model ID
Model availability changes over time. Use the live catalog or the models endpoint instead of hard-coding an ID copied from an old example.