Search for libraries and resolve them to Context7-compatible IDs
The resolveLibraryId tool searches Context7’s library database and returns matching results with their Context7-compatible library IDs. This is typically the first step in a documentation lookup workflow.
import { resolveLibraryId, queryDocs } from "@upstash/context7-tools-ai-sdk";import { generateText, stepCountIs } from "ai";import { openai } from "@ai-sdk/openai";const { text, toolCalls } = await generateText({ model: openai("gpt-5.2"), prompt: "What libraries are available for React?", tools: { resolveLibraryId: resolveLibraryId(), queryDocs: queryDocs(), }, stopWhen: stepCountIs(5),});// The model will call resolveLibraryId and receive a list of matching librariesconsole.log(text);
import { resolveLibraryId } from "@upstash/context7-tools-ai-sdk";import { generateText, stepCountIs } from "ai";import { openai } from "@ai-sdk/openai";const { toolCalls, toolResults } = await generateText({ model: openai("gpt-5.2"), prompt: "Find the official Next.js documentation", tools: { resolveLibraryId: resolveLibraryId(), }, stopWhen: stepCountIs(3),});// See what the model searched forfor (const call of toolCalls) { console.log("Searched for:", call.args.libraryName);}// See the resultsfor (const result of toolResults) { console.log("Found:", result.result);}