LLMs are frozen at their training cutoff and hallucinate recent facts. Giving an agent a Google search tool fixes both — and a cheap, synchronous SERP API like serp.cheap is the ideal backend because latency is predictable and per-call cost is low enough to run at agent scale.
The search tool (plain function)
import requests
def google_search(query: str, country: str = "us") -> str:
"""Search Google and return the top results as text."""
data = requests.post(
"https://api.serp.cheap/v1/search",
headers={"X-API-Key": "YOUR_KEY"},
json={"q": query, "gl": country},
timeout=30,
).json()
return "\n".join(
f'{r["position"]}. {r["title"]} — {r["link"]}\n {r.get("snippet","")}'
for r in data["organic"]
)
With the OpenAI tool-calling API
tools = [{
"type": "function",
"function": {
"name": "google_search",
"description": "Search Google for up-to-date information.",
"parameters": {
"type": "object",
"properties": {
"query": {"type": "string"},
"country": {"type": "string", "default": "us"},
},
"required": ["query"],
},
},
}]
# When the model calls google_search, run the function above and return its
# output as the tool result, then let the model answer with citations.
With LangChain
from langchain.tools import Tool
search_tool = Tool(
name="google_search",
description="Search Google for current information.",
func=lambda q: google_search(q),
)
# Add search_tool to your agent's tool list.
Why serp.cheap fits agents
- Synchronous ~2s responses — no async queue to orchestrate inside a tool call.
- Cheap at scale — agents fan out many searches; $0.0006/call (half cached) keeps runs affordable.
- Real google.com + citations — return links the model can cite, not a black-box index.
Next
- Add web search to an LLM / RAG pipeline
- No-code agents with n8n / Make / Zapier
- Google Search API in Python
Try serp.cheap
Wire it into your agent as a tool call in a few lines. 100 free searches on signup — no card required; pay-as-you-go from $0.75/1k after that, and credits stay valid for 12 months.
- Get your free API key →
- Prefer paying by card? serp.cheap is also on RapidAPI (
$0.90/1k) and Apify ($1.50/1k).