Add AI video generation to a Next.js app: route handlers, spend caps, polling and webhooks A developer working on the Revana image and video generation API published a guide for integrating AI video generation into a Next.js App Router application, using separate route handlers to start jobs, report status, and serve generated files. The design adds a pre-flight quote endpoint that prices each request before creation, a hard max_cost_usd ceiling, idempotency keys, and server-side model allowlisting to prevent clients from selecting expensive models or durations. The author notes that a 5-second 720p Seedance 2.5 clip quoted $1.05 from text but $1.25 with a start image on November 5, 2026. Disclosure: I work on Revana https://revana.si?utm source=devto&utm medium=article&utm campaign=crosspost-6 , a pay-as-you-go API for image and video models. The code uses its SDK npm install revana , MIT and REST API, but the structure applies to any video API you put behind a web app. Putting a "Generate video" button in a Next.js app sounds like one fetch . In practice video generation has three properties that shape the whole design: So the shape is: a route that starts a job and returns its id, a route that reports status , a route that serves the file , and a client that polls or a webhook that tells you when it's done . This post builds those with the App Router. npm install revana .env.local REVANA API KEY=sr live ... from revana.si/dashboard; server only, no NEXT PUBLIC prefix REVANA MAX COST USD=2 the most one request may cost app/api/videos/route.ts python import Revana, { RevanaError } from "revana"; const revana = new Revana ; // reads REVANA API KEY const MAX USD = Number process.env.REVANA MAX COST USD ?? 2 ; // Only what your product offers. Never pass a client-chosen model or input straight through. const MODELS: Record