Overview
Monkeytype API supports multiple authentication methods to accommodate different use cases. All authenticated requests must include proper authorization headers.Authentication Methods
Bearer Token (Firebase JWT)
Primary authentication method using Firebase ID tokens.How It Works
- User authenticates via Firebase (email/password, OAuth, etc.)
- Firebase returns an ID token
- Include token in
Authorizationheader - Backend verifies token with Firebase Admin SDK
Request Format
Token Requirements
- Valid Firebase ID token
- Token not expired (tokens expire after 1 hour)
- User account exists in Monkeytype database
Fresh Tokens
Some sensitive endpoints require fresh tokens (issued within the last 60 seconds):- User deletion
- Account reset
- Email/password updates
- Name changes
- Token revocation
Token Caching
By default, tokens are cached for performance. Disable caching for:- Email verification checks
- Token revocation
- Real-time permission updates
ApeKey Authentication
API keys for programmatic access and automation.What Are ApeKeys?
ApeKeys are user-generated API credentials that provide:- Long-lived authentication (no expiration)
- Higher rate limits
- Programmatic access to user data
- Fine-grained control (enable/disable per key)
Creating an ApeKey
- Authenticate with Bearer token
- POST to
/ape-keysendpoint:
Using ApeKeys
Include ApeKey in theAuthorization header with ApeKey scheme:
ApeKey Format
ApeKeys consist of:- Key ID (identifies the key)
- Secret (hashed using bcrypt)
- Combined and base64url-encoded
keyId.secret (encoded)
ApeKey Management
List Your ApeKeysApeKey Configuration
ApeKeys can be disabled system-wide:Endpoint Support
Not all endpoints accept ApeKeys. Check endpoint metadata:GET /resultsGET /users/personalBestsGET /users/statsGET /users/tagsGET /users/streakGET /leaderboards/rank- And more…
Sensitive operations (delete account, update password) never accept ApeKeys.
Public Endpoints
Some endpoints require no authentication:GET /- API statusGET /leaderboards- Public leaderboardsGET /users/:name/profile- Public profilesGET /users/checkName/:name- Username availabilityPOST /users/forgotPasswordEmail- Password reset request
Authentication Flow
Backend Authentication Process
-
Extract Authorization Header
-
Determine Auth Scheme
Bearer→ Verify Firebase tokenApeKey→ Validate API keyUid→ Development-only mode- None → Public endpoint or error
-
Verify Credentials
- Bearer:
verifyIdToken()via Firebase Admin - ApeKey: Lookup key, verify hash with bcrypt
- Bearer:
-
Attach Context
-
Check Permissions
- Verify endpoint allows auth type
- Check user permissions (admin, quoteMod, etc.)
- Validate configuration requirements
Error Handling
Common Authentication Errors
401 Unauthorized - Missing TokenRate Limiting by Auth Type
Different rate limits apply based on authentication:Bad Authentication Rate Limiting
Failed authentication attempts are tracked:- Limit: 30 failed attempts per hour per IP
- Triggers: Invalid tokens, wrong passwords, malformed credentials
- Result: Temporary IP ban
Development Mode
Uid Authentication (Dev Only)
For local testing without Firebase:Public on Dev
Some endpoints become public in development:Security Best Practices
Token Management
-
Never expose tokens in client code
-
Refresh expired tokens
-
Handle token expiration gracefully
ApeKey Security
- Store securely - Use environment variables or secret managers
- Rotate regularly - Delete old keys, generate new ones
- Disable unused keys - Don’t delete if you need audit trail
- Use specific keys - Different keys for different integrations
- Monitor usage - Check
lastUsedOntimestamp
Request Headers
Additional security headers:Example: Complete Auth Flow
Troubleshooting
Token Verification Failed
Problem: 401 errors despite valid token Solutions:- Check token expiration (max 1 hour)
- Verify Firebase project configuration
- Ensure user exists in database
- Check for token revocation
ApeKey Not Working
Problem: 401/503 errors with ApeKey Solutions:- Verify endpoint accepts ApeKeys
- Check ApeKey is enabled
- Confirm system-wide ApeKeys not disabled
- Validate ApeKey format (base64url-encoded)
- Ensure ApeKey not deleted
Fresh Token Required
Problem: “This endpoint requires a fresh token” Solutions:- Re-authenticate user
- Get new token with
getIdToken(true) - Ensure token issued within last 60 seconds