Most AI agents can't search the web without expensive API keys from Google or Bing. I built Scaff Search — a free, open search API that any agent can call with zero configuration.
In this tutorial, I'll show you how to build a simple AI agent in Python that can search the web, process results, and answer questions using real-time data.
The Search API
One endpoint, no auth:
curl "https://search.scaff.dev/api/search?q=python+async+tutorial"
Returns JSON with results[], each containing title, url, snippet. That's it.
Step 1: Search Function
import requests
def web_search(query: str, num_results: int = 5) -> list[dict]:
"""Search the web using Scaff Search API."""
resp = requests.get(
"https://search.scaff.dev/api/search",
params={"q": query},
timeout=10
)
resp.raise_for_status()
return resp.json()["results"][:num_results]
Step 2: Build the Agent Loop
import json
class SearchAgent:
def __init__(self, llm_client):
self.llm = llm_client
self.tools = {
"web_search": {
"description": "Search the web for current information",
"parameters": {"query": "string"},
"function": web_search
}
}
def run(self, user_query: str) -> str:
messages = [
{"role": "system", "content": f"""You are a helpful assistant with web search.
Available tools: {json.dumps({k: v['description'] for k, v in self.tools.items()})}
To search, respond with: SEARCH: <query>
After getting results, synthesize an answer."""},
{"role": "user", "content": user_query}
]
for _ in range(5): # max iterations
response = self.llm.chat(messages)
if "SEARCH:" in response:
query = response.split("SEARCH:")[1].strip()
results = web_search(query)
formatted = "\n".join(
f"- [{r['title']}]({r['url']}): {r.get('snippet', '')}"
for r in results
)
messages.append({"role": "assistant", "content": response})
messages.append({"role": "user", "content": f"Search results:\n{formatted}"})
else:
return response
return response
Step 3: Use It
# With any LLM client (OpenAI, Anthropic, local models)
agent = SearchAgent(your_llm_client)
answer = agent.run("What are the latest Python 3.13 features?")
print(answer)
The agent will:
- Decide it needs to search for current info
- Call
web_search("Python 3.13 new features 2026") - Get real results from Scaff Search
- Synthesize a grounded answer
Async Version
For production, use async:
import httpx
async def async_web_search(query: str) -> list[dict]:
async with httpx.AsyncClient() as client:
resp = await client.get(
"https://search.scaff.dev/api/search",
params={"q": query},
timeout=10
)
return resp.json()["results"]
JavaScript / Node.js
Same API works from any language:
async function webSearch(query) {
const url = new URL("https://search.scaff.dev/api/search");
url.searchParams.set("q", query);
const res = await fetch(url);
const data = await res.json();
return data.results;
}
// Use in your agent
const results = await webSearch("latest AI frameworks 2026");
console.log(results.map(r => `${r.title}: ${r.url}`));
Why This Works for AI Agents
- No API key — no signup, no billing, no rate limit headaches
- JSON by default — structured data agents can parse directly
- Fast — responses in 200-400ms
- Multi-engine — aggregates results from multiple search engines via SearXNG
- OpenAPI spec — auto-discoverable at search.scaff.dev/openapi.json
- MCP compatible — works with the Model Context Protocol
Full API Docs
-
API:
GET https://search.scaff.dev/api/search?q=your+query - Docs: search.scaff.dev/docs
- OpenAPI: search.scaff.dev/openapi.json
- LLM info: search.scaff.dev/llms.txt
- Status: search.scaff.dev/status
If you're building AI agents, RAG pipelines, or any tool that needs web search — give it a try. It's completely free and running in production.
Previously: I Built a Free Search API for AI Agents
Top comments (0)