Sign in

Recipe: bulk from CSV

Drive a batch from a CSV of scripts. Use a stable Idempotency-Key per row so re-running the script never double-charges.

typescript
import { ClipFoundry } from '@clipfoundry/sdk';
import { parse } from 'csv-parse/sync';
import { readFileSync } from 'node:fs';

const cf = new ClipFoundry({ apiKey: process.env.CLIPFOUNDRY_API_KEY });
const rows = parse(readFileSync('scripts.csv'), { columns: true });

for (const [i, row] of rows.entries()) {
  const job = await cf.jobs.create(
    { script: row.script, style: row.style ?? 'cinematic', voiceId: row.voice },
    { idempotencyKey: 'bulk-' + i + '-' + row.id },
  );
  console.log(row.id, '→', job.jobId);
}

Poll or use webhooks to collect results; the queue handles concurrency for you.