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 '{ "model": "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
Two per-minute limits apply to API requests, based on your plan:
- Per IP address: requests from one IP address. This is checked first.
- Per project: all requests to one project, from any IP address.
| Plan | Per IP / min | Per project / min | Requests included / month |
|---|---|---|---|
| Free | 30 | 40 | 25,000 |
| Pro | 100 | 200 | 500,000 |
| Scale | 300 | 1,000 | 5,000,000 |
| Custom | Custom | Custom | Custom |
So a Free project called from a single server can send up to 30 requests a minute. To reach the project limit of 40, the requests must come from more than one IP address. There are hourly limits too.
When rate limited, you'll receive a 429 response. Its limit_type field is ip or project, so you can tell which limit you hit. 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
Authentication errors return a JSON body with an error message:
Status and error | Cause | Solution |
|---|---|---|
401 Invalid or missing API key | No Authorization: Bearer header, or the key is wrong, revoked or expired | Send Authorization: Bearer mr_live_..., check the key in the console, and create a new one if it was revoked or expired |
403 Project is archived | The key's project is archived | Restore the project, or use a key from an active project |
429 Rate limit exceeded | Too many requests | Wait for retry_after seconds, add backoff, or upgrade your plan |
Next steps
- Migration guide: Migrate from other providers
- Security: Full security documentation
- Error handling: Handle authentication errors