What is an API Key?
An API key is a unique identifier used to authenticate your requests to the Loops API. It acts like a password and should be kept secure at all times.Getting Your API Key
Step 1: Access Your Dashboard
- Log in to your Loops Dashboard
- Navigate to Settings → API Keys
Step 2: Create or Copy Your Key
- If you don’t have an API key yet, click Create API Key
- If you already have one, click the Copy button next to your key
- You can create multiple API keys for different environments (development, production, etc.)
Best Practice: Create separate API keys for development and production environments. This makes it easier to rotate keys without affecting your live application.
Using Your API Key
Authentication Method
All API requests must include your API key in theAuthorization
header using Bearer authentication:
Example Requests
Security Best Practices
Never expose your API key in client-side code, public repositories, or logs!
1. Use Environment Variables
Always store your API key in environment variables, not in your code:2. Add to .gitignore
Make sure your.env
file is in your .gitignore
:
.gitignore
3. Use Server-Side Only
API keys should only be used in server-side code (backend, API routes, serverless functions), never in:- ❌ Frontend JavaScript
- ❌ Mobile apps
- ❌ Desktop applications
- ❌ Browser extensions
4. Rotate Keys Regularly
Consider rotating your API keys periodically, especially if:- A developer with access leaves your team
- You suspect a key may have been compromised
- As a regular security practice (e.g., every 90 days)
5. Use Separate Keys for Different Environments
Create different API keys for:- Development: For local testing
- Staging: For pre-production testing
- Production: For your live application
Managing Multiple API Keys
You can create multiple API keys in your dashboard. This is useful for:- Different environments (dev, staging, production)
- Different applications using the same Loops account
- Team member access with different permissions
- Key rotation without downtime
Creating a New Key
- Go to Settings → API Keys
- Click Create API Key
- Give it a descriptive name (e.g., “Production Server”, “Development”)
- Copy the key immediately (you won’t be able to see it again)
- Store it securely in your environment variables
Revoking a Key
If you need to revoke an API key:- Go to Settings → API Keys
- Find the key you want to revoke
- Click Revoke or Delete
- Confirm the action
Revoking a key will immediately stop all API requests using that key. Make sure you’ve updated your application with a new key before revoking the old one.
Common Errors
401 Unauthorized
- Missing
Authorization
header - Invalid or expired API key
- Incorrect Bearer token format
- Verify your API key is correct
- Check the
Authorization
header format:Bearer your_api_key
- Ensure your API key hasn’t been revoked
403 Forbidden
- API key doesn’t have permission for the requested resource
- Account has restrictions or is suspended
- Verify your account status in the dashboard
- Contact support if you believe this is an error
Testing Your API Key
You can test if your API key is working with a simple request:Need Help?
If you’re having trouble with your API key:- Check our Getting Started Guide
- Join our Discord Community
- Visit our GitHub