> ## Documentation Index
> Fetch the complete documentation index at: https://praison.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# SerpAPI Tool

> Guide for using the SerpAPI tool with PraisonAI agents.

The SerpAPI tool lets an agent search Google and other engines through the SerpAPI service.

```mermaid theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
graph LR
    subgraph "SerpAPI"
        User[User] --> Agent[Agent]
        Agent --> Tool[SerpAPIWrapper]
        Tool --> API[SerpAPI]
        API --> Result[Results]
    end

    classDef input fill:#8B0000,stroke:#7C90A0,color:#fff
    classDef process fill:#189AB4,stroke:#7C90A0,color:#fff
    classDef output fill:#10B981,stroke:#7C90A0,color:#fff

    class User,Agent input
    class Tool,API process
    class Result output
```

## Overview

The SerpAPI tool is a tool that allows you to search the web using the SerpAPI.

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
pip install langchain-community google-search-results
export SERPAPI_API_KEY="${SERPAPI_API_KEY:?Set SERPAPI_API_KEY in your shell}"
export OPENAI_API_KEY="${OPENAI_API_KEY:?Set OPENAI_API_KEY in your shell}"
```

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
from praisonaiagents import Agent, AgentTeam
from langchain_community.utilities import SerpAPIWrapper

data_agent = Agent(instructions="Search about AI job trends in 2025", tools=[SerpAPIWrapper])
editor_agent = Agent(instructions="Write a blog article")

agents = AgentTeam(agents=[data_agent, editor_agent])
agents.start()
```

## How It Works

```mermaid theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
sequenceDiagram
    participant User
    participant Agent
    participant Serp as SerpAPIWrapper
    participant API as SerpAPI

    User->>Agent: "Search for X"
    Agent->>Serp: run(query)
    Serp->>API: HTTPS request
    API-->>Serp: results
    Serp-->>Agent: parsed result
    Agent-->>User: final answer
```

## Getting Started

<Steps>
  <Step title="Simple Usage">
    1. Install dependencies (see **Overview** above)
    2. Set required API keys in your environment
    3. Run the agent example in **Overview**
  </Step>

  <Step title="With Configuration">
    Use the same tool with an agent — see the **Overview** example, or pass env vars from the sections above.
  </Step>
</Steps>

## Best Practices

<AccordionGroup>
  <Accordion title="Keep SERPAPI_API_KEY in the environment">
    Set `SERPAPI_API_KEY` in your shell or `.env`. `SerpAPIWrapper` reads it automatically — never hard-code the key.
  </Accordion>

  <Accordion title="Watch the monthly quota">
    SerpAPI plans cap total searches per month. Cache repeated queries so agents do not exhaust the quota mid-task.
  </Accordion>

  <Accordion title="Handle rate limits">
    SerpAPI returns an error when the quota is exceeded. Wrap the call in `try/except` so the agent can fall back to another search tool.
  </Accordion>
</AccordionGroup>

## Related Tools

<CardGroup cols={2}>
  <Card title="Serp Search" icon="book" href="/docs/tools/external/serp-search">
    SerpAPI wrapper
  </Card>

  <Card title="Google Search" icon="book" href="/docs/tools/external/google-search">
    LangChain Google search
  </Card>

  <Card title="Serper" icon="book" href="/docs/tools/external/serper">
    Google search API
  </Card>
</CardGroup>
