How to Integrate Bright Data With Mastra
1
Prerequisites
- Node.js
- npm (latest version)
- Bright Data API key
- OpenAI API key (for GPT-4o-mini)
- Bright Data zones will be auto-created if needed
2
Obtain Your Bright Data API Key
- Log in to your Bright Data dashboard.
- Go to Account Settings.
- Generate an API key if you haven’t already done so.
- Enable SDK access for your API key
3
Obtain Your OpenAI API Key
- Go to OpenAI Platform
- Navigate to the API keys section
- Create a new API key
- Ensure you have access to the GPT-4o-mini model
4
Create a New Mastra Project Using the Template
Create a new project using the Bright Data Mastra template:
Alternatively, you can clone the repository directly:
5
Configure Environment Variables
Edit
.env
and add your API keys:6
Start the Development Server
Run the Mastra development server with hot reloading:Your Bright Data-powered web agent is now ready to use!
7
Example Usage
The web agent comes pre-configured with four powerful tools. Here’s how the agent works:Example queries you can ask the agent:
- “Search for the latest developments in quantum computing”
- “Scrape the pricing information from example.com”
- “Get details and reviews for this Amazon product: [URL]”
- “Collect LinkedIn profiles for executives at [company name]”
8
Available Tools
The integration provides four powerful tools:1. Search Tool
- Search across Google, Bing, or Yandex
- Returns results in markdown or HTML format
- Automatic anti-bot protection bypass
- Supports localized results with country codes
- Extract website content in clean markdown format
- Automatic CAPTCHA and bot detection bypass
- Country-specific proxy support
- Get pricing, ratings, reviews, and specifications
- Location-specific data with ZIP code support
- Comprehensive product information
- Fetch professional background, experience, and education
- Batch processing for multiple profiles
- Detailed skills and work history
9
Customizing Tools
You can selectively enable or disable tools:
Project Structure
Key Features
- AI-Powered Intelligence: Uses OpenAI GPT-4o-mini for intelligent reasoning
- Bright Data SDK Integration: Direct integration with Bright Data’s web data tools
- Multiple Data Sources: Search engines, web scraping, Amazon, LinkedIn
- Anti-Bot Protection: Automatic CAPTCHA and bot detection bypass
- Persistent Memory: Maintains conversation history using LibSQL
- TypeScript Support: Fully typed for better development experience
Production Deployment
Build and start your production server:Troubleshooting
“Bright Data API key is required to initialize tools”- Ensure
.env
file exists with a validBRIGHTDATA_API_KEY
- Verify the API key has SDK access permissions
- Check that the API key is not expired
- Verify
OPENAI_API_KEY
in.env
- Ensure the API key has access to GPT-4o-mini model
- Check your OpenAI account has available credits
- The integration uses
autoCreateZones: true
to automatically create zones - Check that the zones were created in your Bright Data account