Authenticating with the Bright Data API: Complete Guide
Learn how to authenticate with Bright Data API. Complete guide covering API key creation, configuration, security best practices, and practical code examples.
Bright Data API authentication uses API keys for secure access. Generate API keys from the control panel to set up safe and efficient API authentication for your projects.
Bright Data API Authentication Fundamentals
Bright Data APIs use a secure authentication system where all API requests require authentication via API keys. This system ensures account security while enabling access to proxy services and data collection tools.
For basic Bright Data usage, see our complete proxy guide.
API Key Creation and Management
1. API Key Basics
Auto-Generated API Keys
- Automatically created when account is created
- Found in Account settings or Zone overview section
- Auto-generated when creating Web Unlocker or SERP API zones
API Key Features
- Secure authentication method
- Shown only once after generation
- Configurable expiration dates
- Fine-grained permission controls
2. Creating New API Keys
Step 1: Access Control Panel
- Log into Bright Data
- Navigate to Account Settings
- Ensure you're logged in as admin
Step 2: Generate API Key
- Click "Add API key" button
- Select "Add API key" in top right
- Configure settings:
- User: Specify the API key user
- Permissions: Set required permission levels
- Expiration date: Set expiry (or choose "Unlimited")
- Click "Save" to create
Important Notes
- API keys are shown only once
- Save in a secure location immediately
- Setting expiration dates is recommended for security
Practical Authentication Setup Examples
1. Python Authentication
import requests
# API key authentication
api_key = "your_api_key_here"
headers = {
"Authorization": f"Bearer {api_key}",
"Content-Type": "application/json"
}
# API request example
url = "https://brightdata.com/api/v1/zones"
response = requests.get(url, headers=headers)
if response.status_code == 200:
data = response.json()
print("Authentication successful:", data)
else:
print("Authentication error:", response.status_code)
2. Node.js Authentication
const axios = require('axios');
const apiKey = 'your_api_key_here';
const config = {
headers: {
'Authorization': `Bearer ${apiKey}`,
'Content-Type': 'application/json'
}
};
// API request example
axios.get('https://brightdata.com/api/v1/zones', config)
.then(response => {
console.log('Authentication successful:', response.data);
})
.catch(error => {
console.error('Authentication error:', error.response.status);
});
3. cURL Authentication
# cURL request with API key
curl -H "Authorization: Bearer your_api_key_here" \
-H "Content-Type: application/json" \
https://brightdata.com/api/v1/zones
Zone-Specific Authentication Methods
1. Web Unlocker API Authentication
Web Unlocker API also supports zone-specific password authentication:
# Web Unlocker authentication
import requests
customer_id = "your_customer_id"
zone_password = "your_zone_password"
proxies = {
'http': f'http://brd-customer-{customer_id}-zone-web_unlocker:{zone_password}@brd.superproxy.io:33335',
'https': f'http://brd-customer-{customer_id}-zone-web_unlocker:{zone_password}@brd.superproxy.io:33335'
}
response = requests.get('https://example.com', proxies=proxies)
2. SERP API Authentication
# SERP API authentication
import requests
api_key = "your_api_key_here"
params = {
'api_token': api_key,
'q': 'search query',
'location': 'United States'
}
response = requests.get('https://api.brightdata.com/serp/v1/search', params=params)
Check our Bright Data pricing guide for detailed pricing information on each API service.
Security Best Practices
1. Safe API Key Management
Using Environment Variables
# .env file example
BRIGHT_DATA_API_KEY=your_api_key_here
BRIGHT_DATA_CUSTOMER_ID=your_customer_id
# Loading API key from environment
import os
from dotenv import load_dotenv
load_dotenv()
api_key = os.getenv('BRIGHT_DATA_API_KEY')
Configuration File Separation
# config.py
import os
class Config:
API_KEY = os.getenv('BRIGHT_DATA_API_KEY')
CUSTOMER_ID = os.getenv('BRIGHT_DATA_CUSTOMER_ID')
BASE_URL = "https://brightdata.com/api/v1"
2. Permission Management
Principle of Least Privilege
- Grant only necessary permissions
- Create separate API keys for different use cases
- Regular key rotation
Permission Level Examples
- Read-only: Data retrieval only
- Configuration: Zone setting changes
- Admin: Full operational access
3. Error Handling
import requests
from requests.exceptions import RequestException
def make_api_request(url, headers):
try:
response = requests.get(url, headers=headers, timeout=30)
response.raise_for_status()
return response.json()
except requests.exceptions.HTTPError as e:
if e.response.status_code == 401:
print("Authentication error: Check API key")
elif e.response.status_code == 403:
print("Permission error: Insufficient privileges")
else:
print(f"HTTP error: {e.response.status_code}")
except RequestException as e:
print(f"Request error: {e}")
return None
Troubleshooting
Common Authentication Errors and Solutions
401 Unauthorized Error
- Verify API key is correctly configured
- Check API key expiration date
- Confirm header format is correct
403 Forbidden Error
- Verify API key permission levels
- Ensure API key was created by admin account
- Check if required permissions are granted
API Key Not Found
- Log in with admin account
- Check API key section in account settings
- Create new API key if needed
Frequently Asked Questions
Q1. How often should I rotate API keys? A1. We recommend rotating keys every 3-6 months for security. Consider more frequent rotation if multiple developers have access.
Q2. Can I recover a forgotten API key? A2. No, API keys are shown only once. If forgotten, create a new API key and delete the old one.
Q3. Can I use the same API key for multiple projects? A3. While technically possible, we recommend creating separate API keys for each project for better security and management.
Q4. Can I modify API key permissions after creation? A4. No, you cannot modify existing API key permissions. Create a new API key and delete the old one.
Conclusion
Bright Data API authentication uses a simple yet secure API key system. Implementing proper security measures ensures safe API usage.
Key Points:
- API keys are shown only once
- Set expiration dates for security
- Apply least privilege principle
- Regular key rotation recommended
For practical scraping implementation, see our Python + Selenium scraping tutorial.
Ready to try Bright Data API?
Start your Bright Data free trial to create API keys and experience powerful data collection tools.