Build a TikTok Ad Pipeline with the agent-media API | agent-media
Use Case
TikTok ad accounts burn through creatives fast. Instead of hiring creators or building a video pipeline from scratch, call the agent-media API. Generate 9:16 UGC videos with lip-synced AI actors, TikTok-style subtitles, and energetic delivery. Batch generate variants, get webhook callbacks when videos are ready, and push directly to your ad platform. $3 per video.
Generate a TikTok Ad in 10 Lines
Install the TypeScript SDK and create a TikTok-optimized UGC video. The SDK handles voiceover generation, lip-sync, subtitle rendering, and final assembly. You get back a download URL.
import {'{ AgentMedia }'}{' '}
from{' '}
"agent-media-sdk";
const client ={' '}
new{' '}
AgentMedia(process.env.AGENT_MEDIA_API_KEY);
const video ={' '}
await client.videos.create({'{'}
{' '}script: "Stop scrolling. This app saved me two hours
every morning.",
{' '}actor: "sofia",
{' '}aspect_ratio: "9:16",
{' '}subtitle_style: "tiktok",
{' '}voice_tone: "energetic",
{' '}duration: 10,
{'}'});
console.log(video.download_url);{' '}
{'// → https://cdn.agent-media.ai/v/abc123.mp4'}
Batch Generate 10 Variants with Different Actors
TikTok ad testing requires volume. Same script, different faces. Use Promise.all to generate multiple variants in parallel. Each variant uses a different AI actor from the 200+ available.
const actors = [
"sofia", "emma", "naomi",
"marco", "liam",
{' '}"priya", "aisha", "carlos",
"mei", "jordan"];
const script =
"Stop scrolling. This app saved me two hours every
morning.";
const videos ={' '}
await Promise.all(
{' '}actors.map((actor) =>
{' '}client.videos.create({'{'}
{' '}script,
{' '}actor,
{' '}aspect_ratio: "9:16",
{' '}subtitle_style: "tiktok",
{' '}voice_tone: "energetic",
{' '}duration: 10,
{' '}{'}'})
{' '})
);
{'// 10 TikTok-ready videos, each with a different actor'}
videos.forEach((v) => console.log(v.actor, v.download_url));
Async Pipeline with Webhooks
For production pipelines, use webhook callbacks instead of polling. Submit video jobs with a webhook_url, and agent-media will POST the result when the video is ready. This lets you decouple generation from downstream processing like uploading to TikTok Ads Manager.
{'// 1. Submit job with webhook callback'}
const job ={' '}
await client.videos.create({'{'}
{' '}script: "This changed everything for me.",
{' '}actor: "sofia",
{' '}aspect_ratio: "9:16",
{' '}subtitle_style: "tiktok",
{' '}voice_tone: "energetic",
{' '}webhook_url: "https://your-app.com/api/video-ready",
{'}'});
{'// 2. Your webhook receives the completed video'}
export async function{' '}
POST(req: Request) {'{'}
{' '}const {'{ video_id, download_url, status }'} ={' '}
await req.json();
{' '}
{'// Upload to TikTok Ads Manager, notify Slack, etc.'}
{'}'}
CLI for Quick Iteration
Use the CLI for ad-hoc generation and testing before wiring up the API. Same capabilities, faster feedback loop.
Install the agent-media CLI
globally and log in with your API key.
$ npm install -g
agent-media-cli
$ agent-media
login
Pass your script, pick an actor, and set TikTok-native
defaults. The --sync{' '}
flag waits for the video to finish and returns the download URL.
$ agent-media ugc
"Stop scrolling. This product saved me two hours every
morning." \
{' '}--actor sofia \
{' '}--style tiktok \
{' '}--duration 10 \
{' '}--tone energetic \
{' '}--sync
Same script, different actors. Use a shell loop to generate
multiple variants for A/B testing.
$ for actor in
sofia emma naomi marco liam; do
{' '}agent-media ugc "Stop scrolling..." \
{' '}--actor $actor --style tiktok --tone energetic
--sync
{' '}done
Cost per Video
At $3 per video, generating 10 TikTok ad variants costs $30. Hiring UGC creators for the same batch: $1,500 to $5,000 plus revision rounds. View full pricing.
Why Developers Build on agent-media
Resources
Last updated: April 2026