API Keys
API keys are the primary method for authenticating with the Brevo API. They provide a simple and secure way to access your account programmatically.
What are API Keys?
API keys are unique identifiers that authenticate your application when making requests to the Brevo API. Each key is a 64-character string that serves as both an identifier and a password.
Example API key: xkeysib-a1b2c3d4e5f6789012345678901234567890abcdef1234567890abcdef123456-Ab1Cd2Ef3Gh4Generating API Keys
Step-by-Step Guide
- Log into Brevo: Access your Brevo dashboard
- Navigate to Settings: Click on your profile → Settings
- Go to API Keys: Select “API Keys” from the left menu
- Create New Key: Click “Generate a New API Key”
- Name Your Key: Give it a descriptive name (e.g., “Production App”, “Development Testing”)
- Set Permissions: Choose the appropriate access level
- Generate: Click “Generate” and copy the key immediately
API Key Naming Conventions
Use descriptive names that help you identify the key’s purpose:
production-web-appstaging-environmentmobile-app-ioswebhook-listenerdata-sync-service
API Key Types and Permissions
Full Access Keys
Permissions: All API endpointsUse cases: Complete application integrationRisk level: High - protect carefullyRead-Only Keys
Permissions: GET requests onlyUse cases: Analytics, reporting, dashboardsRisk level: Low - limited accessSend-Only Keys
Permissions: Transactional email sendingUse cases: Application notifications, receiptsRisk level: Medium - can send emailsContact Management Keys
Permissions: Contact CRUD operationsUse cases: CRM integrations, form submissionsRisk level: Medium - data modificationUsing API Keys
Header Authentication
Include your API key in the api-key header:
GET /v3/account HTTP/1.1Host: api.brevo.comAccept: application/jsonContent-Type: application/jsonapi-key: YOUR_API_KEYCode Examples
JavaScript/Node.js
const brevo = require('@brevo/api');
const apiInstance = new brevo.AccountApi();apiInstance.setApiKey(brevo.AccountApiApiKeys.apiKey, process.env.BREVO_API_KEY);
// Make authenticated requestapiInstance.getAccount() .then(data => console.log('Account info:', data)) .catch(error => console.error('Error:', error));Python
import sib_api_v3_sdkfrom sib_api_v3_sdk.rest import ApiException
# Configure API keyconfiguration = sib_api_v3_sdk.Configuration()configuration.api_key['api-key'] = 'YOUR_API_KEY'
# Create API instanceapi_instance = sib_api_v3_sdk.AccountApi(sib_api_v3_sdk.ApiClient(configuration))
try: # Get account info api_response = api_instance.get_account() print(api_response)except ApiException as e: print("Exception when calling AccountApi->get_account: %s\n" % e)PHP
<?phprequire_once(__DIR__ . '/vendor/autoload.php');
// Configure API key$config = SendinBlue\Client\Configuration::getDefaultConfiguration()->setApiKey('api-key', 'YOUR_API_KEY');
// Create API instance$apiInstance = new SendinBlue\Client\Api\AccountApi( new GuzzleHttp\Client(), $config);
try { $result = $apiInstance->getAccount(); print_r($result);} catch (Exception $e) { echo 'Exception when calling AccountApi->getAccount: ', $e->getMessage(), PHP_EOL;}?>Ruby
require 'sib-api-v3-sdk'
# Configure API keySibApiV3Sdk.configure do |config| config.api_key['api-key'] = 'YOUR_API_KEY'end
# Create API instanceapi_instance = SibApiV3Sdk::AccountApi.new
begin # Get account info result = api_instance.get_account puts resultrescue SibApiV3Sdk::ApiError => e puts "Exception when calling AccountApi->get_account: #{e}"endAPI Key Security
Secure Storage
Environment Variables (Recommended)
# .env fileBREVO_API_KEY=xkeysib-your-api-key-here
# Usage in codeconst apiKey = process.env.BREVO_API_KEY;Cloud Secret Managers
- AWS Secrets Manager
- Google Secret Manager
- Azure Key Vault
- HashiCorp Vault
Security Best Practices
-
Never Hardcode Keys
// ❌ Bad - hardcodedconst apiKey = "xkeysib-a1b2c3d4...";// ✅ Good - environment variableconst apiKey = process.env.BREVO_API_KEY; -
Use Different Keys per Environment
Production: BREVO_API_KEY_PRODStaging: BREVO_API_KEY_STAGINGDevelopment: BREVO_API_KEY_DEV -
Rotate Keys Regularly
- Set calendar reminders for quarterly rotation
- Use automation tools for key rotation
- Have a rollback plan ready
-
Monitor Key Usage
- Set up alerts for unusual activity
- Review key usage logs monthly
- Track geographic access patterns
Key Management
Active Key Monitoring
Monitor your active keys in the dashboard:
Key Name: production-web-appCreated: 2024-01-15Last Used: 2024-01-20 14:30 UTCRequests Today: 1,247Status: ActiveKey Rotation Process
- Generate New Key: Create replacement key
- Update Configuration: Deploy with new key
- Monitor: Ensure new key works correctly
- Grace Period: Keep old key active for 24-48 hours
- Revoke Old Key: Delete the previous key
Emergency Key Revocation
If a key is compromised:
- Immediate Revocation: Delete key from dashboard
- Generate Replacement: Create new key immediately
- Update Applications: Deploy with new key ASAP
- Monitor Activity: Check for unauthorized usage
- Incident Report: Document the security incident
Rate Limiting and API Keys
Each API key has individual rate limits:
- Free Plan: 300 requests/day
- Starter Plan: 20,000 requests/day
- Business Plan: 50,000 requests/day
- Enterprise Plan: Custom limits
Rate Limit Headers
HTTP/1.1 200 OKX-RateLimit-Limit: 1000X-RateLimit-Remaining: 999X-RateLimit-Reset: 1640995200Handling Rate Limits
async function makeApiCall() { try { const response = await fetch(url, { headers });
if (response.status === 429) { const resetTime = response.headers.get('X-RateLimit-Reset'); const waitTime = resetTime - Math.floor(Date.now() / 1000);
console.log(`Rate limited. Waiting ${waitTime} seconds`); await new Promise(resolve => setTimeout(resolve, waitTime * 1000));
// Retry the request return makeApiCall(); }
return response.json(); } catch (error) { console.error('API call failed:', error); throw error; }}Troubleshooting API Keys
Common Error Messages
Invalid API Key (401)
{ "code": "unauthorized", "message": "Invalid API key provided"}Insufficient Permissions (403)
{ "code": "permission_denied", "message": "API key does not have required permissions"}Rate Limit Exceeded (429)
{ "code": "too_many_requests", "message": "Rate limit exceeded for API key"}Debugging Checklist
- Key is correctly formatted (64 characters)
- No extra spaces or hidden characters
- Key has required permissions
- Key is active (not revoked)
- Within rate limits
- Using correct API endpoint
- Headers properly formatted