Skip to main content
Bright Data provides a powerful SERP API that allows you to query search engines (Google,Bing.DuckDuckGo,Yandex) with geo-targeting and advanced customization options, particularly useful for AI agents requiring real-time web information.

Overview

Integration details

ClassPackageSerializableJS supportVersion
BrightDataSERPlangchain-brightdataβœ…βŒPyPI - Version

Tool features

Native asyncReturns artifactReturn dataPricing
❌❌Title, URL, snippet, position, and other search result dataRequires Bright Data account

Setup

The integration lives in the langchain-brightdata package. pip install langchain-brightdata

Credentials

You’ll need a Bright Data API key to use this tool. You can set it as an environment variable:
import os

os.environ["BRIGHT_DATA_API_KEY"] = "your-api-key"
Or pass it directly when initializing the tool:
from langchain_brightdata import BrightDataSERP

serp_tool = BrightDataSERP(bright_data_api_key="your-api-key")

Instantiation

Here we show how to instantiate an instance of the BrightDataSERP tool. This tool allows you to perform search engine queries with various customization options including geo-targeting, language preferences, device type simulation, and specific search types using Bright Data’s SERP API. The tool accepts various parameters during instantiation:
  • bright_data_api_key (required, str): Your Bright Data API key for authentication.
  • search_engine (optional, str): Search engine to use for queries. Default is β€œgoogle”. Other options include β€œbing”, β€œyahoo”, β€œyandex”, β€œDuckDuckGo” etc.
  • country (optional, str): Two-letter country code for localized search results (e.g., β€œus”, β€œgb”, β€œde”, β€œjp”). Default is β€œus”.
  • language (optional, str): Two-letter language code for the search results (e.g., β€œen”, β€œes”, β€œfr”, β€œde”). Default is β€œen”.
  • results_count (optional, int): Number of search results to return. Default is 10. Maximum value is typically 100.
  • search_type (optional, str): Type of search to perform. Options include:
    • None (default): Regular web search
    • β€œisch”: Images search
    • β€œshop”: Shopping search
    • β€œnws”: News search
    • β€œjobs”: Jobs search
  • device_type (optional, str): Device type to simulate for the search. Options include:
    • None (default): Desktop device
    • β€œmobile”: Generic mobile device
    • β€œios”: iOS device (iPhone)
    • β€œandroid”: Android device
  • parse_results (optional, bool): Whether to return parsed JSON results. Default is False, which returns raw HTML response.

Invocation

Basic Usage

from langchain_brightdata import BrightDataSERP

# Initialize the tool
serp_tool = BrightDataSERP(
    bright_data_api_key="your-api-key"  # Optional if set in environment variables
)

# Run a basic search
results = serp_tool.invoke("latest AI research papers")

print(results)

Advanced Usage with Parameters

from langchain_brightdata import BrightDataSERP

# Initialize with default parameters
serp_tool = BrightDataSERP(
    bright_data_api_key="your-api-key",
    search_engine="google",  # Default
    country="us",  # Default
    language="en",  # Default
    results_count=10,  # Default
    parse_results=True,  # Get structured JSON results
)

# Use with specific parameters for this search
results = serp_tool.invoke(
    {
        "query": "best electric vehicles",
        "country": "de",  # Get results as if searching from Germany
        "language": "de",  # Get results in German
        "search_type": "shop",  # Get shopping results
        "device_type": "mobile",  # Simulate a mobile device
        "results_count": 15,
    }
)

print(results)

Customization Options

The BrightDataSERP tool accepts several parameters for customization:
ParameterTypeDescription
querystrThe search query to perform
search_enginestrSearch engine to use (default: β€œgoogle”)
countrystrTwo-letter country code for localized results (default: β€œus”)
languagestrTwo-letter language code (default: β€œen”)
results_countintNumber of results to return (default: 10)
search_typestrType of search: None (web), β€œisch” (images), β€œshop”, β€œnws” (news), β€œjobs”
device_typestrDevice type: None (desktop), β€œmobile”, β€œios”, β€œandroid”
parse_resultsboolWhether to return structured JSON (default: False)

Use within an agent

from langchain_brightdata import BrightDataSERP
from langchain_google_genai import ChatGoogleGenerativeAI
from langchain.agents import create_agent


# Initialize the LLM
llm = ChatGoogleGenerativeAI(model="gemini-2.5-flash", google_api_key="your-api-key")

# Initialize the Bright Data SERP tool
serp_tool = BrightDataSERP(
    bright_data_api_key="your-api-key",
    search_engine="google",
    country="us",
    language="en",
    results_count=10,
    parse_results=True,
)

# Create the agent
agent = create_agent(llm, [serp_tool])

# Provide a user query
user_input = "Search for 'best electric vehicles' shopping results in Germany in German using mobile."

# Stream the agent's output step-by-step
for step in agent.stream(
    {"messages": user_input},
    stream_mode="values",
):
    step["messages"][-1].pretty_print()

API reference


Connect these docs programmatically to Claude, VSCode, and more via MCP for real-time answers.