cosmicstack-labs/routerbase-model-gateway
Configure RouterBase as an OpenAI compatible model gateway for AI apps, with routing, fallback, media generation, and credential handling patterns.
npx skills add https://github.com/cosmicstack-labs/mercury-agent-skills --skill routerbase-model-gateway
Use routerbase when an application needs an OpenAI compatible gateway for chat, embeddings, image, video, audio, speech, model routing, or fallback behavior.
The goal is not to rewrite the whole AI layer. The goal is to move provider selection behind a clean server side boundary, keep credentials private, and make model choices reversible.
Use this skill when the user asks to:
Do not use this skill for:
All RouterBase calls should run in trusted code:
Never place ROUTERBASE_API_KEY in browser code, mobile applications, public logs, screenshots, or checked in examples.
Most migrations should start with configuration:
https://routerbase.com/v1ROUTERBASE_API_KEYROUTERBASE_CHAT_MODELROUTERBASE_EMBEDDING_MODELKeep the OpenAI compatible request shape until there is a documented reason to change it.
Do not scatter model IDs across product code. Put them in one adapter, config file, or environment mapping.
Good boundaries:
aiClient.tsmodelConfig.tsllmGateway.tsservices/ai/routerbase.tsPoor boundaries:
import OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.ROUTERBASE_API_KEY,
baseURL: process.env.ROUTERBASE_BASE_URL || "https://routerbase.com/v1",
});
export async function summarizeReleaseNote(text: string) {
const completion = await client.chat.completions.create({
model: process.env.ROUTERBASE_CHAT_MODEL || "openai/gpt-5.4-mini",
messages: [
{ role: "system", content: "Summarize clearly for product engineers." },
{ role: "user", content: text },
],
});
return completion.choices[0]?.message?.content || "";
}
Before choosing models, answer these questions:
Use fallbacks for availability, not to hide every error.
async function runWithFallback(messages: OpenAI.Chat.Completions.ChatCompletionMessageParam[]) {
const primary = process.env.ROUTERBASE_CHAT_MODEL || "openai/gpt-5.4-mini";
const fallback = process.env.ROUTERBASE_CHAT_FALLBACK_MODEL || "openai/gpt-5.4-mini";
try {
return await client.chat.completions.create({ model: primary, messages });
} catch (error) {
if (!isRetryableModelError(error)) throw error;
return client.chat.completions.create({
model: fallback,
messages,
});
}
}
Fallback only when:
Treat long running media as a job workflow, not as a chat completion.
Score the integration from 0 to 2 for each item.
| Area | 0 | 1 | 2 |
|---|---|---|---|
| Credential handling | key exposed or hard coded | key is server side but examples are unclear | key is server side, documented, and scanned |
| Model configuration | IDs scattered in code | central config for some workloads | central config for all workloads |
| Fallback design | no fallback or unsafe fallback | fallback exists without clear policy | fallback policy is explicit and tested |
| Error handling | provider errors leak to users | common errors mapped | auth, quota, rate, timeout, and model errors handled |
| Media workflow | synchronous long request | polling exists but storage is weak | job, polling, storage, and status are separate |
| Observability | no useful logs | basic latency and status logs | request ID, model ID, fallback, retry count, latency |
Recommended threshold before production: at least 10 out of 12.
When completing a RouterBase task, provide:
Keep the final recommendation concise. Include code only where it changes the integration boundary.
Take cosmicstack-labs/routerbase-model-gateway from the repository into ~/.claude/skills for personal
use, or into .claude/skills inside a project.
The agent identifies a skill by the name field in its header. Two skills with the
same name cannot sit side by side — one of them will be ignored.