A minimal, production-shaped chat agent that searches the live web and answers with cited sources. Built with Next.js, the Vercel AI SDK and SERPdive, the web search API for AI agents.
There is a free tier, and it has no ceiling. The krill model is free and unlimited under fair use — no card, no credits, nothing to decrement. It returns the shortest set of sentences that still answers (about 700 tokens a search, roughly half what the usual alternatives send), one request at a time, at low priority. Use it to build; switch one word to mako when you need depth and steady latency.
One search call returns extracted, answer-ready page content instead of a list of links, so the agent quotes and cites facts straight from the response. Same speed as Tavily with 20.2% fewer tokens and 60.7% of decided quality duels won on a public benchmark.
Two things to have ready:
- A SERPdive API key, free at serpdive.com: 1,000 credits every month, no card.
- Model access through the Vercel AI Gateway, which authenticates automatically on Vercel deployments. No provider API key needed.
- Streaming chat UI with the AI SDK's
useChat, tool-call activity shown inline - Real-time web search as a tool: the model decides when to search, in any language
- Cited answers: every search result carries the extracted page content, so the model links claims to sources
- Source chips under each answer, linking to the pages the answer came from
- Zero database, zero auth: one route handler, one page, deploy and chat
- Model-agnostic: point
AI_MODELat any AI Gateway model
git clone https://github.com/serpdive/ai-agent-web-search
cd ai-agent-web-search
npm install
cp .env.example .env.local # add SERPDIVE_API_KEY and AI_GATEWAY_API_KEY
npm run devOpen http://localhost:3000 and ask about anything current.
The whole agent is one route handler:
// app/api/chat/route.ts
const result = streamText({
model: process.env.AI_MODEL ?? "anthropic/claude-sonnet-5",
system: SYSTEM_PROMPT,
messages: await convertToModelMessages(messages),
tools: {
webSearch: serpdiveSearch({ maxResults: 5 }),
},
stopWhen: isStepCount(5),
});serpdiveSearch exposes one tool the model can call with a query and an optional retrieval depth: mako (default) returns the fact-carrying sentences of each source, moby reads whole pages when deep context is needed. The response is the raw SERPdive payload, results already extracted and sized for a context window, which the UI also uses to render source chips.
| Variable | Required | Description |
|---|---|---|
SERPDIVE_API_KEY |
Yes | Free at serpdive.com/dashboard/keys |
AI_GATEWAY_API_KEY |
Local dev only | Auto-provided on Vercel via OIDC |
AI_MODEL |
No | AI Gateway model string, defaults to anthropic/claude-sonnet-5 |
MIT