Resources / Developers

Generate 9:16 video ads from your backend

Turn an ad brief into a 10-second vertical video with sound, save it to your storage, and never pay for a video that failed. About 60 lines of Node.

DeveloperswithConflux Team · Dec 1, 2026 · 3 min read

By the end of this guide your server turns an ad brief into a 10-second vertical video with sound, saves it to your storage, and never pays for a video that failed.

1. Get a test key

Create a test key in the dashboard under API keys. Test keys return a short sample clip, labelled as a test, and are never charged. Everything below works the same with a live key.

CONFLUX_API_KEY=cflx_test_...
CONFLUX_VIDEO_MODEL=   # pick one from GET /v1/models?type=video
CONFLUX_WEBHOOK_SECRET=whsec_...

2. Write a prompt that sells

Short ads work best when the prompt covers five things. Keep it to two or three sentences.

PartExample for a sneaker drop
SubjectWhite high-tops, close up
SettingWet city street at night, neon reflections
CameraSlow orbit, ends on the side logo
SoundLow bass, hit on the reveal
Space for textLeave the top third clear for your headline

Do not ask for other brands' logos or for real people without consent. Those prompts are refused, with a reason and no charge.

3. Create the video

The create call returns at once with an id. The cost of the full duration is reserved now and charged only if the video succeeds.

// lib/video.ts
const BASE = "https://withconflux.com/api/v1";

export async function createAdScene(adId: string, prompt: string) {
  const res = await fetch(`${BASE}/videos/generations`, {
    method: "POST",
    headers: {
      Authorization: `Bearer ${process.env.CONFLUX_API_KEY}`,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      model: process.env.CONFLUX_VIDEO_MODEL, // from GET /v1/models?type=video
      prompt,
      duration: 10,
      aspect_ratio: "9:16",
      resolution: "1080p",
      audio: true,
      idempotency_key: `ad-${adId}-scene-1`, // a retry never makes a second video
      client_reference_id: `ad-${adId}`,      // your own id, sent back on every answer
    }),
  });
  if (res.status === 429) {
    const wait = Number(res.headers.get("retry-after") ?? 60);
    throw new Error(`Too many requests, retry in ${wait} s`);
  }
  if (!res.ok) throw new Error((await res.json()).error.message);
  return res.json(); // { id: "vgen_...", status: "queued", reserved_eur: 1 }
}

4. Receive the webhook

Add your URL under Webhooks in the dashboard. We send video.succeeded, video.failed or video.refused, signed with your secret. Check the signature before you trust the body.

// app/api/hooks/conflux-video/route.ts
import { verify } from "@/lib/verify-conflux"; // the function from the API reference

export async function POST(req: Request) {
  const raw = await req.text();
  if (!verify(raw, req.headers.get("conflux-signature") ?? "", process.env.CONFLUX_WEBHOOK_SECRET!))
    return new Response("bad signature", { status: 401 });

  const event = JSON.parse(raw);
  if (event.type === "video.succeeded") {
    await saveToYourStorage(event.data.id, event.data.video.url); // before available_until
  } else {
    await markSceneFailed(event.data.id, event.data.failure_reason); // not charged
  }
  return new Response("ok"); // answer 2xx within 10 s
}

No public URL yet? Poll instead: GET /v1/videos/generations/{id} every 5 seconds until the status is no longer queued or running.

5. Save the file

Our link works for 30 days; the date is in available_until. Copy the MP4 to your own storage as soon as it is ready. A still frame is at video.thumbnail_url.

async function saveToYourStorage(id: string, url: string) {
  const file = await fetch(url);
  await yourBucket.put(`ads/${id}.mp4`, file.body, { contentType: "video/mp4" });
}

6. Make many at once

Your account makes up to 5 videos at once (your limit is in GET /v1/videos/limits and in the x-ratelimit-* headers). Send more and they wait in line as queued, then start on their own. You do not need your own queue.

What it costs

At the time of writing, €0.10 per second at 1080p.

Batch1080p
1 scene, 10 s€1.00
5 variants of one ad€5.00
A week of daily ads, 3 formats€21.00

When something goes wrong

  • 402 insufficient_credits: the error shows the cost and your balance. Top up and send again.
  • 402 video_spend_cap_reached: your monthly video limit would be passed. Raise it in Settings.
  • 422 consent_required: you sent reference images. Add "consent": true once you have permission from any real person shown.
  • 429 rate_limited: too many requests a minute. Wait for the Retry-After seconds.
  • failure_reason: "content_refused": rewrite the prompt and try again. Not charged.
  • failure_reason: "timed_out" or "no_audio": not charged. Send a new request with a new idempotency key.

Read the full API reference.

Ready to try it?
One key, one bill, every content-AI vendor.
See the video generation API
Keep reading
We use a single analytics cookie to understand traffic to this site. Nothing loads until you choose. See our Privacy Policy.