New:Introducing Socket Scanning for VS Code Marketplace Extensions.Learn more →
Get Started

@contextfetch/ai-sdk

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@contextfetch/ai-sdk

ContextFetch web search and page contents tools for the Vercel AI SDK

latest
Source
npmnpm
Version
0.1.0
Version published
Weekly downloads
277
Maintainers
1
Weekly downloads
 
Created
Source

@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                                   # unit tests against a local fake API
CONTEXTFETCH_API_KEY=... npm test          # plus the live smoke test (about 2 credits)

License

MIT

Keywords

contextfetch

FAQs

Package last updated on 22 Oct 2026

Related posts