Mercury uses API key authentication to secure all endpoints. This guide covers how to obtain, use, and manage your API keys securely.
All API requests to Mercury must include an API key in the request headers. The API key identifies your application and determines your access permissions and rate limits.
x-hermes-api-key: YOUR_API_KEY_HERE
curl -X GET \ 'https://your-api-name.mercury.ratiomachina.com/personas' \ -H 'Content-Type: application/json' \ -H 'x-hermes-api-key: hk_1234567890abcdef...'
const response = await fetch('/api/personas', {
method: 'GET',
headers: {
'Content-Type': 'application/json',
'x-hermes-api-key': process.env.MERCURY_API_KEY
}
});import requests
headers = {
'Content-Type': 'application/json',
'x-hermes-api-key': 'your_api_key_here'
}
response = requests.get(
'https://your-mercury-api.../personas',
headers=headers
)Never expose your API keys in client-side code, public repositories, or browser applications. Always use environment variables or secure credential management systems.
hk_1234567890abcdef1234567890abcdef12345678
Mercury API keys always start with hk_ followed by 40 characters of alphanumeric data.
Active
Key is valid and can make API calls
Deprecated
Key works but should be replaced soon
Revoked
Key is disabled and will not work
MERCURY_API_KEY=hk_1234567890abcdef... MERCURY_BASE_URL=https://your-mercury-api.../prod
const apiKey = process.env.MERCURY_API_KEY;
const baseUrl = process.env.MERCURY_BASE_URL;
if (!apiKey) {
throw new Error('MERCURY_API_KEY not found');
}MERCURY_API_KEY=hk_1234567890abcdef... MERCURY_BASE_URL=https://your-mercury-api.../prod
import os
from dotenv import load_dotenv
load_dotenv()
api_key = os.getenv('MERCURY_API_KEY')
base_url = os.getenv('MERCURY_BASE_URL')
if not api_key:
raise ValueError('MERCURY_API_KEY not found')Standard CRUD operations
Complex operations like /conversations
Message generation and skill execution
X-RateLimit-Limit: 1000 X-RateLimit-Remaining: 847 X-RateLimit-Reset: 1642694400 X-RateLimit-Window: 3600
Limit: Total requests allowed in the window
Remaining: Requests left in current window
Reset: Unix timestamp when window resets
Window: Rate limit window in seconds
HTTP/1.1 429 Too Many Requests
X-RateLimit-Limit: 1000
X-RateLimit-Remaining: 0
X-RateLimit-Reset: 1642698000
Retry-After: 3600
{
"error": "Rate limit exceeded",
"code": "RATE_LIMIT_EXCEEDED",
"message": "Too many requests. Limit: 1000/hour",
"retryAfter": 3600
}async function callMercuryAPI(url, options) {
try {
const response = await fetch(url, options);
if (response.status === 429) {
const retryAfter = response.headers.get('Retry-After');
await new Promise(resolve =>
setTimeout(resolve, retryAfter * 1000)
);
return callMercuryAPI(url, options);
}
return response;
} catch (error) {
console.error('API call failed:', error);
throw error;
}
}{
"error": "Invalid API key",
"code": "INVALID_API_KEY",
"message": "The provided API key is invalid or has been revoked"
}{
"error": "Insufficient permissions",
"code": "INSUFFICIENT_PERMISSIONS",
"message": "API key does not have permission for this operation"
}Problem: Request doesn't include the x-hermes-api-key header
Solution: Ensure every request includes the header with your valid API key
Problem: API key doesn't match expected format (hk_followed by 40 chars)
Solution: Double-check you've copied the complete API key from Mercury UI
Problem: API key was revoked in Mercury UI or has expired
Solution: Generate a new API key and update your application configuration
Now that you understand Mercury's authentication system, you're ready to start integrating with the API. Begin with the Conversation Design endpoints to create your first personas and conversations.