API Keys
Create, manage, and secure your ModelRed API keys
API Keys
API Key Authentication
API keys provide secure access to the ModelRed platform. Learn how to create, manage, and secure your authentication credentials.
Creating API Keys
Generate Your API Key
Create and manage your ModelRed API keys from the dashboard.
Dashboard Steps
Log in to ModelRed Dashboard
Navigate to Settings → API Keys
Click "Create New API Key"
Copy the key immediately (it won't be shown again)
Key Format
All ModelRed API keys follow this format:
mr_[random_string]
mr_abc123...
Production key
Using API Keys
Authentication Methods
Configure your API key using environment variables or direct initialization.
Environment Variable (Recommended)
export MODELRED_API_KEY="mr_your_api_key_here"
import os
from modelred import ModelRed
# Automatically loads from MODELRED_API_KEY environment variable
async with ModelRed() as client:
account = await client.validate_api_key()
print(f"✅ Authenticated: {account['organization']['name']}")
Direct Initialization
from modelred import ModelRed
# Pass API key directly (less secure)
async with ModelRed(api_key="mr_your_api_key_here") as client:
models = await client.list_models()
Security Best Practices
Security Warning
API keys provide full access to your ModelRed account. Never commit them to version control, share them publicly, or store them in unsecured locations.
✅ Do This
❌ Avoid This
Troubleshooting
🔐 Authentication Failed
AuthenticationError: Invalid API key
Common solutions:
- • Check that the key starts with
mr_
- • Verify the key is active in your dashboard
- • Ensure you're using the correct environment key
- • Check the
MODELRED_API_KEY
environment variable
⚙️ Key Not Found
ValidationError: API key required
echo $MODELRED_API_KEY
Quick Validation Test
🧪 Test Your API Key
Run this quick test to verify your API key is working:
import asyncio
from modelred import ModelRed
async def test_api_key():
try:
async with ModelRed() as client:
account = await client.validate_api_key()
print(f"✅ API key valid!")
print(f"📊 Organization: {account['organization']['name']}")
print(f"🎯 Tier: {account['tier']}")
except Exception as e:
print(f"❌ API key test failed: {e}")
asyncio.run(test_api_key())