@upstash/context7-tools-ai-sdk provides Vercel AI SDK compatible tools and agents that give your AI applications access to up-to-date library documentation.
When building AI-powered applications with the Vercel AI SDK, your models often need accurate information about libraries and frameworks. Instead of relying on potentially outdated training data, Context7 tools let your AI fetch current documentation on-demand, ensuring responses include correct API usage, current best practices, and working code examples.
The package gives you two ways to integrate:
- Individual tools (
resolveLibraryIdandqueryDocs) that you add to your existinggenerateTextorstreamTextcalls - A pre-built agent (
Context7Agent) that handles the entire documentation lookup workflow automatically
Both approaches work with any AI provider supported by the Vercel AI SDK, including OpenAI, Anthropic, Google, and others.
Installation#
Prerequisites#
You'll need:
- A Context7 API key from the Context7 Dashboard
- An AI provider SDK (e.g.,
@ai-sdk/openai,@ai-sdk/anthropic)
Configuration#
Set your Context7 API key as an environment variable:
The tools and agents will automatically use this key.
Quick Start#
Using Tools with generateText#
The simplest way to add documentation lookup to your AI application:
Using the Context7 Agent#
For a more streamlined experience, use the pre-configured agent:
Using Tools with streamText#
For streaming responses:
Explicit Configuration#
You can also pass the API key directly if needed:
How It Works#
The tools follow a two-step workflow:
-
resolveLibraryId- Searches Context7's database to find the correct library ID for a given query (e.g., "react" →/reactjs/react.dev) -
queryDocs- Fetches documentation for the resolved library using the user's query to retrieve relevant content
The AI model orchestrates these tools automatically based on the user's prompt, fetching relevant documentation before generating a response.