Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 93 additions & 0 deletions External/routerbase-api-integration/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
---
name: routerbase-api-integration
description: 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.
metadata:
author: zenlee123
category: External
---

# RouterBase API Integration

## Overview

Use [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.

Read `references/routerbase-api.md` when exact endpoint details, headers, or examples are needed.

## Integration Workflow

1. Identify whether the user is asking for migration, a new integration, debugging, or documentation.
2. Keep credentials out of client/browser code. Prefer `ROUTERBASE_API_KEY` in server-side environment configuration.
3. 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.
4. Preserve standard OpenAI request shapes unless RouterBase docs or the selected model require a model-specific field.
5. 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.
6. 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

```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

```js
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

```bash
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.
130 changes: 130 additions & 0 deletions External/routerbase-api-integration/references/routerbase-api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
# RouterBase API Reference Notes

Use this reference for exact integration details. Prefer the live RouterBase documentation when making production claims.

## Product Facts

- RouterBase routes LLMs through one OpenAI-compatible API.
- The public docs describe the base URL as `https://routerbase.com/v1`.
- RouterBase positions itself as a drop-in replacement for the OpenAI SDK: change the client base URL and use a RouterBase API key.
- Publicly documented benefits include 200+ models, one API key, smart routing, automatic fallback, unified billing, and usage analytics.

Source pages:

- https://routerbase.com
- https://docs.routerbase.com
- https://docs.routerbase.com/api-reference/chat-completions

## Authentication

Every API request needs:

```http
Authorization: Bearer <YOUR_API_KEY>
Content-Type: application/json
```

Use `ROUTERBASE_API_KEY` in examples. Never place keys in frontend code.

## Core Endpoints

```text
POST https://routerbase.com/v1/chat/completions
POST https://routerbase.com/v1/images/generations
POST https://routerbase.com/v1/videos/generations
POST https://routerbase.com/v1/audio/speech
POST https://routerbase.com/v1/audio/generations
GET https://routerbase.com/api/v1/models
GET https://routerbase.com/api/v1/models/{model_id}
GET https://routerbase.com/api/v1/models/{model_id}/pricing
GET https://routerbase.com/api/v1/pricing
```

## Chat Completion Fields

Common OpenAI-compatible fields:

- `model`
- `messages`
- `temperature`
- `max_tokens`
- `top_p`
- `stream`
- `stop`
- `seed`
- `response_format`
- `presence_penalty`
- `frequency_penalty`
- `tools`
- `prompt_cache_key`

## Examples

Python:

```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": "What is 2+2?"}],
)
```

JavaScript:

```js
import OpenAI from "openai";

const client = new OpenAI({
apiKey: process.env.ROUTERBASE_API_KEY,
baseURL: "https://routerbase.com/v1",
});
```

Streaming:

```python
stream = client.chat.completions.create(
model="google/gemini-2.5-flash",
messages=[{"role": "user", "content": "Write a haiku"}],
stream=True,
)

for chunk in stream:
print(chunk.choices[0].delta.content or "", end="")
```

Vision content parts:

```json
{
"model": "google/gemini-2.5-flash",
"messages": [
{
"role": "user",
"content": [
{ "type": "text", "text": "What's in this image?" },
{ "type": "image_url", "image_url": { "url": "https://example.com/image.png" } }
]
}
]
}
```

## Validation

When debugging:

1. Confirm `ROUTERBASE_API_KEY` is set server-side.
2. Confirm `base_url` or `baseURL` is exactly `https://routerbase.com/v1`.
3. Confirm headers include bearer auth and JSON content type.
4. Confirm model ID exists in the live catalog.
5. Confirm the selected endpoint matches the model modality.
6. Check for rate-limit responses before adding fallback logic.
91 changes: 91 additions & 0 deletions External/routerbase-media-generation/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
---
name: routerbase-media-generation
description: Build image, video, and audio generation workflows on RouterBase. Use when calling RouterBase image, video, audio, speech, or media APIs; selecting media model IDs; handling synchronous image responses; polling asynchronous video or audio tasks; using callback URLs; storing generated media before retention expiry; or migrating OpenAI-compatible image generation calls to RouterBase.
metadata:
author: zenlee123
category: External
---

# RouterBase Media Generation

## Overview

Use [routerbase](https://routerbase.com) to access image, video, and audio generation models through one API. This skill helps agents choose the right media endpoint, handle sync versus async responses, and return production-safe integration guidance.

Read `references/routerbase-media.md` when exact endpoints, parameters, media retention notes, or example requests are needed.

## Media Workflow

1. Determine the modality: image, image edit/upscale, video, text-to-speech, music, or other audio.
2. Query or verify the current model ID for that modality. Prefer the live catalog when credentials are available.
3. Pick the endpoint:
- Image: `POST https://routerbase.com/v1/images/generations`
- Video: `POST https://routerbase.com/v1/videos/generations`
- Speech/audio: `POST https://routerbase.com/v1/audio/speech` or `POST https://routerbase.com/v1/audio/generations`
4. Decide sync behavior:
- Image generation is synchronous in RouterBase docs.
- Video and audio generation are asynchronous; poll task details by ID or supply a callback URL.
5. Download and persist generated files on the user's side. RouterBase docs describe generated image/video media retention as time-limited.
6. Add user-facing progress and retry handling for async media jobs.

## Image Example

```bash
curl -X POST https://routerbase.com/v1/images/generations \
-H "Authorization: Bearer $ROUTERBASE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "google/imagen-4",
"prompt": "A clean product-style illustration of an AI model router dashboard",
"aspect_ratio": "1:1",
"resolution": "1K"
}'
```

## Image-to-Image Example

```json
{
"model": "blackforestlabs/flux-2-pro-i2i",
"prompt": "Make the source image look like a polished watercolor editorial illustration",
"image_urls": ["https://example.com/source.jpg"]
}
```

## Async Video Or Audio Pattern

```js
const create = await fetch("https://routerbase.com/v1/videos/generations", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.ROUTERBASE_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
model: "google/veo-3-1-fast",
prompt: "A 5-second shot of abstract network routes lighting up on a dark map",
}),
});

const task = await create.json();
// Poll GET /v1/videos/generations/{id} until the task reaches a terminal status.
```

Use a callback URL when the application already has a durable webhook receiver. Otherwise, poll with backoff and a clear timeout.

## Production Guardrails

- Keep media prompts and input image URLs appropriate for the user's rights and product policy.
- Store generated media before retention expiry.
- Validate `aspect_ratio`, `resolution`, `quality`, `style`, `negative_prompt`, and `image_urls` against the selected model's supported fields.
- Treat model-specific parameters as model-dependent; do not assume every image model honors every option.
- For async tasks, persist the task ID, request payload hash, created time, status, result URLs, and error details.
- Avoid sending real API keys, private media URLs, or user data into logs.

## Output Checklist

- Name the modality and endpoint.
- Include a current model ID or say that the model ID must be verified.
- Include sync/async handling.
- Include storage and retention handling.
- Include a minimal request example and a validation step.
Loading