Package Manager
Install the SDK using your preferred package manager:
npm install @upstash/context7-sdk
Requirements
- Node.js 16+ or modern browser environment
- TypeScript 4.5+ (optional, for TypeScript projects)
API Key
You’ll need a Context7 API key to use the SDK. Get one from context7.com.
API keys follow the format: ctx7sk-...
Environment Setup
Environment Variable (Recommended)
Set your API key as an environment variable:
CONTEXT7_API_KEY=ctx7sk-your-api-key-here
Then initialize the client without passing the key:
import { Context7 } from '@upstash/context7-sdk';
const client = new Context7();
Direct Configuration
Alternatively, pass the API key directly to the constructor:
import { Context7 } from '@upstash/context7-sdk';
const client = new Context7({
apiKey: 'ctx7sk-your-api-key-here'
});
Never commit API keys to version control. Use environment variables or secure secret management.
TypeScript Support
The SDK is written in TypeScript and includes full type definitions. No additional @types packages are needed.
import { Context7, Library, Documentation } from '@upstash/context7-sdk';
const client = new Context7();
// Full type inference
const libraries: Library[] = await client.searchLibrary('react', 'react');
const docs: Documentation[] = await client.getContext('hooks', '/facebook/react');
Verification
Verify your installation with a quick test:
import { Context7 } from '@upstash/context7-sdk';
const client = new Context7({ apiKey: 'ctx7sk-...' });
try {
const libraries = await client.searchLibrary('test query', 'react');
console.log(`Found ${libraries.length} libraries`);
console.log('SDK is working correctly!');
} catch (error) {
console.error('SDK error:', error);
}
Next Steps
Client Configuration
Learn how to initialize and configure the Context7 client