Node.js & TypeScript SDK
Official @smallpict/sdk documentation for Node.js, Next.js, and TypeScript applications.
Node.js & TypeScript SDK (@smallpict/sdk)
The official SmallPict Node.js SDK provides full TypeScript type definitions, automated HMAC-SHA256 request signing, stream support, and built-in retries.
📦 Installation
npm install @smallpict/sdk
# or
bun add @smallpict/sdk
# or
pnpm add @smallpict/sdk
🚀 Quickstart Example
import { SmallPict } from '@smallpict/sdk';
import fs from 'node:fs';
const client = new SmallPict({
apiKey: process.env.SMALLPICT_API_KEY!,
secretKey: process.env.SMALLPICT_SECRET_KEY!,
retryConfig: {
maxRetries: 3,
baseDelayMs: 500
}
});
// 1. Optimize an image buffer
const inputBuffer = fs.readFileSync('hero.jpg');
const result = await client.optimize(inputBuffer, {
format: 'avif',
quality: 80,
maxWidth: 1920
});
console.log(`Optimized URL: ${result.url}`);
console.log(`Saved: ${result.savingsPercentage}% (${result.bytesSaved} bytes)`);
// 2. Check current monthly quota
const quota = await client.getQuota();
console.log(`Quota Used: ${quota.bytesUsed} / ${quota.quotaLimitBytes} bytes`);
// 3. Purge edge CDN cache
await client.purgeCdn([result.url]);
⚙️ Configuration Options
interface ClientOptions {
apiKey: string;
secretKey: string;
baseUrl?: string; // Default: https://api.smallpict.app/v1
timeoutMs?: number; // Default: 30000 (30 seconds)
fallbackMode?: 'throw' | 'passthrough'; // Default: 'throw'
retryConfig?: {
maxRetries?: number; // Default: 3
baseDelayMs?: number; // Default: 500
};
}
