Authentication
Maniac uses API keys for authentication. This guide covers how to obtain, configure, and manage your API keys securely.
Getting Your API Key
1. Sign Up for Maniac
Visit maniac.ai and create an account:
Click "Sign Up"
Currently, we support sign ins with GitHub and Google.
2. Create an API Key
In the Maniac dashboard:
Create a new organization and project.
Navigate to Project → Settings → API Keys
Click "Create a Key"
Give your key a descriptive name (e.g., "Production API", "Development")
Click "Submit," and copy your key.
⚠️ Important: API keys are scoped per user and project.
Configuring Authentication
Method 1: Environment Variables (Recommended)
Set your API key as an environment variable:
Linux/macOS:
export MANIAC_API_KEY="mk-1234567890abcdef"Windows:
set MANIAC_API_KEY=mk-1234567890abcdefPython Code:
import os
from maniac import Maniac
# Client automatically uses MANIAC_API_KEY environment variable
client = Maniac(api_key=os.getenv("MANIAC_API_KEY"))Method 2: Configuration File
Create a configuration file at ~/.maniac/config.yaml:
api_key: mk-1234567890abcdef
environment: production
region: us-west-2Python Code:
from maniac import Maniac
# Client automatically loads from config file
client = Maniac(api_key=os.getenv("MANIAC_API_KEY"))Method 3: Direct in Code
from maniac import Maniac
client = Maniac(api_key="MANIAC_API_KEY")⚠️ Security Warning: Never hardcode API keys in production code or commit them to version control.
Security Best Practices
1. Environment-Specific Keys
Use different API keys for different environments:
import os
from maniac import Maniac
# Automatically switch based on environment
api_key = os.getenv("MANIAC_API_KEY")
environment = os.getenv("ENVIRONMENT", "development")
client = Maniac(
api_key=api_key,
environment=environment
)2. Key Rotation
Regularly rotate your API keys:
Generate a new API key
Update your environment variables/config
Test the new key
Delete the old key
3. Least Privilege Access
Create keys with minimal required permissions:
# Example: Read-only key for monitoring
permissions:
- containers:read
- metrics:read
# Example: Full access key for deployment
permissions:
- containers:*
- models:*
- data:*4. Monitoring Usage
Monitor your API key usage in the dashboard:
Track request volumes
Monitor error rates
Set up usage alerts
Review access patterns
Managing Multiple Keys
Team Environments
For team development, consider:
import os
from maniac import Maniac
# Each team member has their own key
api_key = os.getenv(f"MANIAC_API_KEY_{os.getenv('USER', 'default').upper()}")
client = Maniac(api_key=api_key)Troubleshooting Authentication
Common Error Messages
Invalid API Key
{
"error": "invalid_api_key",
"message": "The provided API key is invalid or has been revoked"
}Solution: Check that your API key is correct and hasn't been revoked.
Permission Denied
{
"error": "permission_denied",
"message": "This API key doesn't have permission for this action"
}Solution: Check your key's permissions in the dashboard.
Rate Limit Exceeded
{
"error": "rate_limit_exceeded",
"message": "Rate limit exceeded. Try again in 60 seconds"
}Solution: Implement rate limiting in your code or upgrade your plan.
Debugging Authentication Issues
Enable debug logging:
import logging
from maniac import Maniac
# Enable debug logging
logging.basicConfig(level=logging.DEBUG)
client = Maniac(api_key=os.getenv("MANIAC_API_KEY"))
# Test authentication
try:
info = client.get_account_info()
print(f"Authenticated as: {info['email']}")
except Exception as e:
print(f"Authentication failed: {e}")Environment Variables Reference
MANIAC_API_KEY
Your API key
Yes
MANIAC_ENVIRONMENT
Environment (production/sandbox)
No
MANIAC_REGION
Preferred region
No
MANIAC_TIMEOUT
Request timeout (seconds)
No
MANIAC_MAX_RETRIES
Max retry attempts
No
Next Steps
Last updated

