All ModelRiver API requests require authentication using project API keys. Keys are scoped to a specific project and determine which workflows, providers, and data you can access.
API key format
All API keys use the mr_live_ prefix. When creating a key you choose an expiration (1 day, 7 days, 30 days, 60 days, 90 days, or Never). Use short-lived keys for development and longer durations for production.
Using API keys
Header authentication
Include your API key in the Authorization header:
curl -X POST https://api.modelriver.com/v1/ai \ -H "Authorization: Bearer mr_live_YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "workflow": "my-workflow", "messages": [{"role": "user", "content": "Hello"}] }'With OpenAI SDK
1from openai import OpenAI2 3client = OpenAI(4 base_url="https://api.modelriver.com/v1",5 api_key="mr_live_YOUR_API_KEY"6)1import OpenAI from "openai";2 3const client = new OpenAI({4 baseURL: "https://api.modelriver.com/v1",5 apiKey: "mr_live_YOUR_API_KEY",6});Managing API keys
Creating keys
- Navigate to your project in the ModelRiver console
- Go to Settings → API Keys
- Click Create API Key
- Choose an expiration period
- Copy and store the key securely: it won't be shown again
Revoking keys
- Go to Settings → API Keys
- Find the key to revoke
- Click Revoke
- The key is immediately invalidated
Warning: Revoking a key immediately breaks all applications using it. Ensure you've updated all deployments before revoking.
Key rotation
For security, rotate your API keys periodically:
- Create a new key in the console
- Update your deployments to use the new key
- Verify all services are working with the new key
- Revoke the old key once all services are migrated
Environment variable approach
Store keys in environment variables, never in source code:
# .env (never commit this file)MODELRIVER_API_KEY=mr_live_YOUR_API_KEY1import os2from openai import OpenAI3 4client = OpenAI(5 base_url="https://api.modelriver.com/v1",6 api_key=os.environ["MODELRIVER_API_KEY"]7)1const client = new OpenAI({2 baseURL: "https://api.modelriver.com/v1",3 apiKey: process.env.MODELRIVER_API_KEY,4});Rate limiting
API keys are subject to rate limits based on your plan:
| Plan | Requests/min | Requests/month |
|---|---|---|
| Free | 60 | 25,000 |
| Starter | 120 | 100,000 |
| Core | 300 | 500,000 |
| Growth | 600 | 2,000,000 |
When rate limited, you'll receive a 429 response. See Error handling for retry strategies.
Security best practices
- Never expose keys in client-side code: Always proxy API calls through your backend
- Use environment variables: Store keys in
.envfiles or secret management services - Add
.envto.gitignore: Prevent accidental commits of API keys - Use separate keys per environment: Production, staging, and development should each have their own keys
- Rotate keys regularly: At minimum quarterly, or immediately if compromised
- Monitor key usage: Check Request Logs for unusual activity
- Use short-lived keys for development: Choose 1-day or 7-day expiration so forgotten keys auto-expire
- Restrict network access: Use IP allowlisting where possible
Backend proxy pattern
Never call ModelRiver directly from the browser. Instead, proxy through your backend:
1// ❌ DON'T: Client-side (exposes key)2const client = new OpenAI({3 baseURL: "https://api.modelriver.com/v1",4 apiKey: "mr_live_EXPOSED_KEY", // Visible in browser dev tools!5 dangerouslyAllowBrowser: true,6});7 8// ✅ DO: Server-side proxy9// api/chat.js (your backend)10export async function POST(req) {11 const { messages } = await req.json();12 13 const response = await fetch("https://api.modelriver.com/v1/chat/completions", {14 method: "POST",15 headers: {16 "Authorization": `Bearer ${process.env.MODELRIVER_API_KEY}`,17 "Content-Type": "application/json",18 },19 body: JSON.stringify({ model: "my_workflow", messages }),20 });21 22 return response;23}Troubleshooting authentication
| Error | Cause | Solution |
|---|---|---|
401 authentication_error | Invalid or expired key | Verify key in console, create new if needed |
401 missing_api_key | No Authorization header | Add Bearer mr_live_... header |
403 forbidden | Key doesn't have access | Check key belongs to the correct project |
429 rate_limit_exceeded | Too many requests | Implement backoff or upgrade plan |
Next steps
- Migration guide: Migrate from other providers
- Security: Full security documentation
- Error handling: Handle authentication errors