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
You’re settling for average performance across all domains instead of excellence in each.
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:
curl --request POST \
--url https://api.inworld.ai/router/v1/routers \
--header 'Authorization: Bearer <your-api-key>' \
--header 'Content-Type: application/json' \
--data '{
"name": "routers/specialist-routing",
"defaults": {
"text_generation_config": {
"max_new_tokens": 1024,
"temperature": 0.7
}
},
"routes": [
{
"route": {
"route_id": "coding-specialist",
"variants": [
{
"variant": {
"variant_id": "gemini-flash-coding",
"model_id": "google-ai-studio/gemini-2.5-flash"
},
"weight": 60
},
{
"variant": {
"variant_id": "gpt5-coding",
"model_id": "openai/gpt-5"
},
"weight": 40
}
]
},
"condition": {
"cel_expression": "domain == \"coding\""
}
},
{
"route": {
"route_id": "creative-specialist",
"variants": [
{
"variant": {
"variant_id": "claude-creative",
"model_id": "anthropic/claude-opus-4-20250514"
},
"weight": 70
},
{
"variant": {
"variant_id": "gpt5-creative",
"model_id": "openai/gpt-5"
},
"weight": 30
}
]
},
"condition": {
"cel_expression": "domain == \"creative\""
}
},
{
"route": {
"route_id": "math-specialist",
"variants": [
{
"variant": {
"variant_id": "o3-math",
"model_id": "openai/o3-mini"
},
"weight": 60
},
{
"variant": {
"variant_id": "gemini-math",
"model_id": "google-ai-studio/gemini-2.5-flash"
},
"weight": 40
}
]
},
"condition": {
"cel_expression": "domain == \"math\""
}
},
{
"route": {
"route_id": "general-purpose",
"variants": [
{
"variant": {
"variant_id": "gpt5-general",
"model_id": "openai/gpt-5"
},
"weight": 60
},
{
"variant": {
"variant_id": "claude-general",
"model_id": "anthropic/claude-opus-4-6"
},
"weight": 40
}
]
},
"condition": {
"cel_expression": "domain == \"general\" || domain == \"\""
}
}
],
"defaultRoute": {
"route_id": "default",
"variants": [
{
"variant": {
"variant_id": "default-general",
"model_id": "openai/gpt-5"
},
"weight": 100
}
]
}
}'
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 in extra_body.metadata to route requests:
# Route coding questions to coding specialists
curl --location 'https://api.inworld.ai/v1/chat/completions' \
--header 'Authorization: Bearer <your-api-key>' \
--header 'Content-Type: application/json' \
--data '{
"model": "inworld/specialist-routing",
"messages": [
{"role": "user", "content": "Write a Python function to implement quicksort with detailed comments"}
],
"extra_body": {
"metadata": {
"domain": "coding"
}
}
}'
# Route creative requests to creative specialists
curl --location 'https://api.inworld.ai/v1/chat/completions' \
--header 'Authorization: Bearer <your-api-key>' \
--header 'Content-Type: application/json' \
--data '{
"model": "inworld/specialist-routing",
"messages": [
{"role": "user", "content": "Write a poetic brand description for a sustainable fashion company that emphasizes craftsmanship and environmental consciousness"}
],
"extra_body": {
"metadata": {
"domain": "creative"
}
}
}'
# Route math problems to math specialists
curl --location 'https://api.inworld.ai/v1/chat/completions' \
--header 'Authorization: Bearer <your-api-key>' \
--header 'Content-Type: application/json' \
--data '{
"model": "inworld/specialist-routing",
"messages": [
{"role": "user", "content": "Prove that the square root of 2 is irrational"}
],
"extra_body": {
"metadata": {
"domain": "math"
}
}
}'
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
Sort criteria: ["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
Sort criteria: ["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
Sort criteria: ["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
Sort criteria: ["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
Sort criteria: ["intelligence", "price"]
Advanced: Prompt-Based Domain Detection
For more sophisticated routing, use system prompts to classify domains:
{
"defaults": {
"message_templates": [
{
"role": "system",
"content": "You are a domain classifier. Analyze the user's query and classify it as one of: 'coding', 'creative', 'math', 'medical', 'general'. Respond with only the domain name."
}
]
}
}
Then use the classification result to route to the appropriate specialist model.
Use Cases
Route code-related queries to coding specialists:
# Code generation
curl --location 'https://api.inworld.ai/v1/chat/completions' \
--header 'Authorization: Bearer <your-api-key>' \
--header 'Content-Type: application/json' \
--data '{
"model": "inworld/specialist-routing",
"messages": [{"role": "user", "content": "Implement a REST API endpoint in Node.js"}],
"extra_body": {"sort": ["coding"]}
}'
# Code review
curl --location 'https://api.inworld.ai/v1/chat/completions' \
--header 'Authorization: Bearer <your-api-key>' \
--header 'Content-Type: application/json' \
--data '{
"model": "inworld/specialist-routing",
"messages": [{"role": "user", "content": "Review this Python code for performance issues"}],
"extra_body": {"sort": ["coding"]}
}'
Content Creation Platform
Route creative requests to creative specialists:
# Brand copywriting
curl --location 'https://api.inworld.ai/v1/chat/completions' \
--header 'Authorization: Bearer <your-api-key>' \
--header 'Content-Type: application/json' \
--data '{
"model": "inworld/specialist-routing",
"messages": [{"role": "user", "content": "Write compelling product descriptions for an e-commerce site"}],
"extra_body": {"sort": ["intelligence"]}
}'
Route math problems to math specialists:
# Mathematical proofs
curl --location 'https://api.inworld.ai/v1/chat/completions' \
--header 'Authorization: Bearer <your-api-key>' \
--header 'Content-Type: application/json' \
--data '{
"model": "inworld/specialist-routing",
"messages": [{"role": "user", "content": "Prove that the square root of 2 is irrational"}],
"extra_body": {"sort": ["math"]}
}'
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:
{
"route": {
"route_id": "coding-variants",
"variants": [...]
},
"condition": {
"cel_expression": "domain.startsWith('code') || domain.contains('programming') || domain.contains('debug')"
}
}
This routes coding, programming, and debugging requests to coding specialists.
Domain + Complexity Routing
Route complex domain-specific tasks to premium models:
{
"route": {
"route_id": "complex-coding",
"variants": [...]
},
"condition": {
"cel_expression": "domain == \"coding\" && complexity_score >= 8"
}
}
This ensures complex coding tasks get premium models while simple coding tasks use cost-effective options.
Multiple Domain Support
Route to the same specialist for multiple related domains:
{
"route": {
"route_id": "coding-specialist",
"variants": [...]
},
"condition": {
"cel_expression": "domain == \"coding\" || domain == \"debugging\" || domain == \"refactoring\" || domain == \"code-review\""
}
}
This consolidates multiple coding-related domains into a single specialist route.
Domain + Content Length
Route long-form domain content to appropriate models:
{
"route": {
"route_id": "long-creative",
"variants": [...]
},
"condition": {
"cel_expression": "domain == \"creative\" && content_length > 5000"
}
}
This routes long creative writing tasks to models optimized for extended content generation.
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
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