· 7 min read
Automate UGC Video Ads with the agent-media API
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.
The solution: generate UGC videos programmatically
The agent-media API exposes the full UGC pipeline — script splitting, a realistic AI actor, natural speech delivery, scene direction, and styled subtitles — 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.
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:
AGENT_MEDIA_API_KEY=ma_xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Install the SDK
Install the official SDK for your language. Both packages wrap the REST API with typed helpers and automatic retries.
npm install @agentmedia/sdk
pip install agent-media
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.
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://media.agent-media.ai/videos/abc123.mp4
That is it. One function call, one finished video. The response includes the video URL, duration, credit cost, and metadata.
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.
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.
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.
// 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:
{
"event": "video.completed",
"jobId": "job_abc123",
"status": "completed",
"video": {
"url": "https://media.agent-media.ai/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.
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.
$ 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 actor + character sheet...
Generating talking heads (3 scenes)...
Assembling timeline...
Rendering subtitles (hormozi)...
Adding music + CTA overlay...
Completed in 52s | 252 credits
https://media.agent-media.ai/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.
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.
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.
Published April 14, 2026 by the agent-media team. Code examples use the latest SDK versions as of publication. Check the API docs for the most up-to-date reference.
Related: Best AI UGC Generator for Developers Create UGC Videos in 60 Seconds AI UGC Pricing Comparison 2026