SerpAPI Tool
Multi-engine search across Google, Bing, Yahoo and more
|
The SerpAPI tool provides search functionality across multiple search engines including Google, Bing, Yahoo, and more.
Installation
import "github.com/model-box/agent-kit/tool/serp_api"
Setup
Requirements
- SerpAPI Key: Sign up at SerpAPI
- API Access: Free tier includes 100 searches per month
Environment Variables
export SERPAPI_API_KEY="your-serpapi-key"
Usage
package main
import (
"context"
"os"
"github.com/model-box/agent-kit/agent"
"github.com/model-box/agent-kit/model"
"github.com/model-box/agent-kit/session"
"github.com/model-box/agent-kit/tool/serp_api"
)
func main() {
// Create SerpAPI tools
serpTools := serp_api.NewSerpAPITools()
// Create model
model := model.Model("gpt-4o").
SetAPIKey(os.Getenv("OPENAI_API_KEY"))
// Create agent with SerpAPI tools
agent := agent.New().
SetModel(model).
SetSystemPrompt("You are a research assistant with multi-engine search capabilities.").
AddTool(serpTools.Search()).
AddTool(serpTools.ImageSearch())
// Create session and run
session := session.New(agent)
ctx := context.Background()
response, err := session.Run(ctx, []agent.ChatMessage{
agent.NewUserMessage("Search for 'golang best practices' on Google and Bing"),
}, nil)
if err != nil {
panic(err)
}
println(response.GetLastMessage().GetContent())
}
Available Tools
serpapi_search
Search multiple search engines.
Parameter | Type | Required | Description |
---|---|---|---|
query | string | Yes | The search query |
engine | string | No | "google", "bing", "baidu", "yandex", "yahoo", "ebay", "youtube" (default: "google") |
location | string | No | Location for local results (e.g., "Austin, Texas, United States") |
hl | string | No | Language code (e.g., "en", "fr", "de") (default: "en") |
gl | string | No | Country code (e.g., "us", "uk", "fr") (default: "us") |
num_results | int | No | Number of results per page (default: 10) |
start | int | No | Result offset for pagination (default: 0) |
safe_search | string | No | "active" or "off" (default: "off") |
serpapi_image_search
Search for images using Google Images.
Parameter | Type | Required | Description |
---|---|---|---|
query | string | Yes | The image search query |
location | string | No | Location for local results |
hl | string | No | Language code (default: "en") |
gl | string | No | Country code (default: "us") |
num_results | int | No | Number of results (default: 10) |
image_type | string | No | "clipart", "face", "lineart", "stock", "photo", "animated" |
size | string | No | "large", "medium", "icon" |
Supported Search Engines
- Google: Full support with organic results, knowledge graph, related searches
- Bing: Web search results
- Baidu: Chinese search engine
- Yandex: Russian search engine
- Yahoo: Web search results
- eBay: Product search
- YouTube: Video search
Location Examples
For location-based searches:
- "Austin, Texas, United States"
- "London, England, United Kingdom"
- "Paris, France"
- "Tokyo, Japan"
- "Sydney, New South Wales, Australia"
Rate Limits
- Free plan: 100 searches/month
- Basic plan: 5,000 searches/month
- Professional: 30,000 searches/month
- Business: 100,000+ searches/month
Advanced Features
SerpAPI provides additional data including:
- Knowledge graphs
- Related searches
- People also ask
- Local pack results
- Shopping results
- News results
- Video results