Full-featured JavaScript/TypeScript SDK with promise-based API, automatic retries, and TypeScript support.
npm install @butterflyapi/sdkimport { ButterflyAPI } from '@butterflyapi/sdk';
const client = new ButterflyAPI({
apiKey: 'your_api_key_here'
});
// Cartoonify an image
const result = await client.cartoon({
imageUrl: 'https://your-bucket.s3.amazonaws.com/photo.jpg',
style: 'pixar'
});
console.log('Result:', result.outputUrl);client.cartoon() - Convert images to cartoon stylesclient.imageToImage() - Transform images with AIclient.backgroundRemove() - Remove image backgroundsclient.upscale() - Upscale images up to 4xclient.enhance() - Enhance image qualityclient.faceRestore() - Restore blurry facesclient.watermark() - Add text watermarksclient.textToImage() - Generate images from textclient.imageCaption() - Generate image captionsclient.videoGenerate() - Generate videos from promptsclient.cineflowDirector() - Advanced video generation with camera controlsclient.htmlToPdf() - Convert HTML to PDF documents// Submit job
const job = await client.videoGenerate({
prompt: 'A cat playing piano',
duration: '5s',
tier: 'standard'
});
// Poll for completion
const result = await client.waitForJob(job.jobId);
console.log('Video ready:', result.outputUrl);try {
const result = await client.cartoon({
imageUrl: 'https://your-bucket.s3.amazonaws.com/photo.jpg',
style: 'anime'
});
} catch (error) {
if (error.code === 'INSUFFICIENT_CREDITS') {
console.error('Not enough credits');
} else if (error.code === 'INVALID_IMAGE') {
console.error('Invalid image URL');
} else {
console.error('API error:', error.message);
}
}import { ButterflyAPI, CartoonStyle, UpscaleFactor } from '@butterflyapi/sdk';
const client = new ButterflyAPI({ apiKey: 'YOUR_BUTTERFLY_API_KEY' });
const result: any = await client.cartoon({
imageUrl: 'https://your-bucket.s3.amazonaws.com/photo.jpg',
style: 'pixar' as CartoonStyle
});const client = new ButterflyAPI({
apiKey: 'your_api_key',
baseUrl: 'https://butterflyapi.com/api/v1', // Optional
timeout: 30000, // 30 seconds
retries: 3, // Automatic retries
webhookUrl: 'https://yoursite.com/webhook' // Optional webhook
});@butterflyapi/sdkNeed help? Check out our full documentation or contact support.