This guide walks you through making your first API call to generate an educational video.
Generate a video with a single API call:
curl -X POST https://api.aiprep.in/api/v1/generate \
-H "X-API-Key: your-api-key" \
-H "Content-Type: application/json" \
-d '{
"query": "Explain how neural networks learn",
"language": "english",
"duration": 2
}'You'll get back a response with a job_id:
{
"job_id": "abc123-def456-ghi789",
"status": "processing",
"message": "Video generation started",
"cached": false
}Use the job_id to check on your video. You have two options:
Subscribe to live updates — no polling needed:
const response = await fetch(
`https://api.aiprep.in/api/v1/jobs/${jobId}/stream`,
{ headers: { "X-API-Key": "your-api-key" } }
);
const reader = response.body.getReader();
const decoder = new TextDecoder();
while (true) {
const { done, value } = await reader.read();
if (done) break;
const text = decoder.decode(value);
for (const line of text.split("\n")) {
if (line.startsWith("data: ")) {
const data = JSON.parse(line.slice(6));
console.log(data);
}
}
}Check the job status on an interval:
curl https://api.aiprep.in/api/v1/jobs/abc123-def456-ghi789 \
-H "X-API-Key: your-api-key"Poll every 3-5 seconds until status is "completed" or "failed".
When the job completes, the response includes a video_url:
{
"job_id": "abc123-def456-ghi789",
"status": "completed",
"progress": 100,
"video_url": "https://storage.aiprep.in/videos/abc123.mp4",
"thumbnail_url": "https://storage.aiprep.in/thumbnails/abc123.jpg",
"duration": 120
}Use video_url to embed or stream the video in your application.