Skip to main content

Overview

Serper provides fast, affordable access to Google Search results via API. Get structured search results including web, images, news, and more.

Installation

pip install "praisonai[tools]"

Environment Variables

export SERPER_API_KEY=your_api_key_here
Get your API key from Serper.

Quick Start

from praisonai_tools import SerperTool

# Initialize
serper = SerperTool()

# Search
results = serper.search("Python programming tutorials")
print(results)

Usage with Agent

from praisonaiagents import Agent
from praisonai_tools import SerperTool

agent = Agent(
    name="Researcher",
    instructions="You are a research assistant. Use Serper to search Google.",
    tools=[SerperTool()]
)

response = agent.chat("Search Google for the latest AI news")
print(response)

Available Methods

search(query, num_results=10)

Search Google for web results.
from praisonai_tools import SerperTool

serper = SerperTool()
results = serper.search("machine learning tutorials", num_results=5)

# Returns:
# [
#     {"title": "...", "link": "...", "snippet": "...", "position": 1},
#     ...
# ]

news(query, num_results=10)

Search Google News.
news = serper.news("artificial intelligence", num_results=5)

images(query, num_results=10)

Search Google Images.
images = serper.images("sunset landscape", num_results=5)

Configuration Options

serper = SerperTool(
    api_key="your_key",    # Optional: defaults to SERPER_API_KEY
    gl="us",               # Country code
    hl="en"                # Language code
)

Function-Based Usage

from praisonai_tools import serper_search

# Quick search without instantiating class
results = serper_search("Python best practices", num_results=5)

CLI Usage

# Set API key
export SERPER_API_KEY=your_key

# Use with praisonai
praisonai --tools SerperTool "Search for Python tutorials"

Error Handling

from praisonai_tools import SerperTool

serper = SerperTool()
results = serper.search("my query")

if results and "error" in results[0]:
    print(f"Error: {results[0]['error']}")
else:
    for r in results:
        print(f"- {r['title']}: {r['link']}")

Common Errors

ErrorCauseSolution
SERPER_API_KEY not configuredMissing API keySet environment variable
Invalid API keyWrong API keyVerify at serper.dev
Rate limitedToo many requestsCheck usage limits