Quick Start Guide
Get up and running with ClipFM in less than 5 minutes.
Before you begin
- • You'll need a ClipFM account. Sign up here
- • Get your API key from the dashboard
- • Have Node.js 14+ installed on your system
1. Install the SDK
Choose your preferred package manager to install the ClipFM SDK:
Recommended:
The SDK provides type safety, error handling, and a better developer experience.
npm install @clipfm/sdk2. Initialize the SDK
Import and configure the SDK with your API key:
Security tip: Store your API key in environment variables, never commit it to version control.
import { ClipFM } from '@clipfm/sdk';
const clipfm = new ClipFM({
apiKey: process.env.CLIPFM_API_KEY
});3. Create your first clip
Now let's create a clip from a video URL:
Supported formats
MP4, MOV, AVI, WebM
Max video size
2GB per video
Processing time
Usually 10-60 seconds
async function createClip() {
try {
const clip = await clipfm.clips.create({
video_url: 'https://s3.amazonaws.com/my-bucket/video.mp4',
duration: 60,
style: 'viral',
title: 'My First Clip'
});
console.log('Clip created:', clip.url);
console.log('Status:', clip.status);
// The clip is now being processed
return clip;
} catch (error) {
console.error('Error creating clip:', error);
}
}4. Get notified when clips are ready
ClipFM processes videos asynchronously. You have two options to know when a clip is ready:
Option 1: Webhooks (Recommended)
Set up a webhook endpoint in your dashboard to receive real-time notifications.
Option 2: Polling
Check the clip status periodically (shown below).
// Set up a webhook endpoint
app.post('/webhooks/clipfm', async (req, res) => {
const { event, data } = req.body;
if (event === 'clip.ready') {
console.log('Clip is ready:', data.clip.url);
console.log('Thumbnail:', data.clip.thumbnail_url);
// Notify your users, update your database, etc.
}
if (event === 'clip.failed') {
console.error('Clip processing failed:', data.error);
}
res.status(200).send('OK');
});Alternative: Polling approach
If you can't use webhooks, you can poll the API to check clip status:
Note: Polling is less efficient and may hit rate limits. We recommend using webhooks for production applications.
async function waitForClip(clipId: string) {
let clip;
let attempts = 0;
const maxAttempts = 30; // 5 minutes with 10s intervals
while (attempts < maxAttempts) {
clip = await clipfm.clips.get(clipId);
if (clip.status === 'ready') {
console.log('Clip is ready!', clip.url);
return clip;
}
if (clip.status === 'failed') {
throw new Error('Clip processing failed');
}
// Wait 10 seconds before checking again
await new Promise(resolve => setTimeout(resolve, 10000));
attempts++;
}
throw new Error('Clip processing timed out');
}🎉 You're all set!
You've successfully created your first clip with ClipFM. Here's what to explore next: