Get Docs
Retrieve documentation for a specific library. You can get code examples or informational documentation in either JSON or text format.
Arguments
The library identifier in the format /owner/repo (e.g., /facebook/react)
Type of documentation to retrieve
code: Code examples and API documentation
info: Informational documentation and guides
Default: "code" Format of the response
json: Structured JSON with metadata
txt: Plain text format
Default: "json" Maximum number of snippets to return (1-100)
Page number for pagination (starts at 1)
Filter documentation by topic (e.g., “hooks”, “components”, “api”)
Specific version to retrieve documentation for (e.g., “18.0.0”)
Response
The response type is automatically inferred based on the format and mode parameters. All response types extend a common base with pagination and token information.
Text Format (format: "txt")
Plain text documentation content
Total number of tokens in the content
Total number of pages available
Whether there is a next page
Whether there is a previous page
Array of code snippets Show CodeSnippet properties
Title of the code snippet
Description of what the code does
Programming language (e.g., “typescript”, “javascript”)
Number of tokens in the code
Unique identifier for the code snippet
List of code examples Show CodeExample properties
Total number of tokens across all snippets
Total number of pages available
Whether there is a next page
Whether there is a previous page
metadata
APIResponseMetadata
required
authentication
'none' | 'personal' | 'team'
required
Authentication level used
Array of informational snippets Show InfoSnippet properties
Breadcrumb path to the content
The documentation content
Number of tokens in the content
Pagination information (same structure as code response)
metadata
APIResponseMetadata
required
Response metadata (same structure as code response)
Examples
Code Docs (JSON - Default)
Code Docs (Text)
Info Docs (Text)
Info Docs (JSON)
With Pagination
With Topic Filter
With Version
import { Context7 } from "@upstash/context7-sdk" ;
const client = new Context7 ();
// JSON is the default format, no need to specify
const docs = await client . getDocs ( "/facebook/react" , {
mode: "code" ,
limit: 5 ,
});
console . log ( `Retrieved ${ docs . snippets . length } code snippets` );
Use Cases
Building a Documentation Chat Bot
import { Context7 } from "@upstash/context7-sdk" ;
const client = new Context7 ({
apiKey: process . env . CONTEXT7_API_KEY ! ,
});
async function getRelevantDocs ( library : string , topic : string ) {
const docs = await client . getDocs ( library , {
mode: "code" ,
format: "json" ,
topic ,
limit: 5 ,
});
return docs . snippets . map (( snippet ) => ({
title: snippet . codeTitle ,
description: snippet . codeDescription ,
code: snippet . codeList [ 0 ]?. code ,
language: snippet . codeLanguage ,
}));
}
const reactHooksDocs = await getRelevantDocs ( "/facebook/react" , "hooks" );
Fetching All Documentation Pages
import { Context7 } from "@upstash/context7-sdk" ;
const client = new Context7 ({
apiKey: process . env . CONTEXT7_API_KEY ! ,
});
async function getAllDocs ( library : string ) {
const allSnippets = [];
let page = 1 ;
let hasMore = true ;
while ( hasMore ) {
const response = await client . getDocs ( library , {
mode: "code" ,
format: "json" ,
page ,
limit: 100 ,
});
allSnippets . push ( ... response . snippets );
hasMore = response . pagination . hasNext ;
page ++ ;
}
return allSnippets ;
}
const allReactDocs = await getAllDocs ( "/facebook/react" );
console . log ( `Total snippets: ${ allReactDocs . length } ` );
import { Context7 } from "@upstash/context7-sdk" ;
const client = new Context7 ({
apiKey: process . env . CONTEXT7_API_KEY ! ,
});
const docs = await client . getDocs ( "/facebook/react" , {
mode: "code" ,
format: "json" ,
limit: 20 ,
});
const tsExamples = docs . snippets
. filter (( snippet ) => snippet . codeLanguage === "typescript" )
. map (( snippet ) => snippet . codeList )
. flat ();
console . log ( `Found ${ tsExamples . length } TypeScript examples` );