Skip to main content

API Guide

Authentication, rate limits, best practices, and integration guides for the Context7 API
5 min read

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#

MethodEndpointDescription
Search DocumentationGET /api/v3/searchFind relevant documentation without resolving a library first
Search LibraryGET /api/v2/libs/searchFind libraries by name
Get ContextGET /api/v2/contextRetrieve documentation snippets for a library
Refresh LibraryPOST /api/v1/refreshRefresh a library's documentation
Get PoliciesGET /api/v2/policiesRetrieve teamspace policy configuration
Update PoliciesPATCH /api/v2/policiesUpdate teamspace policies
Get MetricsGET /api/v2/libs/metricsRetrieve usage metrics for libraries
Add GitHub RepoPOST /api/v2/add/repo/githubSubmit a GitHub repository for processing
Add GitLab RepoPOST /api/v2/add/repo/gitlabSubmit a GitLab repository for processing
Add Bitbucket RepoPOST /api/v2/add/repo/bitbucketSubmit a Bitbucket repository for processing
Add Other Git RepoPOST /api/v2/add/repo/gitSubmit a repository from any other Git provider
Add OpenAPIPOST /api/v2/add/openapiSubmit an OpenAPI spec
Upload OpenAPIPOST /api/v2/add/openapi-uploadUpload an OpenAPI spec file
Add LLMs.txtPOST /api/v2/add/llmstxtSubmit an llms.txt file
Add WebsitePOST /api/v2/add/websiteSubmit a website for crawling
Add ConfluencePOST /api/v2/add/confluenceSubmit a Confluence space
Add NotionPOST /api/v2/add/notionSubmit Notion pages

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:

SourceExample library ID
GitHub repository/vercel/next.js
GitLab / Bitbucket / generic Git repo/<owner>/<repo> (same shape as GitHub)
Website/websites/uploadcare
llms.txt source/llmstxt/<source>
npm / package source/packages/<name> or /npm/<name>
Uploaded docs/docs/<name>

You can pin a specific version with either /owner/repo/<version> or /owner/repo@<version>:

Tip

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.

Search documentation in one request#

The Search API is the simplest way to retrieve documentation. You provide a question, and Context7 selects relevant libraries before searching and reranking their snippets.

If no documentation matches, Search returns 404 no_documentation_found; treat it as an empty result. A temporary search failure returns 503 search_failed and can be retried.

Library hints are optional and do not need to be exact. You can provide up to four names or exact Context7 library IDs. Use version with at least one library hint, and use language when you want language-specific examples to rank higher.

Choose a library yourself#

Use Search Library followed by Get Context when your application needs to inspect or choose a specific documentation source.

Info

Each Search API call counts as one request. The two-step flow makes two API calls when it searches for a library and then retrieves its documentation.

Info

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

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:

HeaderDescription
Retry-AfterSeconds until rate limit resets
RateLimit-LimitTotal request limit
RateLimit-RemainingRemaining requests in window
RateLimit-ResetUnix timestamp when limit resets

Best Practices#

Be Specific with Queries#

Use detailed, natural language queries for better results:

Add hints only when they provide useful context#

Start with only the question when the relevant library is clear from the task. Add library hints when a name is ambiguous or when the answer needs documentation from more than one product.

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:

CodeDescriptionAction
200SuccessProcess the response normally
202Accepted - Library not finalizedWait and retry later
301Moved - Library redirectedUse the new library ID from redirectUrl
400Bad Request - Invalid parametersCheck query parameters
401Unauthorized - Invalid API keyCheck your API key format (starts with ctx7sk)
403Forbidden - Access deniedCheck library access permissions or plan
404Not Found - Library doesn't existVerify the library ID
409Conflict - Resource already existsThe library has already been added
422Unprocessable - Library too large/no codeTry a different library
429Too Many Requests - Rate limit exceededWait for Retry-After header, then retry
500Internal Server ErrorRetry with backoff
503Service Unavailable - Search failedRetry later
504Gateway Timeout - Processing timed outRetry later

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.