async function generateVideo(prompt: string) {
const response = await fetch('https://longstories.ai/api/v1/short', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'x-api-key': 'your-api-key'
},
body: JSON.stringify({
prompt,
scriptConfig: {
style: 'educational'
},
imageConfig: {
model: 'flux_schnell'
}
})
});
const { data } = await response.json();
return data.id;
}
async function checkStatus(runId: string) {
const response = await fetch(`https://longstories.ai/api/v1/short?runId=${runId}`, {
headers: {
'x-api-key': 'your-api-key'
}
});
const { data } = await response.json();
return data;
}
// Usage
const runId = await generateVideo('Create a video about the benefits of meditation');
console.log('Generation started:', runId);
// Poll for status
const checkInterval = setInterval(async () => {
const status = await checkStatus(runId);
console.log('Status:', status.status);
if (status.isCompleted) {
if (status.isSuccess) {
console.log('Video URL:', status.output.url);
} else {
console.log('Generation failed:', status.error?.message);
}
clearInterval(checkInterval);
}
}, 5000);