Conductor also includes AI-powered smart routing that uses OpenAI to make optimal provider selection decisions based on transaction context, historical performance, and cost optimization.
POST /v1/routing/select
Request Body:
{
"currency": "USD",
"amount": 150.00,
"country": "US",
"customer_segment": "premium",
"transaction_type": "one_time",
"merchant_id": "merchant_123",
"customer_id": "customer_456",
"ip_address": "192.168.1.1",
"metadata": {
"product_category": "electronics",
"payment_method": "credit_card"
}
}Response:
{
"recommended_provider": "stripe",
"confidence_score": 92,
"reasoning": "Stripe offers the best success rate (98.5%) and competitive pricing (2.9%) for USD transactions in the US market",
"alternative_provider": "xendit",
"estimated_success_rate": 0.985,
"estimated_cost": 4.65,
"routing_time_ms": 150,
"cache_hit": false,
"fallback_used": false
}GET /v1/routing/stats
Response:
{
"stripe": {
"success_rate": 0.985,
"avg_response_time_ms": 450,
"cost_per_transaction": 0.029,
"total_transactions": 15000,
"failed_transactions": 225,
"last_updated": "2024-01-15T10:30:00Z"
},
"xendit": {
"success_rate": 0.972,
"avg_response_time_ms": 380,
"cost_per_transaction": 0.025,
"total_transactions": 8500,
"failed_transactions": 238,
"last_updated": "2024-01-15T10:30:00Z"
}
}GET /v1/routing/metrics?start_date=2024-01-01T00:00:00Z&end_date=2024-01-15T23:59:59Z
Response:
{
"total_decisions": 2500,
"cache_hit_rate": 0.75,
"avg_confidence_score": 87.5,
"success_rate": 0.96,
"avg_response_time_ms": 180,
"cost_savings": 1250.50,
"provider_distribution": {
"stripe": 1600,
"xendit": 900
}
}GET /v1/routing/config
PUT /v1/routing/config
Configuration:
{
"enable_ai_routing": true,
"cache_ttl_seconds": 3600,
"min_confidence_score": 70,
"fallback_provider": "stripe",
"enable_cost_optimization": true,
"enable_success_rate_optimization": true
}curl -X POST http://localhost:8080/v1/routing/select \
-H "Content-Type: application/json" \
-H "X-API-Key: your_api_key_here" \
-d '{
"currency": "USD",
"amount": 99.99,
"country": "US",
"customer_segment": "standard",
"transaction_type": "one_time"
}'curl -X POST http://localhost:8080/v1/routing/select \
-H "Content-Type: application/json" \
-H "X-API-Key: your_api_key_here" \
-d '{
"currency": "EUR",
"amount": 2500.00,
"country": "DE",
"customer_segment": "enterprise",
"transaction_type": "subscription",
"metadata": {
"subscription_plan": "enterprise",
"billing_cycle": "annual"
}
}'curl -X POST http://localhost:8080/v1/routing/select \
-H "Content-Type: application/json" \
-H "X-API-Key: your_api_key_here" \
-d '{
"currency": "IDR",
"amount": 500000,
"country": "ID",
"customer_segment": "standard",
"transaction_type": "one_time"
}'The AI considers multiple factors when making routing decisions:
- USD/EUR/GBP: Prefers Stripe (global expertise)
- IDR/SGD/MYR/PHP/THB/VND: Prefers Xendit (regional expertise)
- Success Rate: Historical transaction success rates
- Response Time: Average API response times
- Cost Efficiency: Processing fees and transaction costs
- Amount: High-value transactions may prefer different providers
- Customer Segment: Premium customers get priority routing
- Transaction Type: Subscriptions vs one-time payments
- Geographic Location: Local provider preferences
- Time of Day: Peak vs off-peak hours
- Provider Health: Current availability and performance
- Load Balancing: Distribute load across providers
When OpenAI is unavailable, the system uses rule-based routing:
// Currency-based fallback
switch currency {
case "USD", "EUR", "GBP":
return "stripe"
case "IDR", "SGD", "MYR", "PHP", "THB", "VND":
return "xendit"
default:
return "stripe" // Default fallback
}- Cache Key: Based on currency, amount, country, and customer segment
- TTL: 1 hour (configurable)
- Cache Hit Rate: Typically 75-80% for similar transactions
- Performance: Sub-millisecond cache lookups
- Routing Decisions: Total decisions made
- Cache Performance: Hit rates and response times
- AI Confidence: Average confidence scores
- Success Rates: Transaction success by provider
- Cost Savings: Estimated savings from optimal routing
- Provider Distribution: Usage patterns across providers
- AI Routing: 150-300ms average response time
- Cache Hit: < 5ms response time
- Fallback Routing: < 10ms response time
- Confidence Score: 85-95% average
# OpenAI Configuration
OPENAI_API_KEY=your_openai_api_key_here
# Routing Configuration
ROUTING_CACHE_TTL=3600
ROUTING_MIN_CONFIDENCE=70
ROUTING_FALLBACK_PROVIDER=stripeUse the /v1/routing/config endpoint to adjust settings:
- Enable/Disable AI Routing: Toggle AI-powered decisions
- Cache TTL: Adjust caching duration
- Confidence Threshold: Minimum confidence for AI decisions
- Fallback Provider: Default provider when AI fails
- Optimization Flags: Enable cost or success rate optimization
The intelligent routing integrates seamlessly with the existing payment flow:
// 1. Get routing recommendation
routingResp, err := routingService.SelectOptimalProvider(ctx, routingReq)
// 2. Use recommended provider for payment
paymentReq := &models.ChargeRequest{
Currency: routingReq.Currency,
Amount: routingReq.Amount,
// ... other fields
}
// 3. Route to optimal provider
chargeResp, err := providerSelector.Charge(ctx, paymentReq)- Low Confidence Scores: Check provider statistics and transaction data
- High Response Times: Monitor OpenAI API performance
- Cache Misses: Review cache key generation logic
- Fallback Usage: Check OpenAI API availability and configuration
Enable detailed logging to troubleshoot routing decisions:
# Check routing logs
curl -X GET http://localhost:8080/v1/routing/metrics
# Monitor provider stats
curl -X GET http://localhost:8080/v1/routing/stats