Skip to main content

Building an AI startup?

You might be eligible for our Startup Program. Get fully funded access to the infrastructure you’re reading about right now (up to $20K value).
The Bright Data SDK integration is now available in Mastra, bringing powerful web scraping and data extraction capabilities to AI agents. This integration enables structured data extraction from over 40 platforms, including Amazon, LinkedIn, and major search engines like Google, Bing, and Yandex. Mastra agents can perform tasks like web scraping with anti-bot protection, running search queries, extracting Amazon product data, and collecting LinkedIn profiles-all with minimal setup. This makes it easy to build intelligent agents that can reason, act, and fetch real-time web data for research, automation, and competitive analysis.

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

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
2. Scrape Tool
  • Extract website content in clean markdown format
  • Automatic CAPTCHA and bot detection bypass
  • Country-specific proxy support
3. Amazon Product Tool
  • Get pricing, ratings, reviews, and specifications
  • Location-specific data with ZIP code support
  • Comprehensive product information
4. LinkedIn Collect Profiles Tool
  • 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:

How the project is structured

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

How to deploy to production

Build and start your production server:

Troubleshooting

“Bright Data API key is required to initialize tools”
  • Ensure .env file exists with a valid BRIGHTDATA_API_KEY
  • Verify the API key has SDK access permissions
  • Check that the API key is not expired
“OpenAI API key not found”
  • Verify OPENAI_API_KEY in .env
  • Ensure the API key has access to GPT-4o-mini model
  • Check your OpenAI account has available credits
Tool initialization failures
  • The integration uses autoCreateZones: true to automatically create zones
  • Check that the zones were created in your Bright Data account

Where to learn more