Getting Your API Key
Agent LoL requires a Riot Games API key to fetch match data, summoner information, and game timelines.Step 1: Create a Riot Developer Account
- Visit developer.riotgames.com
- Sign in with your Riot Games account
- Accept the Developer Terms of Service
Step 2: Generate an API Key
Once logged in, you’ll see your API key on the dashboard:Development API keys are shown immediately and regenerate automatically every 24 hours.
.env.local file.
Development vs Production Keys
Development Keys
Characteristics:- Expire every 24 hours at midnight Pacific Time
- Rate limit: 20 requests per second, 100 requests per 2 minutes
- Free and automatically available
- Sufficient for local development and testing
Production Keys
Characteristics:- Do not expire
- Higher rate limits (varies by tier)
- Requires application and approval from Riot Games
- Intended for public-facing applications
Rate Limits
All API keys have rate limits to prevent abuse:| Key Type | Per Second | Per 2 Minutes |
|---|---|---|
| Development | 20 | 100 |
| Personal (Tier 1) | 20 | 100 |
| Production (Tier 2+) | Varies | Varies |
Handling Rate Limits
The application makes multiple API calls per match view:- Match details (
/lol/match/v5/matches/{matchId}) - Timeline data (
/lol/match/v5/matches/{matchId}/timeline) - Account verification during authentication
If you encounter rate limit errors (HTTP 429), the auth flow in
auth.js:59 will return a user-friendly message: “Too many requests. Please try again later.”Finding Your Riot ID
Your Riot ID consists of two parts: Game Name and Tag Line.In the League Client
- Open League of Legends
- Look at the top-right corner
- Your Riot ID appears as
GameName#TAG
Faker#KR1
- GAME_NAME:
Faker - TAG_LINE:
KR1
In Game
Press Tab during a match - your Riot ID is shown next to your champion name.Environment Variable Format
Authentication Flow
Agent LoL uses NextAuth.js with a custom Credentials provider to authenticate users via the Riot API.How It Works
- User Login - Users provide their Game Name, Tag Line, and API Key
- Validation - Credentials are validated in
auth.js:10-19:- Game Name must be at least 2 characters
- Tag Line is required
- API Key is required
- Riot API Verification - The application calls the Riot Account API:
- PUUID Retrieval - If successful, the user’s PUUID is stored in the JWT session
- Session Storage - The API key is stored securely in the JWT and never exposed to the client (
auth.js:101)
Error Handling
The authentication flow handles common API errors:| Status Code | Error Message | Cause |
|---|---|---|
| 401 | Invalid API key or Riot account | Wrong API key or credentials |
| 403 | API key forbidden or rate limited | Key revoked or rate limit hit |
| 404 | Riot ID not found | Incorrect Game Name or Tag Line |
| 429 | Too many requests | Rate limit exceeded |
auth.js:48-62 for the complete error handling logic.
Session Configuration
Sessions are configured with:- Strategy: JWT (JSON Web Tokens)
- Max Age: 30 days
- Update Age: 24 hours (session refreshes daily)
auth.js:81-85 for session settings.
API Key Security
Best Practices
- Use
.env.local- This file is gitignored by default - Never use
NEXT_PUBLIC_prefix - This exposes variables to the browser - Secure JWT Storage - The API key is stored in the JWT token (server-side) and never sent to the client (
auth.js:76) - Server-Side API Calls - All Riot API requests are made from Next.js API routes, not the browser
Verifying Security
The application ensures the API key is never exposed:auth.js
auth.js:96-104 explicitly omits the API key from the client-accessible session.
Testing Your Configuration
-
Add your credentials to
.env.local: -
Start the development server:
-
Navigate to
/loginand sign in with your credentials - If successful, you’ll be redirected to the dashboard and can view match history
Troubleshooting
”Invalid API key or Riot account”
- Verify your API key is current (dev keys expire daily)
- Check for typos or extra whitespace
- Ensure you’re using the key from developer.riotgames.com
”Riot ID not found”
- Double-check your Game Name and Tag Line
- Ensure TAG_LINE doesn’t include the
#symbol - Verify you’re using your Riot ID, not your old summoner name
”Too many requests”
- You’ve hit the rate limit (20 requests/second for dev keys)
- Wait 2 minutes and try again
- Consider implementing request queuing for production use
”API key forbidden”
- Your API key may have been revoked
- Regenerate your key at developer.riotgames.com
- Check that you accepted the Developer Terms of Service
Regional Endpoints
The application uses regional routing for Riot API calls:- Account API:
americas.api.riotgames.com(used inauth.js:4-5) - Match API:
americas.api.riotgames.com(used in timeline compare route)
The Americas routing value covers NA, BR, LAN, LAS, and OCE regions. For other regions (Europe, Asia), you may need to modify the API base URLs in the source code.
