Add AI video generation to a Next.js app: route handlers, spend caps, polling and webhooks
Disclosure: I work on Revana , 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: It's slow. A 5-second clip takes…
Here is a summary of the key points from the source about adding AI video generation to a Next.js app:
The key considerations for implementing AI video generation in a Next.js app are that the process is slow, can cost money, and may occasionally fail. To handle this, a route handler should be used that:
1. Accepts a POST request with the video generation parameters
2. Returns the job ID to start the generation process
3. Provides a status route to check the progress
4. Has a file serving route to retrieve the generated video
5. Uses polling or webhooks to notify the client when generation completes
The code sets up a Next.js route handler at app/api/videos/route.ts that uses the Revana SDK to start video generation jobs with configurable cost limits. It validates the request, determines video specs, prices the generation, and returns the job ID. Status can be polled or a webhook can be used to notify when the job is done. The server must manage costs and retries properly.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.