Everything you need to understand, configure, and operate ModelRouter.
Get up and running with ModelRouter in four steps.
POST /v1/providers/test or the Settings page.
Every request passes through a multi-stage pipeline running at the edge on Fastly Compute.
Auth Check: Validates the Bearer token against the secret store. Rejects unauthorized requests immediately.
Injection Check: Runs 30+ regex/heuristic patterns against the prompt content. Produces a 0.0-1.0 injection score. Prompts above the threshold (default 0.5) are blocked before any LLM call.
Custom Rules: Evaluates user-defined blocking rules stored in the KV store. Rules support contains, regex, starts_with, equals, and not_contains operators with AND/OR/NOT logic.
Cache Check: Looks up an exact-match cache key (hash of model + messages + temperature). SimpleCache is per-POP with microsecond latency. KV Store is global with millisecond latency.
Detect Modality: Scans message content for images (OpenAI image_url format), OCR requests, image generation prompts ("create an image", "generate a picture"), and code blocks. Detected modality determines which capability filters apply during routing.
Classify: Analyzes prompt complexity to assign one of 9 tiers (fast, balanced, quality, reasoning, code, vision, ocr, image_gen, embedding). Uses keyword heuristics, question detection, code block detection, image detection, and content analysis.
Route: Scores all 26 available models for the assigned tier using user preference weights (cost, speed, quality) and internal quality rankings (Claude Opus 4 at the top, down through GPT-5.4, Claude Sonnet 4, DeepSeek R1, GPT-4o, and so on). Models without the required capability (e.g., vision, ocr, image_gen) are automatically excluded. Picks the highest-scoring model from connected providers with a fallback chain if the primary provider fails.
Audit Log: Writes a fire-and-forget entry to the KV store keyed by tenant and date. Zero added latency to the response.
Every prompt goes through a two-stage process: first the prompt is classified into a tier, then the best model within that tier is selected based on your preference weights. No LLM is used for classification -- it runs deterministic heuristics in microseconds.
Models are ranked by overall quality. These rankings are used as one of three factors (alongside cost and speed) when scoring models within a tier:
When a prompt arrives, ModelRouter reads it and decides what kind of work it is. The classifier runs through checks in priority order -- the first match wins:
Once the tier is chosen, ModelRouter scores each available model in that tier using your preference weights (the cost, speed, and quality sliders):
Models are ranked 0 to 1 within their tier for each dimension. The highest-scoring model wins.
Additional constraints:
A user sends: "Write a Python function to sort a list"
ModelRouter reads each message's content blocks. In the OpenAI format, a message can contain multiple content blocks:
If any content block has type image_url or image, the prompt is classified as VISION. This overrides all other classification -- even if the text says "write code", the presence of an image means vision routing.
Within the VISION tier, only models with vision capability are considered:
If the text also contains OCR keywords ("extract text", "read the text", "OCR"), it is classified as OCR instead, which routes to specialized OCR models like Mistral OCR and DeepSeek OCR that preserve table structure, formulas, and layout.
ModelRouter doesn't just route to the biggest model. It routes to the right model.
Sending OCR to GPT-4o is like using a bulldozer to plant a flower. Mistral OCR is purpose-built for document parsing -- it's more accurate, 10x cheaper, and preserves structure (tables, formulas) that GPT-4o flattens.
Sending image generation to DALL-E 3 ignores that FLUX.1 Pro generates higher-quality images in less time at lower cost.
This is the core value of ModelRouter: you don't need to know which model is best for each task. We do.
ModelRouter automatically detects content type in your prompts and routes to models with the required capabilities. Models that lack a required capability (e.g., vision) are automatically excluded from selection.
Include images using the OpenAI image_url content block format. ModelRouter detects the image and routes to vision-capable models (GPT-4o, Claude Sonnet 4).
When your prompt includes an image and mentions text extraction keywords (e.g., "extract text", "read the text", "OCR"), ModelRouter routes to purpose-built OCR models. Mistral OCR is the primary choice -- a specialized document parser that achieves state-of-the-art accuracy at $0.002/page, preserving table structure, formulas, and layout that general-purpose models lose. DeepSeek OCR is available as a lower-cost alternative, with GPT-4o as a fallback. The detection is automatic — no special flags needed.
Prompts requesting image creation (e.g., "create an image of...", "generate a picture", "draw a...") are automatically routed to FLUX models via Together AI. FLUX.1 Schnell (free) generates images in ~2 seconds. FLUX.1 Pro matches or exceeds DALL-E 3 quality at lower cost with faster generation. DALL-E 3 is available as a fallback. No model override needed — just describe what you want.
Prompts containing code blocks, programming keywords, or debugging requests are routed to code-optimized models like DeepSeek Coder.
| Provider | Text | Vision | OCR | Image Gen | Code | Reasoning |
|---|---|---|---|---|---|---|
| OpenAI (GPT-4o) | Yes | Yes | Fallback | DALL-E 3 | Yes | Yes |
| Anthropic (Claude Sonnet 4) | Yes | Yes | — | — | Yes | Yes |
| Anthropic (Claude Opus 4) | Yes | — | — | — | Yes | Yes |
| Groq | Yes | — | — | — | — | — |
| Together AI (FLUX) | Yes | — | — | FLUX.1 | Yes | — |
| Mistral (OCR) | Yes | — | Primary | — | — | — |
| DeepSeek | Yes | — | Yes | — | Yes | Yes |
| Ollama | Yes | — | — | — | — | — |
Capability filtering: When a modality is detected (vision, OCR, image generation), models without that capability are automatically excluded from routing. This ensures your request always reaches a model that can handle it.
All models available through ModelRouter, organized by provider. BYOK: you bring your own API keys, we route. Models only appear in GET /v1/models when you have the provider's key connected.
| Model | Provider | Tier | Capabilities | Input Cost | Output Cost | Pricing |
|---|---|---|---|---|---|---|
| Ollama (self-hosted, 6 models) | ||||||
| llama3.2:latest | Ollama | Fast | text | $0 | $0 | INCLUDED |
| phi3:latest | Ollama | Fast | text | $0 | $0 | INCLUDED |
| qwen2.5:latest | Ollama | Fast | text | $0 | $0 | INCLUDED |
| glm4:latest | Ollama | Fast | text | $0 | $0 | INCLUDED |
| gpt-oss:latest | Ollama | Fast | text | $0 | $0 | INCLUDED |
| nomic-embed-text | Ollama | Embedding | embedding | $0 | $0 | INCLUDED |
| OpenAI (paid, 5 models) | ||||||
| gpt-4o-mini | OpenAI | Balanced | text vision | $0.15/1M | $0.60/1M | PAID |
| gpt-4o | OpenAI | Quality | text vision ocr code | $2.50/1M | $10/1M | PAID |
| gpt-5.4 | OpenAI | Reasoning | text code reasoning | $5/1M | $20/1M | PAID |
| o3-mini | OpenAI | Reasoning | text reasoning | $1.10/1M | $4.40/1M | PAID |
| text-embedding-3-small | OpenAI | Embedding | embedding | $0.02/1M | — | PAID |
| Anthropic (paid, 2 models) | ||||||
| claude-sonnet-4-20250514 | Anthropic | Quality | text vision ocr code | $3/1M | $15/1M | PAID |
| claude-opus-4-20250514 | Anthropic | Reasoning | text code reasoning | $15/1M | $75/1M | PAID |
| Groq (included tier, 2 models) | ||||||
| llama-3.3-70b-versatile | Groq | Balanced | text | $0 | $0 | INCLUDED |
| gemma2-9b-it | Groq | Fast | text | $0 | $0 | INCLUDED |
| Together AI (200+ models, 5 featured) | ||||||
| meta-llama/Llama-3.3-70B-Instruct-Turbo | Together AI | Balanced | text | $0.88/1M | $0.88/1M | INCLUDED |
| mistralai/Mixtral-8x7B-Instruct-v0.1 | Together AI | Balanced | text | $0.60/1M | $0.60/1M | INCLUDED |
| togethercomputer/CodeLlama-34b-Instruct | Together AI | Code | text code | $0.78/1M | $0.78/1M | INCLUDED |
| black-forest-labs/FLUX.1-schnell-Free | Together AI | Image Gen | image_gen | $0 | $0 | INCLUDED |
| black-forest-labs/FLUX.1-pro | Together AI | Image Gen | image_gen | $50/1M | — | PAID |
| Mistral (included tier, 3 models) | ||||||
| mistral-small-latest | Mistral | Fast | text | $0 | $0 | INCLUDED |
| mistral-large-latest | Mistral | Quality | text | $0 | $0 | INCLUDED |
| mistral-ocr-latest | Mistral | OCR | ocr vision | $1/1M | — | PAID |
| DeepSeek (included tier, 5 models) | ||||||
| deepseek-chat | DeepSeek | Balanced | text | $0.14/1M | $0.28/1M | INCLUDED |
| deepseek-v4 | DeepSeek | Quality | text | $0.27/1M | $1.10/1M | INCLUDED |
| deepseek-reasoner | DeepSeek | Reasoning | text reasoning | $0.55/1M | $2.19/1M | INCLUDED |
| deepseek-coder | DeepSeek | Code | text code | $0.14/1M | $0.28/1M | INCLUDED |
| deepseek-ocr | DeepSeek | OCR | ocr vision | $0.03/1M | — | INCLUDED |
BYOK: You bring your own API keys and pay providers directly. ModelRouter adds no markup to token costs. Ollama models run on your own hardware at zero cost. Groq, Together AI, Mistral, and DeepSeek all offer included tiers with their API keys.
ModelRouter runs a multi-layer security pipeline at the edge before any prompt reaches an LLM.
The injection detector scans every prompt against a library of heuristic patterns covering:
<system> tags, markdown separators used to inject fake system messagesEach pattern contributes a weighted score. The combined injection score (0.0 to 1.0) determines whether the prompt is blocked. Default threshold: 0.5.
Beyond automatic injection detection, you can define custom rules with flexible logic:
Rules are stored in the KV store and evaluated at every edge PoP. Create and test rules on the Rules page.
Use custom rules as a DLP layer to prevent sensitive data from leaving your organization through AI prompts:
\b\d{3}-\d{2}-\d{4}\b blocks Social Security Numbers.DLP rules run at the edge in <1ms and block before any data reaches an external LLM provider.
Every request is logged with: timestamp, provider, model, injection score, cache status, latency, token usage, and HTTP status. Logs are keyed by tenant and date in the KV store. Full visibility into which employees are using AI, what they are asking, and which models are being invoked. View and export logs on the Logging page.
ModelRouter uses two complementary caching layers to minimize LLM API calls and costs.
SimpleCache is a local in-memory cache at each Fastly edge Point of Presence (PoP). Lookups complete in microseconds. If a user at the same PoP asks the same question, the response is served instantly from memory without any network calls.
The KV Store is a globally distributed key-value database. If the SimpleCache misses, ModelRouter checks the KV Store. KV lookups take milliseconds and work across all PoPs worldwide. This means a cache entry written in San Francisco is readable in Tokyo.
temperature=0 (deterministic output)stream=true) are not cachedCost impact: Every cache hit is a $0 LLM call. At a 50% hit rate on 10,000 daily requests using GPT-4o, caching saves approximately $150/day in API costs. Cache hits also return in under 1ms vs 500ms+ for live LLM calls.
Define custom blocking rules that are deployed instantly to every edge PoP via the KV store. No service redeploy needed.
| Operator | Behavior | Example Value |
|---|---|---|
| contains | Case-insensitive substring match | social security |
| not_contains | Passes if substring is NOT found | approved |
| regex | Regular expression match | \b\d{3}-\d{2}-\d{4}\b |
| starts_with | Checks if field starts with value | SYSTEM: |
| equals | Exact string match | admin |
ModelRouter is designed to support multi-tenant deployments where each customer gets isolated resources and configuration.
Multi-tenancy is on the roadmap for a future release. The current single-tenant architecture already supports isolated KV namespacing. Contact jacob.rosenbacher@gmail.com for early access to multi-tenant features.