Search Library
Search across available libraries. Returns finalized public libraries and accessible private repositories based on authentication.
Arguments
The search query to find libraries
Response
Array of library search resultsShow SearchResult properties
Unique identifier for the library (e.g., “/facebook/react”)
Display name of the library
Brief description of the library
ISO 8601 timestamp of last update
state
'initial' | 'finalized' | 'processing' | 'error' | 'delete'
required
Current processing state of the library
Total number of tokens in documentation
Total number of code snippets
Trust score of the library
metadata
APIResponseMetadata
required
authentication
'none' | 'personal' | 'team'
required
Authentication level used for the request
Examples
import { Context7 } from "@upstash/context7-sdk";
const client = new Context7();
const response = await client.searchLibrary("react");
console.log(`Found ${response.results.length} libraries`);
response.results.forEach(library => {
console.log(`${library.title}: ${library.description}`);
});
Use Cases
Finding Popular Libraries
const response = await client.searchLibrary("react");
// Sort by stars
const popular = response.results
.filter((lib) => lib.stars !== undefined)
.sort((a, b) => (b.stars || 0) - (a.stars || 0));
console.log("Most popular:", popular[0].title);
Checking Documentation Availability
const response = await client.searchLibrary("axios");
response.results.forEach((lib) => {
console.log(`${lib.title}:`);
console.log(` - State: ${lib.state}`);
console.log(` - Snippets: ${lib.totalSnippets}`);
console.log(` - Tokens: ${lib.totalTokens}`);
});
Getting Library Versions
const response = await client.searchLibrary("lodash");
const library = response.results[0];
if (library.versions) {
console.log(`Available versions: ${library.versions.join(", ")}`);
}