Overview
No model is the best at everything. Some excel at coding, others at creative writing, medical terminology, or mathematical reasoning. Specialist routing ensures every request goes to the model that’s best-in-class for that specific domain.The Problem
Using a single “jack-of-all-trades” model means:- Coding questions get generic responses instead of precise, syntax-aware answers
- Creative writing lacks the nuance and style of specialized creative models
- Medical queries miss domain-specific terminology and accuracy
- Mathematical problems lack the reasoning capabilities of math-optimized models
The Solution
A specialist router detects the domain of each request and routes it to the best model for that specific task:- Python coding question → Gemini 2.5 Flash or GPT-5 (coding-optimized)
- Poetic brand description → Claude Opus 4 (creative writing)
- Medical diagnosis query → Specialized medical LLM or Claude (medical knowledge)
- Mathematical proof → Models optimized for mathematical reasoning
How It Works
- Request arrives with domain-specific content
- Inworld Router analyzes the prompt to detect domain (coding, creative, medical, math, etc.)
- Inworld Router routes to the model optimized for that domain
- Response is returned with best-in-class quality for that specific niche
Implementation
Step 1: Create a Specialist Router
Create a router with domain-specific routes using conditional routing:Model IDs are specified as strings in the format
"provider/model" (e.g., "openai/gpt-5"). Routes use CEL expressions to match based on domain. Routes are evaluated in order, and the first matching route is selected. Weights must sum to exactly 100 within each route - they are not normalized and are independent per route.Step 2: Use Domain-Specific Routing
Pass the domain inextra_body.metadata to route requests:
Domain-Specific Model Selection
Coding Tasks
Use models optimized for code generation and understanding:- Gemini 2.5 Flash: Fast and capable code generation across multiple languages
- GPT-5: Excellent coding capabilities with broad language support
- Claude Opus 4: Strong code understanding and generation
["coding", "intelligence"]
Creative Writing
Use models with strong creative and stylistic capabilities:- Claude Opus 4: Exceptional creative writing and nuanced responses
- GPT-5: Strong creative capabilities with good style variation
- Gemini Pro: Good creative writing with diverse styles
["intelligence"]
Mathematical Reasoning
Use models optimized for mathematical problem-solving:- o3-mini: OpenAI’s reasoning model optimized for math
- Gemini 2.5 Flash: Strong mathematical reasoning capabilities
- Claude Opus 4: Excellent mathematical problem-solving
["math", "intelligence"]
Medical & Scientific
Use models with strong domain knowledge:- Claude Opus 4: Excellent medical and scientific knowledge
- GPT-5: Strong domain knowledge across medical and scientific fields
- Specialized medical LLMs: For highly specialized medical queries
["intelligence"] (domain knowledge is typically part of general intelligence)
General Purpose
For queries that don’t fit a specific domain:- GPT-5: Best overall general-purpose model
- Claude Opus 4: Excellent general-purpose capabilities
- Gemini 2.5 Flash: Fast and capable general-purpose option
["intelligence", "price"]
Advanced: Prompt-Based Domain Detection
For more sophisticated routing, use system prompts to classify domains:Use Cases
Software Development Platform
Route code-related queries to coding specialists:Content Creation Platform
Route creative requests to creative specialists:Educational Platform
Route math problems to math specialists:Advanced: Domain Pattern Matching
You can use CEL string operations for more flexible domain matching:Domain Prefix Matching
Route multiple related domains using pattern matching:Domain + Complexity Routing
Route complex domain-specific tasks to premium models:Multiple Domain Support
Route to the same specialist for multiple related domains:Domain + Content Length
Route long-form domain content to appropriate models:Best Practices
- Map domains to models: Create a clear mapping of domains to optimal models
- Test domain detection: Ensure your routing logic correctly identifies domains
- Monitor quality: Track response quality per domain to optimize routing
- Fallback to general: Always have a general-purpose route as fallback
- Update regularly: As new specialized models emerge, update your routing
- Use pattern matching: Leverage CEL string operations (startsWith, contains, endsWith) for flexible domain matching
- Combine factors: Use complexity scores and content length to refine routing decisions
Performance Benefits
Specialist routing provides:- Higher quality: Best-in-class responses for each domain
- Better user experience: Users get expert-level answers in their domain
- Cost optimization: Use specialized models only when needed
- Competitive advantage: Superior quality compared to single-model approaches
Next Steps
- Learn about cost optimization to reduce API costs
- Explore failover routing for high availability
- Review model selection criteria for available options