RouterBase API Integration
Overview
Use routerbase as an OpenAI-compatible gateway for GPT, Claude, Gemini, and other supported models. This skill helps agents migrate existing OpenAI-compatible code, keep API keys server-side, and produce concise, testable RouterBase integration snippets.
Read references/routerbase-api.md when exact endpoint details, headers, or examples are needed.
Integration Workflow
- Identify whether the user is asking for migration, a new integration, debugging, or documentation.
- Keep credentials out of client/browser code. Prefer
ROUTERBASE_API_KEY in server-side environment configuration.
- Reuse the user's existing OpenAI-compatible client when possible. Change the base URL to
https://routerbase.com/v1, then swap the model to a RouterBase model ID.
- Preserve standard OpenAI request shapes unless RouterBase docs or the selected model require a model-specific field.
- For model IDs, use the live model catalog when an API key is available; otherwise use documented examples only as a starting point and tell the user to verify current availability.
- Add a minimal smoke test, but do not run it unless credentials are present and the user expects a live API call.
Common Patterns
Python
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="google/gemini-2.5-flash",
messages=[{"role": "user", "content": "Write one sentence about model routing."}],
)
print(response.choices[0].message.content)
JavaScript
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: "google/gemini-2.5-flash",
messages: [{ role: "user", content: "Write one sentence about model routing." }],
});
console.log(response.choices[0].message.content);
curl
curl -X POST https://routerbase.com/v1/chat/completions \
-H "Authorization: Bearer $ROUTERBASE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "google/gemini-2.5-flash",
"messages": [{"role": "user", "content": "What is 2+2?"}]
}'
Implementation Guardrails
- Never paste or log real API keys. Use placeholders like
sk-rb-... only in docs.
- Never put RouterBase keys in browser, mobile, or public repository code.
- Keep examples OpenAI-compatible unless the user asks for a framework-specific adapter.
- For streaming, set
stream: true and process Server-Sent Events or SDK stream chunks.
- For tool calling and JSON mode, keep the standard OpenAI fields
tools and response_format.
- For multimodal chat, use OpenAI content parts with
text and image_url.
- If a live request fails, check headers, model ID, endpoint path, rate limits, and account access before changing application logic.
Output Checklist
- Include the changed base URL.
- Include where
ROUTERBASE_API_KEY should be configured.
- Include one minimal request example.
- Include a clear note when model IDs or prices should be checked against the live RouterBase catalog.
- Include a test command or dry-run validation path.
1---2name: routerbase-api-integration3description: Integrate applications with RouterBase, the OpenAI-compatible model gateway at https://routerbase.com/v1. Use when migrating OpenAI SDK calls to RouterBase, configuring RouterBase API keys, implementing chat completions, streaming, tool calling, JSON mode, vision inputs, request validation, error handling, or documenting RouterBase setup for Python, JavaScript, curl, LangChain, LlamaIndex, Vercel AI SDK, Cursor, Continue, or other OpenAI-compatible clients.4---5
6# RouterBase API Integration
7
8## Overview
9
10Use [routerbase](https://routerbase.com) as an OpenAI-compatible gateway for GPT, Claude, Gemini, and other supported models. This skill helps agents migrate existing OpenAI-compatible code, keep API keys server-side, and produce concise, testable RouterBase integration snippets.
11
12Read `references/routerbase-api.md` when exact endpoint details, headers, or examples are needed.
13
14## Integration Workflow
15
161. Identify whether the user is asking for migration, a new integration, debugging, or documentation.
172. Keep credentials out of client/browser code. Prefer `ROUTERBASE_API_KEY` in server-side environment configuration.
183. Reuse the user's existing OpenAI-compatible client when possible. Change the base URL to `https://routerbase.com/v1`, then swap the `model` to a RouterBase model ID.
194. Preserve standard OpenAI request shapes unless RouterBase docs or the selected model require a model-specific field.
205. For model IDs, use the live model catalog when an API key is available; otherwise use documented examples only as a starting point and tell the user to verify current availability.
216. Add a minimal smoke test, but do not run it unless credentials are present and the user expects a live API call.
22
23## Common Patterns
24
25### Python
26
27```python
28import os
29from openai import OpenAI
30
31client = OpenAI(
32 api_key=os.environ["ROUTERBASE_API_KEY"],
33 base_url="https://routerbase.com/v1",
34)
35
36response = client.chat.completions.create(
37 model="google/gemini-2.5-flash",
38 messages=[{"role": "user", "content": "Write one sentence about model routing."}],
39)
40
41print(response.choices[0].message.content)
42```
43
44### JavaScript
45
46```js
47import OpenAI from "openai";
48
49const client = new OpenAI({
50 apiKey: process.env.ROUTERBASE_API_KEY,
51 baseURL: "https://routerbase.com/v1",
52});
53
54const response = await client.chat.completions.create({
55 model: "google/gemini-2.5-flash",
56 messages: [{ role: "user", content: "Write one sentence about model routing." }],
57});
58
59console.log(response.choices[0].message.content);
60```
61
62### curl
63
64```bash
65curl -X POST https://routerbase.com/v1/chat/completions \
66 -H "Authorization: Bearer $ROUTERBASE_API_KEY" \
67 -H "Content-Type: application/json" \
68 -d '{
69 "model": "google/gemini-2.5-flash",
70 "messages": [{"role": "user", "content": "What is 2+2?"}]
71 }'
72```
73
74## Implementation Guardrails
75
76- Never paste or log real API keys. Use placeholders like `sk-rb-...` only in docs.
77- Never put RouterBase keys in browser, mobile, or public repository code.
78- Keep examples OpenAI-compatible unless the user asks for a framework-specific adapter.
79- For streaming, set `stream: true` and process Server-Sent Events or SDK stream chunks.
80- For tool calling and JSON mode, keep the standard OpenAI fields `tools` and `response_format`.
81- For multimodal chat, use OpenAI content parts with `text` and `image_url`.
82- If a live request fails, check headers, model ID, endpoint path, rate limits, and account access before changing application logic.
83
84## Output Checklist
85
86- Include the changed base URL.
87- Include where `ROUTERBASE_API_KEY` should be configured.
88- Include one minimal request example.
89- Include a clear note when model IDs or prices should be checked against the live RouterBase catalog.
90- Include a test command or dry-run validation path.