Authentication
JWT tokens and API keys
Authentication
The API uses API keys for authentication. Generate keys through the web application and include them in your requests.
API Key Authentication
Our API supports authentication via API keys for programmatic access. API keys provide secure, token-based authentication with built-in rate limiting and usage tracking.
How to Generate an API Key:
- Log in to your account
- Navigate to Profile Settings (click your avatar)
- Go to the “Security” tab
- Click “Create New API Key”
- Give your key a name and select the type (Development/Production)
- Save the key securely - it will only be shown once!
Testing Authentication
Test your API key with our authentication test endpoint:
bash
# Test if your API key is working
curl -H "X-API-Key: sk_live_your_api_key_here" \
http://localhost:8000/api/v1/protected/test
# Success Response:
{
"success": true,
"message": "Authentication successful! Your API key is valid.",
"api_key_name": "My API Key",
"api_key_type": "production",
"rate_limit_tier": "free",
"timestamp": "2025-01-18T12:00:00.000Z"
}
Get User Information
Retrieve information about the user associated with your API key:
bash
curl -H "X-API-Key: sk_live_your_api_key_here" \
http://localhost:8000/api/v1/user/me
# Response:
{
"user_id": 1,
"username": "johndoe",
"email": "john@example.com",
"created_at": "2024-01-01T00:00:00Z",
"api_key_count": 3
}
Check Usage Statistics
Monitor your API usage and rate limit status:
bash
curl -H "X-API-Key: sk_live_your_api_key_here" \
http://localhost:8000/api/v1/usage/stats
# Response:
{
"api_key_name": "My API Key",
"total_requests": 142,
"rate_limit_tier": "free",
"requests_remaining": 58,
"reset_time": "2025-01-18T12:01:00Z"
}