@contextfetch/ai-sdk
ContextFetch web search and page contents tools for the Vercel AI SDK.
contextfetchSearch(): web search; each result carries its title, URL, published date and page content as Markdown
(by default only the parts relevant to the query).
contextfetchContents(): reads web pages as Markdown; with a query, only the parts of each page relevant to it.
Install
npm install @contextfetch/ai-sdk ai zod
Set CONTEXTFETCH_API_KEY (get a key). Without a key, requests use the keyless tier
(a small daily allowance per IP).
Usage
import { generateText, isStepCount } from "ai";
import { contextfetchContents, contextfetchSearch } from "@contextfetch/ai-sdk";
const { text } = await generateText({
model: "openai/gpt-5-mini",
prompt: "What changed in the latest pgvector release?",
tools: {
webSearch: contextfetchSearch(),
readPages: contextfetchContents(),
},
stopWhen: isStepCount(5),
});
console.log(text);
Options
Both tools take apiKey (default: the CONTEXTFETCH_API_KEY env var), baseUrl and timeoutMs.
contextfetchSearch also takes:
numResults: results per search, 1 to 25 (default 5).
content: "prunedContext" (default, the parts of each page relevant to the query), "text" (the whole page)
or "highlights" (a few key sentences).
The model can set query, includeDomains, excludeDomains and startPublishedDate on each search, and urls
(up to 10) and query on each read.
Tools return the API's results as JSON with the API's field names
(API reference). API errors are thrown as ContextFetchError from
@contextfetch/sdk; the AI SDK passes them to the model as tool
errors.
Development
npm install
npm test
CONTEXTFETCH_API_KEY=... npm test
License
MIT