Skip to main content

Authentication

All API requests require authentication using an API key. Include your API key in the Authorization header:
Get your API key at context7.com/dashboard. Learn more about creating and managing API keys.

API Methods

Library ID format

A library ID is the URL path of the library on context7.com. If the library page is at https://context7.com/websites/uploadcare, its ID is /websites/uploadcare. The same ID works for every endpoint that accepts a libraryId or libraryName — including Get Context and Refresh Library. Use /owner/repo for GitHub repositories, or /<source>/<id> for other sources: You can pin a specific version with either /owner/repo/<version> or /owner/repo@<version>:
Don’t know the ID for a library? Find it on context7.com — the URL path of the library page is the ID. Or call Search Library and use the id from the response.

Complete Workflow Example

For TypeScript SDK usage, see Search Library and Get Context.

Response Schemas

Search response

GET /api/v2/libs/search returns a JSON object:
  • results — array of matching libraries ranked by relevance, using the Library ID format for id.
  • searchFilterAppliedtrue when the teamspace’s public library access settings filtered the results (e.g. verified-only or a hand-picked list).
  • totalTokens is the total number of indexed tokens in the library’s documentation, not the amount returned by a single context request — a context request returns a reranked subset of snippets.

Get Context

GET /api/v2/context returns a ContextResponse JSON object: CodeSnippetcodeTitle, codeDescription, codeLanguage, codeTokens (token count for the snippet), codeId (URL to the source location), pageTitle (title of the documentation page), and codeList (the examples array) are all present. Snippets recovered from the dynamic source-code index additionally carry isDynamic and sourceFile. The per-snippet examples array is codeList — not codeExamples. Each entry is a { "language", "code" } pair describing a single code example:
InfoSnippetcontent and contentTokens (token count for the content) are required; pageId (URL to the source page) and breadcrumb (navigation path) are returned when available.

Rate Limits

  • Without API key: Low rate limits and no custom configuration
  • With API key: Higher limits based on your plan
  • View current usage and reset windows in the dashboard.
When you exceed rate limits, the API returns a 429 status code with these headers:

Best Practices

Be Specific with Queries

Use detailed, natural language queries for better results:

Cache Responses

Documentation updates are relatively infrequent, so caching responses for several hours or days reduces API calls and improves performance.

Handle Rate Limits

Implement exponential backoff for rate limit errors:

Use Specific Versions

Pin to a specific version for consistent results. Both / and @ syntax are supported:

Error Handling

The Context7 API uses standard HTTP status codes: All errors return a JSON object with error and message fields:
For 301 redirects, the response also includes a redirectUrl field pointing to the new library ID.

SDK and Libraries

For TypeScript SDK installation and usage, see the Getting Started guide.