Skip to main content

Search

Find relevant documentation without resolving a library first
2 min read

Search#

Search Context7 documentation in one request. Context7 selects relevant libraries, searches them in parallel, and returns the best snippets together.

The SDK returns structured JSON by default, consistent with its other methods. Set type to txt when you need plain text for an LLM prompt. The REST endpoint defaults to text unless you request type=json.

Arguments#

querystringrequired#

The question or task to search for. Specific, natural language questions produce the best results.

optionsSearchOptions#
Show properties
librariesstring[]#

Up to four library names or Context7 library IDs. These hints narrow the search when you already know which products are relevant.

versionstring#

A version to search. Provide at least one library hint. With one library hint, the version is strict and Search returns 404 if no matching tag exists. With multiple libraries, it is a contextual preference.

languagestring#

A programming language to prefer when ranking snippets, such as TypeScript or Python. This is a preference, so Context7 can still return product documentation when a language-specific snippet is unavailable.

type'json' | 'txt'#

The response format. The SDK default is json.

signalAbortSignal#

An abort signal for cancelling this request.

timeoutnumber | false#

A timeout in milliseconds for this request. Use false to disable the client timeout.

cacheCacheSetting#

A native fetch cache mode. Use false to omit the cache option.

Text response#

JSON response#

JSON responses return a SearchResponse object with codeSnippets, infoSnippets, and optional rules. Each snippet includes the libraryId that it came from.

Use a library hint with version when your question depends on a particular release.

Library names do not need to be exact. Use a Context7 library ID when you need to select a specific documentation source.

If nothing matches, client.search() throws Context7Error with status 404. A temporary search failure returns status 503 and follows the SDK retry policy.