Documentation

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

2

Navigate to Settings → API Keys

3

Click "Create New API Key"

4

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)

BASH
export MODELRED_API_KEY="mr_your_api_key_here"
PYTHON
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

PYTHON
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

Use environment variables for API keys
Use different keys for dev/staging/production
Rotate keys regularly (every 90 days)
Revoke unused or compromised keys immediately

Avoid This

Never hardcode API keys in source code
Don't commit keys to Git repositories
Don't share keys via email or chat
Don't use production keys in development

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
DEBUG COMMAND
echo $MODELRED_API_KEY

Quick Validation Test

🧪 Test Your API Key

Run this quick test to verify your API key is working:

PYTHON
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())

Next Steps