Documentation Index
Fetch the complete documentation index at: https://mintlify.com/renja-g/RiftRelay/llms.txt
Use this file to discover all available pages before exploring further.
Why Use Multiple Tokens?
Each Riot API token has its own independent rate limits. By using multiple tokens, RiftRelay can:Higher Throughput
Process more requests per second by distributing load across tokens
Load Balancing
Automatically distribute requests to the least-loaded token
Redundancy
Continue operating if one token hits rate limits
Burst Handling
Handle sudden traffic spikes more effectively
Configuration
Provide multiple tokens as comma-separated values in theRIOT_TOKEN environment variable:
.env
Spaces around commas are automatically trimmed. Both formats work:
RIOT_TOKEN=token1,token2,token3RIOT_TOKEN=token1, token2, token3
Real Configuration Example
How It Works
RiftRelay parses comma-separated tokens on startup using this logic frominternal/config/config.go:
config.go
Request Distribution
When a request arrives, RiftRelay selects the token with the earliest available capacity.
Token Selection Logic
Frominternal/limiter/limiter.go, RiftRelay picks the best available token:
limiter.go
- Check each token’s availability for the requested region and API bucket
- Calculate when each token will next have capacity
- Select the token that can send the request soonest
- Return the token index and ready time
RiftRelay automatically balances load based on real-time rate limit states, not round-robin. This ensures optimal token utilization.
Token Assignment to Requests
Once a token is selected, it’s attached to the request ininternal/proxy/proxy.go:
proxy.go
X-Riot-Token header before proxying to Riot’s API.
Rate Limit Tracking
Each token maintains independent rate limit state:limiter.go
- Application-level rate limits (per region)
- Method-level rate limits (per API endpoint)
- Current usage and remaining capacity
- Next available time for requests
Throughput Calculation
With multiple tokens, your effective rate limit is multiplied:Example: 3 Tokens
Example: 3 Tokens
Single token limits (typical Production API key):
- 20 requests per second
- 100 requests per 2 minutes
- 60 requests per second (3 × 20)
- 300 requests per 2 minutes (3 × 100)
Example: 5 Tokens
Example: 5 Tokens
Single token limits:
- 20 requests per second
- 100 requests per 2 minutes
- 100 requests per second (5 × 20)
- 500 requests per 2 minutes (5 × 100)
Monitoring Token Usage
Enable metrics to monitor token distribution:.env
http://localhost:8985/metrics:
- Request admission rate by outcome
- Queue depth per bucket and priority
- Upstream response times and status codes
Best Practices
Use Matching Token Tiers
Use Matching Token Tiers
All tokens should be the same tier (all Production or all Development). Mixing tiers can lead to unbalanced load distribution.
Good
Avoid
Start with 2-3 Tokens
Start with 2-3 Tokens
Begin with 2-3 tokens and scale up based on actual throughput needs. More tokens doesn’t always mean better performance if your traffic is low.
Increase Queue Capacity
Increase Queue Capacity
With multiple tokens, you can handle more concurrent requests. Increase
QUEUE_CAPACITY accordingly:.env
Rotate Tokens Safely
Rotate Tokens Safely
To rotate tokens without downtime:
- Add new token to the comma-separated list
- Restart RiftRelay
- Verify the new token is being used (check metrics)
- Remove the old token from the list
- Restart again
Validation
Frominternal/config/config.go, token validation happens at startup:
config.go
- At least one token must be provided
- Empty strings in the comma-separated list are filtered out
- Token count must be greater than zero
Common Issues
Tokens are not comma-separated correctly
Tokens are not comma-separated correctly
Problem: Only the first token is recognized.Solution: Ensure commas separate tokens with no quotes around individual tokens:
One token has different rate limits
One token has different rate limits
Problem: Uneven distribution with one token always hitting limits.Solution: Verify all tokens are the same tier. Check each token individually:Look for
X-App-Rate-Limit header in the response to confirm rate limits.All tokens hitting limits simultaneously
All tokens hitting limits simultaneously
Problem: Even with multiple tokens, you’re getting 429 errors.Solution: You may have exceeded the combined capacity. Options:
- Add more tokens
- Increase
QUEUE_CAPACITYto buffer more requests - Reduce request rate
- Use priority requests for critical operations only
Example: Complete Setup
Here’s a complete configuration for high-throughput production use:.env
Performance Impact
1 Token
Baseline
- 20 req/s
- 72K req/hour
3 Tokens
3x throughput
- 60 req/s
- 216K req/hour
5 Tokens
5x throughput
- 100 req/s
- 360K req/hour
Actual throughput depends on your API key tier, endpoint-specific rate limits, and request distribution across regions and methods.
Next Steps
Priority Requests
Combine multiple tokens with priority requests for optimal performance
Configuration
Fine-tune queue capacity and timeouts for your token count