Routerbase Model Gateway logo

Routerbase Model Gateway

Organization
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.

Overview

Publishercosmicstack-labs
Repositorymercury-agent-skills
Skill namerouterbase-model-gateway
Stars
485
Forks
63
Bundled files
Instructions only
LicenseMIT
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • Self-contained

    Everything the model needs lives in the instructions — no extra files to sync.

  • Open source

    Published by cosmicstack-labs on GitHub. Read the source before you install it.

Installation

Install the Routerbase Model Gateway AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/cosmicstack-labs/mercury-agent-skills/tree/main/categories/ai-ml/routerbase-model-gateway
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/cosmicstack-labs/mercury-agent-skills.git /tmp/mercury-agent-skills
mkdir -p .claude/skills
cp -r /tmp/mercury-agent-skills/categories/ai-ml/routerbase-model-gateway .claude/skills/routerbase-model-gateway
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Routerbase Model Gateway in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Routerbase Model Gateway on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Routerbase Model Gateway is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

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.

When To Use

Use this skill when the user asks to:

  • Migrate an OpenAI compatible client to RouterBase.
  • Add RouterBase to a backend API, worker, command line tool, or agent runtime.
  • Route requests across multiple model providers through one API surface.
  • Choose primary and fallback models for latency, quality, price, or availability.
  • Add image, video, audio, speech, or embedding generation through a gateway.
  • Debug RouterBase base URLs, model IDs, streaming, JSON output, or media job polling.

Do not use this skill for:

  • General API gateway design unrelated to AI models.
  • Direct provider SDK features that are not exposed through the OpenAI compatible API.
  • Frontend only integrations that would expose API keys to users.
  • Production security review of the whole application.

Implementation Principles

1. Keep The Gateway Server Side

All RouterBase calls should run in trusted code:

  • backend route
  • serverless function
  • worker
  • command line tool
  • internal service
  • agent runtime process

Never place ROUTERBASE_API_KEY in browser code, mobile applications, public logs, screenshots, or checked in examples.

2. Change Configuration Before Code Shape

Most migrations should start with configuration:

  • base URL: https://routerbase.com/v1
  • API key variable: ROUTERBASE_API_KEY
  • chat model variable: ROUTERBASE_CHAT_MODEL
  • embedding model variable: ROUTERBASE_EMBEDDING_MODEL
  • media model variables for image, video, audio, or speech

Keep the OpenAI compatible request shape until there is a documented reason to change it.

3. Isolate Provider Choices

Do not scatter model IDs across product code. Put them in one adapter, config file, or environment mapping.

Good boundaries:

  • aiClient.ts
  • modelConfig.ts
  • llmGateway.ts
  • services/ai/routerbase.ts

Poor boundaries:

  • hard coded model IDs in every route
  • retries implemented differently in every feature
  • media polling mixed into UI code
  • provider errors returned directly to users

Quick Start Example

ts
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 || "";
}

Routing Checklist

Before choosing models, answer these questions:

  1. What is the workload: chat, JSON output, streaming, tools, embeddings, image, video, audio, or speech?
  2. What matters most: latency, output quality, cost, context length, availability, or modality support?
  3. Does the fallback model return the same output shape?
  4. Can the feature tolerate degraded quality, or should it fail closed?
  5. Are user prompts, uploaded files, or generated assets subject to privacy rules?
  6. What telemetry is needed: model ID, request ID, latency, status code, retry count, and fallback used?
  7. What should the user see when the primary model fails?

Fallback Pattern

Use fallbacks for availability, not to hide every error.

ts
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:

  • the error is temporary or provider specific
  • the fallback model supports the same output contract
  • the request does not require a provider that has a unique compliance rule
  • the user experience is better with degraded output than with a clear failure

Media Generation Flow

Treat long running media as a job workflow, not as a chat completion.

  1. Validate the prompt and user permissions.
  2. Create a media generation job through the RouterBase compatible endpoint for the selected modality.
  3. Store the job ID, model ID, user ID, and requested output type.
  4. Poll with backoff instead of holding one long request open.
  5. Save generated assets to durable storage.
  6. Return a stable URL or asset reference to the user.
  7. Record failures with model ID, status code, and retry count.

Evaluation Rubric

Score the integration from 0 to 2 for each item.

Area012
Credential handlingkey exposed or hard codedkey is server side but examples are unclearkey is server side, documented, and scanned
Model configurationIDs scattered in codecentral config for some workloadscentral config for all workloads
Fallback designno fallback or unsafe fallbackfallback exists without clear policyfallback policy is explicit and tested
Error handlingprovider errors leak to userscommon errors mappedauth, quota, rate, timeout, and model errors handled
Media workflowsynchronous long requestpolling exists but storage is weakjob, polling, storage, and status are separate
Observabilityno useful logsbasic latency and status logsrequest ID, model ID, fallback, retry count, latency

Recommended threshold before production: at least 10 out of 12.

Common Mistakes

  • Putting RouterBase keys in frontend environment variables that are bundled for users.
  • Hard coding one model ID in multiple product features.
  • Assuming streaming and non streaming responses fail in the same way.
  • Falling back to a model with a different JSON output contract.
  • Treating image or video generation as a simple request response call.
  • Logging full prompts, uploaded file contents, or generated private data.
  • Retrying authentication or quota errors that should fail immediately.
  • Returning raw provider error messages to end users.

Output Expectations

When completing a RouterBase task, provide:

  • files changed
  • environment variables required
  • primary and fallback model IDs
  • test or smoke check performed
  • privacy notes for prompts, files, and generated assets
  • any unsupported features or assumptions

Keep the final recommendation concise. Include code only where it changes the integration boundary.

Frequently asked questions

What does the Routerbase Model Gateway AI skill do?

Configure RouterBase as an OpenAI compatible model gateway for AI apps, with routing, fallback, media generation, and credential handling patterns.

Why use Routerbase Model Gateway on TypingMind?

Because you install it once and use it with any model. Routerbase Model Gateway is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Routerbase Model Gateway in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/cosmicstack-labs/mercury-agent-skills/tree/main/categories/ai-ml/routerbase-model-gateway. TypingMind reads its SKILL.md and installs it as a skill you can enable per chat.

Which AI models can use Routerbase Model Gateway?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Routerbase Model Gateway?

As many as you like. As long as a model supports skills, you can use Routerbase Model Gateway with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Routerbase Model Gateway AI skill free?

Yes. It is published on GitHub by cosmicstack-labs under the MIT license. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇