Blog/~7 min read

Automate UGC Video Ads with the agent-media API

Manually creating UGC video ads does not scale. Growth teams and agencies need 50 to 100 creative variants per campaign — different actors, scripts, hooks, and CTAs — and producing each one by hand is a bottleneck. The agent-media API lets you generate UGC videos programmatically so you can ship creative at the speed of your ad spend.

The problem: manual UGC does not scale

A typical paid social workflow looks like this: write a script, hire a creator, wait for delivery, request revisions, export variants. For a single video that takes days. For a campaign with 50 variants across different actors and hooks, it takes weeks and thousands of dollars.

Volume

Meta and TikTok reward creative volume. Winning campaigns test 20-50 ad variants per week.

Speed

By the time you get a revision back from a creator, the trend has moved on.

Integration

Growth teams want to trigger video generation from their existing pipelines — not click through a web UI.

The solution: generate UGC videos programmatically

The agent-media API exposes the full UGC pipeline — script splitting, TTS voiceover, AI talking heads, B-roll, subtitles, and music — as a single API call. You send a script and an actor, and you get back a finished MP4. No editor, no uploads, no waiting for human creators.

Everything below works with the TypeScript SDK, the Python SDK, or raw HTTP calls. Pick whichever fits your stack.

1

Get your API key

Sign up at agent-media.ai, go to your dashboard, and copy your API key. It starts with ma_. Set it as an environment variable so your code can pick it up:

.env
AGENT_MEDIA_API_KEY=ma_xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
2

Install the SDK

Install the official SDK for your language. Both packages wrap the REST API with typed helpers and automatic retries.

TypeScript
npm install @agentmedia/sdk
Python
pip install agent-media
3

Generate your first video

A single createVideo() call sends your script to the UGC pipeline and returns a video URL when it finishes. The waitForCompletion option polls until the video is ready.

generate-video.ts
import { AgentMedia } from "@agentmedia/sdk";

const client = new AgentMedia({
  apiKey: process.env.AGENT_MEDIA_API_KEY,
});

const video = await client.createVideo({
  script:
    "I tried this protein powder for 30 days and the results " +
    "were insane. It mixes clean, no chalky taste, and I actually " +
    "look forward to drinking it. Link in bio.",
  actor: "sofia",
  subtitleStyle: "hormozi",
  waitForCompletion: true,
});

console.log(video.url);
// https://pub-xxx.r2.dev/videos/abc123.mp4

That is it. One function call, one finished video. The response includes the video URL, duration, credit cost, and metadata.

4

Batch generate variants

The real power of API-driven UGC is batch generation. Loop over a matrix of actors and scripts to produce dozens of variants in parallel. Each combination becomes a unique ad creative you can A/B test.

batch-generate.ts
import { AgentMedia } from "@agentmedia/sdk";

const client = new AgentMedia({
  apiKey: process.env.AGENT_MEDIA_API_KEY,
});

const actors = ["sofia", "marcus", "aisha", "james", "luna"];

const scripts = [
  "This changed my morning routine. I wake up, one scoop, done.",
  "I was skeptical but after two weeks the results speak for " +
    "themselves. Just try it.",
  "My trainer recommended this and honestly it is the best " +
    "supplement I have ever used. Link in bio.",
];

const jobs = actors.flatMap((actor) =>
  scripts.map((script) =>
    client.createVideo({
      script,
      actor,
      subtitleStyle: "hormozi",
    })
  )
);

// 15 variants generated in parallel
const videos = await Promise.all(jobs);

for (const video of videos) {
  console.log(`[${video.actor}] ${video.url}`);
}

5 actors multiplied by 3 scripts equals 15 unique ad creatives — generated with a single script run. Scale the matrix to 10 actors and 10 scripts for 100 variants.

5

Use webhooks for async processing

For production pipelines, you probably do not want to hold a connection open while the video renders. Pass a webhookUrl and agent-media will POST the result to your endpoint when the video is ready.

with-webhook.ts
// Fire and forget — no waitForCompletion needed
const job = await client.createVideo({
  script: "This serum changed my skin in two weeks...",
  actor: "sofia",
  subtitleStyle: "karaoke",
  webhookUrl: "https://your-app.com/api/video-complete",
});

console.log(job.id); // "job_abc123" — track it in your DB

When the video finishes, agent-media sends a POST request to your webhook URL with this payload:

webhook payload
{
  "event": "video.completed",
  "jobId": "job_abc123",
  "status": "completed",
  "video": {
    "url": "https://pub-xxx.r2.dev/videos/abc123.mp4",
    "duration": 10.2,
    "actor": "sofia",
    "creditsCost": 306
  },
  "timestamp": "2026-04-14T12:34:56Z"
}

Python SDK example

The same flow works with the Python SDK. The API is identical — just a different language.

generate_video.py
import asyncio
from agent_media import AgentMedia

client = AgentMedia()

async def main():
    actors = ["sofia", "marcus", "aisha"]
    script = (
        "I tried this protein powder for 30 days and the "
        "results were insane. It mixes clean, no chalky taste."
    )

    tasks = [
        client.create_video(
            script=script,
            actor=actor,
            subtitle_style="hormozi",
            wait_for_completion=True,
        )
        for actor in actors
    ]

    videos = await asyncio.gather(*tasks)

    for video in videos:
        print(f"[{video.actor}] {video.url}")

asyncio.run(main())

CLI: one command, one video

If you prefer the terminal over code, the agent-media CLI wraps the same API in a single command. Great for quick tests, shell scripts, and CI/CD pipelines.

terminal

$ agent-media ugc \

"I tried this protein powder for 30 days and the results were insane." \

--actor sofia \

--style hormozi \

--sync

Splitting script into 3 scenes...

Generating TTS voiceover (8.4s total)...

Generating talking heads (3 scenes)...

Assembling timeline...

Rendering subtitles (hormozi)...

Adding music + CTA overlay...

Completed in 52s | 252 credits

https://pub-xxx.r2.dev/videos/def456.mp4

Pipe it into a loop, a Makefile, or a GitHub Action. The CLI returns the video URL to stdout so you can chain it with other tools.

Real-world use cases

Teams are using the agent-media API across industries to automate creative production at scale.

E-commerce product videos

Generate UGC-style product reviews for every SKU in your catalog. Feed product descriptions into the script field, pick 3-5 actors, and batch generate. Use different hooks for different audiences — price-focused for deal hunters, quality-focused for premium buyers.

SaaS testimonial ads

Create testimonial-style ads without waiting for real customer videos. Write scripts based on actual reviews and case studies, generate them as UGC videos, and run them as social proof ads on Meta and TikTok.

TikTok ad variant testing

TikTok ads burn out fast. The API lets you generate 20-50 variants per week with different actors, hooks, and subtitle styles. Feed performance data back into your script matrix to iterate on what converts.

Agency creative operations

Agencies managing multiple clients can build a single pipeline that generates creatives across all accounts. One API integration replaces dozens of creator relationships and revision cycles.

Pricing: credits per second

The API uses the same credit system as the dashboard. Video generation costs 30 credits per second of output. A 10-second video costs 300 credits, roughly $3.00.

PlanMonthlyCredits~Videos (10s)
Creator$393,900~13
Pro$696,900~23
Pro Plus$12912,900~43

Need more? Add credit packs at $39 for 3,900 credits. Purchased credits never expire. See the full breakdown on the pricing page.

Start automating UGC video creation

One API call. One finished video. Scale to hundreds of variants per campaign without touching a video editor.