Official SDK

Node.js SDK

Full-featured JavaScript/TypeScript SDK with promise-based API, automatic retries, and TypeScript support.

Installation

npm install @butterflyapi/sdk

Quick Start

import { 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);

Available Methods

Image Processing

  • client.cartoon() - Convert images to cartoon styles
  • client.imageToImage() - Transform images with AI
  • client.backgroundRemove() - Remove image backgrounds
  • client.upscale() - Upscale images up to 4x
  • client.enhance() - Enhance image quality
  • client.faceRestore() - Restore blurry faces
  • client.watermark() - Add text watermarks
  • client.textToImage() - Generate images from text
  • client.imageCaption() - Generate image captions

Video Processing

  • client.videoGenerate() - Generate videos from prompts
  • client.cineflowDirector() - Advanced video generation with camera controls

Document Processing

  • client.htmlToPdf() - Convert HTML to PDF documents

Advanced Features

Async Job Handling

// 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);

Error Handling

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);
  }
}

TypeScript Support

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
});

Configuration Options

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
});

Package Information

  • Package: @butterflyapi/sdk
  • Version: 1.0.0
  • License: MIT
  • Size: ~50KB (minified + gzipped)
  • Dependencies: axios, form-data

Support

Need help? Check out our full documentation or contact support.