Authentication
All API requests require authentication using an API key. Include your API key in theAuthorization header:
API Methods
Context7 provides two core API methods for retrieving documentation context.Search Library
Search for available libraries by name. Use this to find the correct library ID before fetching documentation. Endpoint:GET /api/v2/libs/search
| Parameter | Type | Required | Description |
|---|---|---|---|
query | string | Yes | Your question or task (used for relevance ranking) |
libraryName | string | Yes | Library name to search for (e.g., “react”, “nextjs”) |
Get Context
Retrieve documentation context for a specific library. Returns relevant documentation snippets based on your query. Endpoint:GET /api/v2/context
| Parameter | Type | Required | Description |
|---|---|---|---|
query | string | Yes | Your question or task (used for relevance ranking) |
libraryId | string | Yes | Library identifier from search (e.g., /facebook/react) |
type | string | No | Response format: json (default) or txt |
Complete Workflow Example
For TypeScript SDK usage with additional features, see 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.
429 status code:
Best Practices
Be Specific with Queries
Use detailed, natural language queries for better results:Cache Responses
Store documentation locally to reduce API calls and improve performance. Documentation updates are relatively infrequent, so caching for several hours or days is usually appropriate.Handle Rate Limits
Implement exponential backoff for rate limit errors:Use Specific Versions
Specify exact versions for consistent results across deployments:Error Handling
The Context7 API uses standard HTTP status codes:| Code | Description | Action |
|---|---|---|
| 200 | Success | Process the response normally |
| 202 | Accepted - Library not finalized | Wait and retry later |
| 301 | Moved - Library redirected | Use the new library ID from redirectUrl |
| 400 | Bad Request - Invalid parameters | Check query parameters |
| 401 | Unauthorized - Invalid API key | Check your API key format (starts with ctx7sk) |
| 403 | Forbidden - Access denied | Check library access permissions |
| 404 | Not Found - Library doesn’t exist | Verify the library ID |
| 422 | Unprocessable - Library too large/no code | Try a different library |
| 429 | Too Many Requests - Rate limit exceeded | Wait for Retry-After header, then retry |
| 500 | Internal Server Error | Retry with backoff |
| 503 | Service Unavailable - Search failed | Retry later |