Building agents that make video
Everything the product can do, an agent can do. This page covers the parts of that which are specific to agents: choosing a transport, surviving a render that outlives the turn, and not spending credits twice.
Which transport should you use?
| If you are | Use | Why |
|---|---|---|
| Working inside Claude or ChatGPT | MCP | Add by URL, OAuth handles the key, tools are described to the model for you. |
| Writing your own agent or backend | REST | Full control over retries, storage and error handling. No MCP client needed. |
| Running in a terminal or CI | Device login | Get a key onto a headless machine without pasting a secret into it. |
A render outlives the turn. Design for that.
Renders take minutes. An agent that blocks waiting for one will time out, and an agent that polls in a tight loop will burn its own context doing nothing. Create the video, store the id, and return.
// An agent should not block a turn on a render. Hand off and return.
const res = await fetch("https://app.makeaivideo.ai/api/v1/videos", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.MAV_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({ ...input, idempotency_key: runId }),
})
const { data, error } = await res.json()
if (error) throw new Error(error.message)
if (data.status === "generating") {
// Persist data.video_id against the task, then stop. Resume when the
// webhook fires, or poll after data.poll_after_seconds.
return { video_id: data.video_id, state: "pending" }
}Resume on a video.ready webhook where you can receive one. Where you cannot, poll GET /videos/{id} and honour poll_after_seconds rather than picking your own interval.
Never pay twice for a retry
Agents retry. Frameworks retry. A dropped connection after the server accepted your create looks identical to a failure, and retrying it without a key renders and charges for a second video. Send an idempotency_key derived from the task, not from the attempt.
{
"tool": "<tool id>",
"fields": { "topic": "How compound interest works" },
"idempotency_key": "run-2026-09-04-a7f3"
}Control what it can spend
An autonomous agent with a write-scoped key can spend credits without a human in the loop. Two cheap guardrails:
# Quote before you commit. Estimating is free; rendering is not.
POST /videos/estimate -> credit cost for this job
POST /videos -> 202, render starts, credits spent- Estimate first.
POST /videos/estimateis free and lets the agent check a job against a budget before committing to it. - Scope the key down. An agent that only reports on videos should hold a
readkey. Only givewriteto something you are content to let spend. See Authentication. - Watch the balance.
GET /creditslets a long-running agent stop itself before it runs dry mid-batch.
Retry the right failures
Every error carries retryable. It is true only for 5xx and 429. A 4xx will fail identically no matter how many times an agent tries it, so branch on the flag instead of retrying everything: back off on retryable: true, and surface anything else to the caller rather than looping.
Where to go next
- MCP server — connect an assistant without writing HTTP.
- Quickstart — the full loop in curl.
- Videos reference — every field on create, edit and regenerate.
Agent questions
- Can an AI agent create videos autonomously?
- Yes. Connect over MCP and an assistant can drive the whole workflow, or call the REST API directly from your own agent. Scope the key to control what it is allowed to do.
- Should my agent use MCP or REST?
- MCP if the agent runs inside Claude or ChatGPT, since the client handles auth and tool descriptions. REST if you are writing the agent yourself and want control over retries and storage.
- How do I stop an agent charging me twice?
- Send an idempotency_key derived from the task rather than the attempt. Agents and their frameworks retry, and without a key a retried create renders and bills a second video.
- How do I cap what an autonomous agent can spend?
- Estimate before creating, and scope the key down. POST /videos/estimate is free, and an agent that only reports on videos should hold a read key rather than one that can spend credits.