Try Bifrost Enterprise free for 14 days.
Request access
[ BIFROST ROUTERS ]

LLM Router:
Send Every Request to the Right Model

Bifrost classifies each request as Simple, Medium or Complex and sends it to the model you choose for that tier. Easy requests go to a fast model, hard ones to a stronger model, and your application code does not change.

Open Source | Self-Hosted | No Code Changes
3Complexity tiers
Simple, Medium and Complex, each with its own model.
3Classifiers
A decision model, semantic matching, or an LLM.
0Code changes
Applications keep calling the same API. The router picks the model.
5Routing scopes
Virtual key, user, team, customer or global.

[ DEFINITION ]

What Is an LLM Router?

An LLM router decides which model answers each request, so the choice no longer lives in application code. In Bifrost, a router classifies every request by complexity and sends each tier to its own model. You can run several routers side by side, each with its own classifier settings, models and traffic figures.

Classifier

Assigns each request a tier: Simple, Medium or Complex. Choose a decision model, semantic matching, or an LLM classifier.

Models

The model each tier sends to. A tier can split traffic across several weighted models, each with its own API key and fallbacks.

Routing

Which requests the router takes: a scope, a priority, an optional CEL condition, and an on/off switch.

[ HOW IT WORKS ]

How Model Routing Works in Bifrost

Every request follows the same five steps. A router needs no routing rules of its own: once it is on, it classifies matching requests and routes them.

  1. 01

    Routing rules run first

    The router takes the request as your existing routing rules left it.

  2. 02

    Routers are tried in scope order

    Virtual key, user, team, customer, then global. Within a scope, the lower priority goes first, and only routers that are on are tried.

  3. 03

    The first matching router takes the request

    Its condition must hold. Each router classifies a request at most once.

  4. 04

    The request goes to the tier's model

    When a tier has several models, Bifrost makes a weighted pick between them.

  5. 05

    Key allowlists and load balancing run last

    The virtual key's provider allowlist and load balancing still apply to the routed request.

A request keeps the model it asked for when no router matches, the router cannot classify it, or the tier has no model.

[ CLASSIFIERS ]

Three Classifiers: Decision Model, Semantic or LLM

Each router uses one classifier, and you can combine them: run semantic routing first and let a decision model answer only the requests no phrase matches confidently.

Decision modelSemanticLLM classifier
How it decidesA decision model picks the tier whose definition, signals and examples fit bestEmbeds the request and takes the tier of the nearest reference phraseA chat model reads the request with a classification prompt and replies with a tier
What you maintainNothing to start. Optionally a definition, signals and examples per tierReference phrases per tier: 150 shipped, up to 750Nothing to start. Optionally the prompt
Cost per requestOne decision call. Typesafe Jev typically answers in 600 to 800 msOne embedding call plus a vector lookup, usually much faster than a decision callOne chat completion, the slowest of the three
WarmupNonePhrases are embedded in the background after each changeNone
Best whenYou want good tiers without curating data, or traffic is variedTraffic is predictable, latency matters most, and you want exact control through examplesYou want to describe tiers in your own words and can afford a chat call per request

Complexity Tiers You Can Edit

The decision model reads a definition, signals and examples for every tier on every request, and you can rewrite any of them.

  • Ships with working defaults for Simple, Medium and Complex
  • It judges the work, not the wording: length, format and tone do not count
  • Typesafe Jev is the default decision model, with OpenAI, Gemini, OpenRouter, Cloudflare, Perplexity, Ollama, Azure, Databricks or a custom provider as alternatives
  • A confidence threshold leaves low-confidence requests on the model they asked for

Semantic Routing with Reference Phrases

The semantic classifier embeds the latest user message and uses the tier of the nearest reference phrase.

  • 150 reference phrases shipped, 50 per tier, and up to 750 of your own
  • A similarity floor decides when the nearest phrase is not close enough
  • A decision model or an LLM can answer as a fallback when no phrase matches
  • System prompts and assistant replies are never embedded

One Model per Tier, with Weights and Fallbacks

Pick the model for each tier, or split a tier across several.

  • Each target sets a provider, a model, or both, with an optional API key
  • Weights split a tier across models, and the weights in a tier sum to 1
  • Fallbacks are set per target, so each tier has its own chain
  • Leave the provider or the model empty to keep what the request asked for

Session-Aware Routing

Keep a conversation on a model strong enough for its hardest turn.

  • A session's tier can rise from Simple to Medium to Complex, but never falls
  • Once a session reaches Complex, Bifrost stops classifying it
  • Sessions are identified by the x-bf-session-id header, and Claude Code and Codex sessions are recognized automatically
  • Only the tier is stored, under a hashed session ID, for 24 hours of inactivity

Logs, Traces and Metrics for Every Routing Decision

See which router took a request, the tier it got, and how that tier was decided.

  • Each log entry records the router, the tier and the mechanism: semantic, decision, llm, session or skipped
  • Filter request logs by router and by tier
  • Span attributes carry the tier, mechanism and score into your traces
  • Prometheus counters track classifier requests and their cost

[ SETUP ]

Set Up an LLM Router in Four Steps

Use the dashboard, the /api/routing/model-routers API, or a model_routers entry in config.json.

  1. 01

    Create a router

    In the dashboard, open Models, then Routers, then New router. Give it a name and pick a classifier: Decision model, Semantic or LLM classifier.

  2. 02

    Pick a model for each tier

    On the Models tab, set a provider and model for Simple, Medium and Complex. Add weights to split a tier across models, and fallbacks per target.

  3. 03

    Set the routing

    Choose a scope and priority, and add a CEL condition if the router should only take some requests. An empty condition takes every request in scope.

  4. 04

    Test, then turn it on

    New routers start off. Send sample requests to the classify endpoint to see the tier and model each would get, then switch the router on.

config.json
{
  "model_routers": [
    {
      "id": "general",
      "name": "General",
      "classifier": "decision",
      "decision": { "provider": "typesafe", "model": "jev-latest" },
      "session": { "enabled": true },
      "keywords": {
        "simple_keywords": ["fix the grammar in this sentence."],
        "medium_keywords": ["apply a standard method to this technical question."],
        "complex_keywords": ["design a solution under several competing constraints."]
      },
      "targets": [
        { "tier": "SIMPLE", "provider": "groq", "model": "llama-3.1-8b-instant", "weight": 1 },
        { "tier": "MEDIUM", "provider": "openai", "model": "gpt-4o-mini", "weight": 1 },
        { "tier": "COMPLEX", "provider": "anthropic", "model": "claude-opus-4-5", "weight": 1 }
      ],
      "routing": { "enabled": true, "scope": "global", "priority": 0 }
    }
  ]
}

The three-tier example from the Routers docs: one decision-model router with a different provider for each tier.

[ COVERAGE ]

Which Requests the Router Can Classify

The router classifies text requests. Anything it cannot classify keeps the model it asked for.

Classified

  • Chat Completions and messages-style requests with text-only user content
  • Text Completions with a prompt
  • Responses API requests with text-only input
  • Anthropic Messages, Bedrock Converse and Gemini requests with text-only user input

Not classified

  • Image generation, embeddings, rerank, OCR, audio, video and count-tokens requests
  • User content that mixes text with image, file or audio blocks
  • Requests with only a system or developer message
  • Requests in large payload mode, which skip routers entirely

Route Your Own Traffic by Complexity

Run Bifrost with npx -y @maximhq/bifrost, create a router, and test it on sample requests before it takes any traffic. Read more on how model routing cuts token costs.

[ BIFROST FEATURES ]

Open Source & Enterprise

Everything you need to run AI in production, from free open source to enterprise-grade features.

01 Governance

SAML support for SSO and Role-based access control and policy enforcement for team collaboration.

02 Adaptive Load Balancing

Automatically optimizes traffic distribution across provider keys and models based on real-time performance metrics.

03 Cluster Mode

High availability deployment with automatic failover and load balancing. Peer-to-peer clustering where every instance is equal.

04 Alerts

Real-time notifications for budget limits, failures, and performance issues on Email, Slack, PagerDuty, Teams, Webhook and more.

05 Log Exports

Export and analyze request logs, traces, and telemetry data from Bifrost with enterprise-grade data export capabilities for compliance, monitoring, and analytics.

06 Audit Logs

Comprehensive logging and audit trails for compliance and debugging.

07 Vault Support

Secure API key management with HashiCorp Vault, AWS Secrets Manager, Google Secret Manager, and Azure Key Vault integration.

08 VPC Deployment

Deploy Bifrost within your private cloud infrastructure with VPC isolation, custom networking, and enhanced security controls.

09 Guardrails

Automatically detect and block unsafe model outputs with real-time policy enforcement and content moderation across all agents.

[ SHIP RELIABLE AI ]

Try Bifrost Enterprise with a 14-day Free Trial

[quick setup]

Drop-in replacement for any AI SDK

Change just one line of code. Works with OpenAI, Anthropic, Vercel AI SDK, LangChain, and more.

1import os
2from anthropic import Anthropic
3
4anthropic = Anthropic(
5 api_key=os.environ.get("ANTHROPIC_API_KEY"),
6 base_url="https://<bifrost_url>/anthropic",
7)
8
9message = anthropic.messages.create(
10 model="claude-3-5-sonnet-20241022",
11 max_tokens=1024,
12 messages=[
13 {"role": "user", "content": "Hello, Claude"}
14 ]
15)
Drop in once, run everywhere.

[ FAQ ]

LLM Router FAQs

Common questions about routing LLM requests by complexity.

An LLM router is a layer that decides which model should answer each request, instead of the application hard-coding one model. Bifrost's router classifies every request as Simple, Medium or Complex and sends it to the model you chose for that tier, so easy requests go to a fast, low-cost model and hard ones go to a stronger model. For a longer explainer, read what an LLM router is and how model routing works.

You pick one of three classifiers per router. A decision model compares the request with a definition, signals and examples for each tier. The semantic classifier embeds the request and takes the tier of the nearest reference phrase. An LLM classifier asks a chat model to reply with a tier. All three judge the latest user request, and the decision model is instructed to judge the work rather than the wording, so length, format and tone do not count. Details are in the Routers docs.

Bifrost is an open-source AI gateway under Apache 2.0, and routers are documented as a core gateway feature that you configure in the dashboard, the API or config.json. The Routers docs mark a few parts as Enterprise: the user routing scope in the dashboard, the Routers permission and data access control, and audit log events. The source is on GitHub.

The classifier call sits on the request path, so its latency is added to every classified request. The default decision model, Typesafe Jev, typically answers in 600 to 800 ms. The semantic classifier makes one embedding call plus a vector lookup and is usually much faster. An LLM classifier is the slowest of the three. Each has a timeout (1.5s for the decision model and semantic, 4s for the LLM classifier by default), and a request that times out keeps the model it asked for.

Semantic routing picks a route by meaning instead of keywords, and a semantic router is the component that does it. In Bifrost that is the semantic classifier: it embeds the latest user message, compares it with reference phrases you keep for each tier, and uses the tier of the nearest phrase. It ships with 150 phrases, 50 per tier, and accepts up to 750. When no phrase matches above your similarity floor, a decision model or an LLM can answer as a fallback.

The request keeps the model it asked for and is served normally. That happens when no router matches, the classifier fails, times out or returns an answer below your confidence threshold, or the tier has no model. The request log records the reason, with complexity_mechanism set to skipped.

No. A router that is on classifies matching requests and sends each one to its tier's model with no application changes. Applications keep calling Bifrost through the same OpenAI-compatible API, and the LLM gateway handles keys, fallbacks and load balancing after the router has chosen a model.