Skip to main content

Getting Started

Get started with the Context7 TypeScript SDK
2 min read
Warning

Work in Progress: This SDK is currently under active development. The API is subject to change and may introduce breaking changes in future releases.

Getting Started#

@upstash/context7-sdk is a TypeScript SDK for Context7, enabling easier access to library documentation with full type coverage.

Using @upstash/context7-sdk you can:

  • Search across available libraries
  • Get documentation context for any library
  • Access library metadata including trust scores and versions

You can find the Github Repository here.

Install#

Usage#

Initializing the Client#

To use the Context7 SDK, you need an API key. You can get your API key from the Context7 Dashboard.

Using environment variables#

The SDK automatically reads from environment variables if no API key is provided in the config:

When an environment variable is set, you can initialize the client without any parameters:

Using a configuration object#

If you prefer to pass configuration in code, the constructor accepts a config object containing the apiKey value. This could be useful if your application needs to interact with multiple projects, each with a different configuration.

Note

The SDK checks for API keys in this order: 1. config.apiKey (if provided) 2. process.env.CONTEXT7_API_KEY

Production HTTP configuration#

The SDK applies a 30-second request timeout and retries transient network failures, 408, 425, 429, and 5xx responses. Only GET requests are retried; mutating requests remain single-attempt.

baseUrl defaults to https://context7.com/api and overrides where the SDK sends requests. Point it at a proxy or a self-hosted deployment to route the SDK elsewhere:

You can also configure additional headers, keepAlive, the native fetch cache mode, a client-wide abort signal, or a custom fetch implementation. The SDK always sets Authorization from the configured API key; additional headers cannot override it.

The MCP server reads the equivalent CONTEXT7_API_URL environment variable; see the Developer Guide.

Following the same convention as @upstash/redis, a signal factory can provide a fresh timeout signal for each request:

Set retry: false to make exactly one request or timeout: false to disable the default timeout.

Quick Start Example#

Error Handling#

The SDK throws Context7Error for API errors:

Next Steps#

Explore the SDK commands: