const BABOU_API_KEY = process.env.BABOU_API_KEY;
const BASE_URL = 'https://api.babou.ai/api/v1';
async function createVideo() {
// 1. Create project
const projectRes = await fetch(`${BASE_URL}/projects`, {
method: 'POST',
headers: {
'Authorization': `Bearer ${BABOU_API_KEY}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
name: 'My First Video',
description: 'Created via API'
})
});
const project = await projectRes.json();
console.log('✓ Project created:', project.id);
// 2. Add chapter
const chapterRes = await fetch(
`${BASE_URL}/projects/${project.id}/chapters`,
{
method: 'POST',
headers: {
'Authorization': `Bearer ${BABOU_API_KEY}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
name: 'Introduction',
duration: 30
})
}
);
const chapter = await chapterRes.json();
console.log('✓ Chapter created:', chapter.id);
// 3. Submit prompt
const promptRes = await fetch(
`${BASE_URL}/projects/${project.id}/chapters/${chapter.id}/prompt`,
{
method: 'POST',
headers: {
'Authorization': `Bearer ${BABOU_API_KEY}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
content: 'Create an engaging intro about AI video creation'
})
}
);
console.log('✓ Prompt submitted, processing...');
// Wait for processing
await new Promise(resolve => setTimeout(resolve, 60000));
// 4. Export video
await fetch(`${BASE_URL}/projects/${project.id}/export`, {
method: 'POST',
headers: { 'Authorization': `Bearer ${BABOU_API_KEY}` }
});
console.log('✓ Export started...');
// 5. Wait for completion
while (true) {
const statusRes = await fetch(
`${BASE_URL}/projects/${project.id}/export`,
{
headers: { 'Authorization': `Bearer ${BABOU_API_KEY}` }
}
);
const status = await statusRes.json();
if (status.status === 'completed') {
console.log('✓ Video ready!');
console.log('Download:', status.download_url);
break;
}
await new Promise(resolve => setTimeout(resolve, 5000));
}
}
createVideo();