Installation
Or with other package managers:
pnpm add @limitry/sdk
yarn add @limitry/sdk
Configuration
Basic Setup
import Limitry from '@limitry/sdk';
// Using API key directly
const client = new Limitry({ apiKey: 'limitry_sk_...' });
// Using environment variable (recommended)
const client = new Limitry({ apiKey: process.env.LIMITRY_API_KEY });
The SDK automatically reads from the LIMITRY_API_KEY environment variable if no key is provided.
Configuration Options
import Limitry from '@limitry/sdk';
const client = new Limitry({
apiKey: 'limitry_sk_...',
// Custom base URL (for self-hosted or testing)
baseURL: 'https://api.limitry.com/v1',
// Request timeout in milliseconds
timeout: 30000,
// Custom headers
defaultHeaders: { 'X-Custom-Header': 'value' }
});
Quick Example
import Limitry from '@limitry/sdk';
const client = new Limitry();
// Check if request is allowed
const check = await client.limits.check({ customerId: 'cust_123' });
if (check.allowed) {
// Make your API/LLM call here...
const response = await callYourAPI();
// Record the usage
await client.events.record({
customerId: 'cust_123',
eventType: 'api_call',
values: { requests: 1, tokens: 150 },
dimensions: { endpoint: '/chat' }
});
}
TypeScript Types
The SDK is fully typed. Import types when needed for explicit typing:
import Limitry from '@limitry/sdk';
import type { CheckResponse, Limit, Meter, Balance } from '@limitry/sdk';
const client = new Limitry();
// Types are inferred automatically
const check = await client.limits.check({ customerId: 'cust_123' });
// Explicit typing when needed (e.g., for function parameters)
function processLimit(limit: Limit) {
console.log(limit.value);
}
Next Steps