Facebook Video Ads API: Automate UGC Ad Generation
Use Case
Build Facebook ad pipelines that generate UGC-style video creatives programmatically. Use the agent-media CLI or REST API to generate 9:16 selfie-style video ads with a generated actor, batch A/B variants across scripts and saved actors, and push finished videos directly to Meta Ads Manager via their API. See pricing.
The Problem: Manual Video Production Doesn't Scale
Facebook ad accounts burn through creatives fast. Audiences fatigue on the same video within days, so you need a constant pipeline of fresh variants. Most teams solve this by hiring creators or using browser-based tools that require manual clicks for every video.
If you are building ad infrastructure, you need an API. You need to generate videos from code, trigger new creatives when performance drops, and push them into Meta Ads Manager without a human in the loop. Browser tools and manual workflows do not fit into a CI/CD pipeline or a cron job.
The result: engineering teams either build fragile video pipelines from scratch or accept a manual bottleneck in an otherwise automated ad system.
Generate a Facebook Ad with the CLI
Use the agent-media selfie command to generate a 9:16 video ad from a text description, no photo required. The pipeline generates the actor on-model from your description, builds a character sheet and storyboard, then Seedance 2.0 animates the scene with native audio.
$ agent-media selfie \
--description "woman in her late 20s, warm and natural, kitchen morning light" \
--script "I tried every budgeting app. This one actually stuck." \
--duration 10 \
--subtitles true
$ agent-media status <job-id> --watch
$ agent-media download <job-id> -o ad.mp4
The clip renders in 9:16, ideal for Facebook Stories and Reels placements. Download the mp4 and pass it directly to Meta.
Batch Generation: A/B Test Descriptions and Scripts
Generate multiple variants in parallel by looping the CLI with different --description values, or save a agent-media character create character to keep the same face consistent across a series.
$ for description in \
"woman in her late 20s, warm and natural, kitchen morning light" \
"man in his 30s, casual, window light" \
"woman in her 40s, confident, home office"; do \
{' '}agent-media selfie --description "$description" \
--script "I tried every budgeting app. This one actually stuck." \
--duration 10; \
{' '}done
Each call returns a job id. Poll agent-media status <job-id> --watch and download the result with agent-media download <job-id> -o variant.mp4 once it completes.
Push Videos to Meta Ads Manager
Generate the video, wait for it to finish, and get the hosted mp4 URL, then upload it to your Meta Ad Account using the Marketing API.
# 1. Generate the video and wait for it to finish
$ agent-media selfie \
--description "woman in her late 20s, warm and natural, kitchen morning light" \
--script "Stop scrolling. This changed how I save money." \
--duration 10
$ agent-media status <job-id> --watch
$ agent-media inspect <job-id>
# 2. Upload to Meta via Marketing API
$ curl -X POST "https://graph.facebook.com/v21.0/$META_AD_ACCOUNT_ID/advideos" \
-H "Content-Type: application/json" \
-d '{
"access_token": "'"$META_ACCESS_TOKEN"'",
"file_url": "'"$AGENT_MEDIA_VIDEO_URL"'",
"title": "UGC Ad"
}'
From here, use the Meta Marketing API to create an adcreative referencing the video ID and attach it to your campaign. The full pipeline runs without any browser interaction.
CLI: Quick Ad Creation
Use the CLI for one-off generation or shell scripts. Run agent-media status <job-id> --watch to wait for a job to finish, then agent-media download <job-id> -o clip.mp4 to save it.
# Generate a 9:16 selfie ad
$ agent-media selfie
--description "woman in her late 20s, warm and natural, kitchen morning light" \
{' '}--script "Stop scrolling. This changed how I save money." --duration
10 --subtitles true
$ agent-media status <job-id> --watch
$ agent-media download <job-id> -o ad.mp4
# Generate 5 variants in a loop
$ for description in "woman in her late 20s, kitchen light" "man in his
30s, window light" "woman in her 40s, home office" "man in his 20s, gym
locker room" "woman in her 30s, bedroom morning light"; do \
{' '}agent-media selfie --description "$description" --script
"Stop scrolling..." --subtitles true --duration 10; \
{' '}done
Async Processing: Poll for Completion
For production pipelines, call the REST API directly and poll the returned status_url instead of blocking on a foreground command.
$ curl -X POST "https://api.agent-media.ai/v2/generate/video" \
-H "Authorization: Bearer $AGENT_MEDIA_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"prompt": "This app saved me $400 last month.",
"seconds": 10,
"aspect": "9:16"
}'
# Response:
# {
# "job_id": "job_abc123",
# "status": "submitted",
# "kind": "video",
# "model": "seedance-2.0",
# "credits_deducted": 325,
# "status_url": "https://api.agent-media.ai/v2/status/job_abc123"
# }
$ curl -H "Authorization: Bearer $AGENT_MEDIA_API_KEY" \
https://api.agent-media.ai/v1/videos/job_abc123
Cost Breakdown
Five 10-second A/B variants are 1,625 credits via API (45 plus 28 per second each), inside the Creator plan at $39/month, versus $750+ with freelance creators. View full pricing.
Why agent-media for Facebook Ad Pipelines
Related Pages
Last updated: April 2026
What do you sell?
First video free, no card