To maximize efficiency and cost savings, LLM Router requires you to define strict rules about which models handle specific types of workloads. Instead of hardcoding a single model for every request in your application, you define Tags. For example, you can configure your router so that all UI Design questions go to Gemini, but all Unit Testing questions go to DeepSeek. You achieve this powerful dynamic routing using the
gateway.tags configuration.
How Tag Routing Works
When a request arrives, our internal Gateway AI analyzes the prompt in milliseconds. It performs two critical steps:- Intent Matching: It matches the user’s prompt to the
descriptionof one of your provided tags. - Complexity Scoring: It scores the difficulty of the prompt (from 0.0 to 1.0) and selects the appropriate model from that tag’s
modelsarray.
Critical Rule: Sorting Your Models
When defining themodels array inside a tag, you must sort the models from most complex (smartest/most expensive) to least complex (simplest/cheapest).
The Gateway uses the complexity score to pick the right model from this list:
- A score of
0.9(Very Hard) will select the first model in your array. - A score of
0.1(Very Simple) will select the last model in your array.
Basic Implementation
You pass thegateway object directly into your request.
TypeScript
What happens in this example?
- Analysis: The user asked for a “Jest unit test”.
- Intent Matching: The Gateway matches the intent perfectly to the
"testing"tag. - Complexity Scoring: The Gateway determines that writing a basic React button test is moderately difficult (Score:
0.5). - Execution: Because the score is in the middle, it selects the middle model from the
"testing"array:deepseek/deepseek-chat. (Saving you the cost of GPT-5.4).
Configuring Multi-Modal Fallbacks
Sometimes, a user’s prompt will trigger a completely different modality. For example, if your app is a general chatbot, a user might suddenly ask: “Generate an image of a sunset.” If the Gateway detects that the user’s intent is to create a visual asset (not text), it will ignore your text-based tags and instantly route the request to the model specified inimageGenerationModel.
Configuration Properties
The Tag Object
| Property | Type | Description |
|---|---|---|
name | string | A short identifier for the tag (e.g., “coding”, “support”). |
description | string | Crucial: A clear, semantic description of the topics this tag covers. The internal AI uses this string to match the user’s prompt. |
models | string[] | An array of models sorted from Most Complex to Least Complex. The router picks the model based on the prompt’s difficulty score. |
The Gateway Object
| Property | Type | Description |
|---|---|---|
tags | Tag[] | An array of custom routing rules. |
imageGenerationModel | string | (Optional) The specific model to use if the Gateway determines the user wants to generate an image instead of text. |