Region Based Routing
Simple routing based on user's geographic region for data residency and performance optimization.
Route requests to different models based on the user's geographic location. This helps with data residency requirements, regulatory compliance, and performance optimization by selecting geographically closer providers.
Use Case
Data residency requirements
Regional performance optimization
Regulatory compliance (GDPR, data sovereignty)
Provider availability by region
Configuration
{
"model": "router/dynamic",
"router": {
"type": "conditional",
"routes": [
{
"name": "european_users",
"conditions": {
"all": [
{
"metadata.region": {
"$eq": "Europe"
}
}
]
},
"targets": {
"$any": [
"openai/gpt-5",
"anthropic/claude-opus-4.1"
],
"sort_by": "ttft",
"sort_order": "min"
}
},
{
"name": "north_american_users",
"conditions": {
"all": [
{
"metadata.country": {
"$in": ["US", "CA", "MX"]
}
}
]
},
"targets": {
"$any": [
"openai/gpt-4.1",
"google/gemini-2.5-pro"
],
"sort_by": "ttft",
"sort_order": "min"
}
},
{
"name": "asian_users",
"conditions": {
"all": [
{
"metadata.region": {
"$eq": "Asia"
}
}
]
},
"targets": {
"$any": [
"deepseek/deepseek-chat",
"kimi-k2"
],
"sort_by": "ttft",
"sort_order": "min"
}
},
{
"name": "global_fallback",
"conditions": {
"all": []
},
"targets": "openai/gpt-4.1-mini"
}
]
}
}
How it works
European Users (using
metadata.region = "Europe"
): Get GPT-5 or Claude-Opus-4.1 models optimized for speedNorth American Users (using specific country codes US, CA, MX): Get GPT-4.1 or Gemini-2.5-pro models optimized for speed
Asian Users (using
metadata.region = "Asia"
): Get DeepSeek-chat or Kimi-k2 models optimized for speedGlobal Fallback: Any unmatched regions/countries get GPT-4.1-mini
Variables Used
metadata.region
: User's geographic region (automatically detected by LangDB based on IP address)metadata.country
: User's country code (automatically detected by LangDB based on IP address)
Geographic Detection
LangDB automatically detects user location based on IP address geolocation and provides both:
Regions: Broad geographic areas like
"Europe"
,"Asia"
,"North America"
, etc.Countries: ISO 3166-1 alpha-2 country codes like
"US"
,"GB"
,"DE"
,"CN"
,"JP"
, etc.No additional setup required - works out of the box
Customization
Region-based: Use
metadata.region
for broad geographic routing ("Europe"
,"Asia"
,"Africa"
, etc.)Country-specific: Use
metadata.country
for precise country targeting ("US"
,"DE"
,"JP"
, etc.)Mixed approach: Combine both region and country routing in the same configuration
Include region-specific model providers (e.g., local AI providers)
Add failover logic for regional outages
Last updated
Was this helpful?