How to Build an AI Video App: Architecture and Costs
How to build an AI video app on an API: a server that holds the key, jobs and webhooks, storage, per-user budgets from quotes, and pricing above your cost.
Updated 6 min read
How to build an AI video app, in one sentence: the app collects the prompt, your server prices it, checks the user's budget and submits it to a video API with a key only the server holds, and a webhook brings the finished clip back to be stored and shown. No GPU, no model hosting: with Frameport as the video API, one key reaches Seedance 2.5, Frameport Motion 1, an upscaler and the rest of the catalog, and a clip that fails costs you nothing.
This guide walks through each part: the architecture, submitting from your server, jobs and webhooks, storage, per-user budgets, and how to price the app so every clip pays for itself.
The architecture in one diagram
Phone or browser ──▶ Your server ─── quote · budget · submit ──▶ https://frameport.ai/v1
▲ │ (the key lives here, nowhere else) │
│ ▼ │
│ Your database ◀──── webhook: generation.succeeded ◀──┘
│ │ or generation.failed
│ ▼
└────── Your CDN ◀── Your storage (S3, R2…): a copy of every finished clip| Part | What it owns |
|---|---|
| The client (web or mobile) | The prompt, the options, showing progress and the result. Never the API key |
| Your server | Users, input checks, quotes, budgets, submits, webhook handling |
| Your database | Jobs, their generation ids, each user's credits |
| Your storage | The clips you keep, served from your own domain |
| The video API | Rendering, holding the price while it runs, charging only on success |
Submitting from your server
A submit is four steps, and the first three spend nothing:
- Check the input. Prompt length (up to 2,400 characters), a length and resolution on the model's grid. Read the grid from GET /v1/models and cache it, rather than hard-coding it.
- Quote it.
POST /v1/generations/quotetakes the same body, holds nothing, is not rate-limited, and returns the exact price (quotes). - Reserve it on the user. Take the quoted amount from the user's credits in your own database, or refuse with a clear message.
- Submit it, with your job id as the
Idempotency-Key, so a retry after a timeout returns the same clip, and the quote asmax_cost_usd, so the request can never cost more than you reserved.
import { randomUUID } from 'node:crypto'
const API = 'https://frameport.ai/v1'
const HEADERS = { 'Authorization': `Bearer ${process.env.FRAMEPORT_API_KEY}`, 'Content-Type': 'application/json' }
// db: your own three calls (reserve, release, attach) on your users' credits
export async function startClip(db, userId, { prompt, seconds, resolution }) {
const body = { model: 'seedance-2-5', prompt, duration: seconds, resolution, aspect_ratio: '9:16' }
const quote = await fetch(`${API}/generations/quote`, { method: 'POST', headers: HEADERS, body: JSON.stringify(body) })
.then(res => res.json())
if (quote.error) throw new Error(quote.error.message) // a length or resolution off the grid
const jobId = randomUUID()
if (!await db.reserve(userId, jobId, quote.reserved_usd)) throw new Error('Not enough credits for this clip')
const res = await fetch(`${API}/videos/generations`, {
method: 'POST',
headers: { ...HEADERS, 'Idempotency-Key': `clip-${jobId}` },
body: JSON.stringify({ ...body, max_cost_usd: quote.reserved_usd }),
})
const gen = await res.json()
if (gen.error) {
await db.release(userId, jobId) // refused: nothing was held on your balance either
throw new Error(gen.error.message)
}
await db.attach(jobId, gen.id)
return jobId
}A 429 here means the workspace is at its limits: 60 requests that start work a minute and 20 generations running at once, shared by all your users. Queue jobs on your side and give each user a fair share, for example one or two clips running at a time; the rate limits guide has a queue to start from.
Jobs, webhooks and progress
Each job in your database moves from pending to done or failed, and a webhook moves it. Add an endpoint under Webhooks in the dashboard; when a clip settles, the API sends a signed generation.succeeded or generation.failed with the whole generation in data.
- On success, copy the file to your storage, mark the job done, and settle the user's credits on
cost_usd, the amount actually charged. - On failure,
cost_usdis 0 and the hold went back to your balance: give the user their credits back too. - Twice is normal. A delivery without a
2xxis retried after 1, 5 and 15 minutes with the same id, so update the job only while it is stillpending. - Never only the webhook. A slow sweep that reads jobs still pending after ten minutes covers a delivery your server missed (polling vs webhooks).
The API reports queued and running, not a percentage. For progress, show the elapsed time next to the typical wait you measure for each model and length, and tell the user when the clip lands: your page polls your own server, or your app sends a push notification from the webhook handler. The webhooks reference has the signature check.
Storage and signed links
A finished output carries a signed url that opens without a key for about an hour, and the API does not keep files forever. So the webhook handler copies each clip to your storage at once, streaming it rather than holding it in memory:
import { S3Client } from '@aws-sdk/client-s3'
import { Upload } from '@aws-sdk/lib-storage'
import { Readable } from 'node:stream'
const s3 = new S3Client({}) // for R2 or another S3-compatible store, pass its endpoint here
export async function keepClip(gen) {
const res = await fetch(`https://frameport.ai/v1/generations/${gen.id}/content`, {
headers: { Authorization: `Bearer ${process.env.FRAMEPORT_API_KEY}` },
})
if (!res.ok) throw new Error(`download failed: ${res.status}`)
const key = `clips/${gen.id}.mp4`
await new Upload({
client: s3,
params: { Bucket: 'my-app-clips', Key: key, Body: Readable.fromWeb(res.body), ContentType: 'video/mp4' },
}).done()
return key
}Serve the copies from your CDN, behind your own signed URLs if the clips are private to each user. A paid tier can offer a sharper file without a new render: Frameport Upscale 1 takes the clip by its file id and returns it at 1080p and 2K, with the same motion, frame rate and sound.
Per-user budgets and quotes
Your users never see your balance; they see the credits your app gives them. Keep that ledger in your own database, driven by three numbers the API hands you: the quote's price before the run, reserved_usd while it runs, and cost_usd when it ends. Reserve on submit, settle on success, release on failure, and a user can never overspend, even with clips still running.
Two habits keep the workspace's own balance healthy. Watch GET /v1/balance: available_usd is what new requests can hold, held_usd what running clips have reserved, and a top-up before available_usd runs low keeps submits from failing with 402. And give staging its own workspace, with its own key, balance and limits, so tests never slow production (account and balance).
Pricing your app
Start from what each clip costs you, which the catalog states exactly:
| Clip | Model | Your cost |
|---|---|---|
| 5 s draft at 480p | Seedance 2.5 | $0.60 |
| 5 s at 720p | Seedance 2.5 | $1.35 |
| 5 s at 768p | Frameport Motion 1 | $0.30 |
| 10 s at 1080p | Frameport Motion 1 | $0.80 |
| 10 s upscaled to 1080p | Frameport Upscale 1 | $0.30 |
Then price above it. Sell credits rather than clips, and charge per second and per resolution, so long or sharp clips cost the user more, as they cost you more. Add your own costs to the API's: storage and bandwidth for the copies, payment fees, support, and the free credits you hand new users. Because a failed clip costs you nothing, the simplest fair rule is that it costs the user nothing either. And base each charge on the quote, so the number the user sees before pressing the button is the number you pay.
Model prices can change, so read them from GET /v1/models and review your credit table now and then rather than freezing it in code. There is no subscription on the API side: a balance topped up from $10 pays for every model. For a concrete product built this way, see the AI UGC video API guide; for the web side in Next.js, Next.js AI image generation; and to price any request before it runs, how to price an AI video. How a prepaid balance compares with plans is in pay as you go vs subscriptions, and ways to lower your cost per clip in reduce AI video API costs.
FAQ
How much does it cost to run an AI video app?
You pay per clip that succeeds, with nothing up front. A 5-second draft on Seedance 2.5 at 480p costs $0.60, and a 10-second clip on Frameport Motion 1 at 1080p $0.80. Add your own storage, bandwidth and payment costs on top.
Can I build an AI video app without a GPU?
Yes. The rendering happens on the API's side, so your servers only handle users, jobs and files. A small web server and a database are enough to start.
Is there a free AI video API for apps?
The account, the API key and quotes are free, and a failed clip costs nothing. Clips are paid from a prepaid balance with no subscription, so a prototype costs only the clips you actually make.
Can my mobile app call the video API directly?
No. A key inside an app can be extracted and spent by anyone. The app talks to your server, which holds the key, checks the user and submits the clip.
How do I show progress while a video renders?
The API reports queued, then running, then the result. Show the elapsed time against the usual wait for that model and length, and notify the user when the webhook brings the clip back.