Automate E-commerce Video Ads with the SDK | agent-media

Use Case

Your product catalog has hundreds of SKUs. Each one needs video for product pages, Meta Ads, and TikTok. Hiring creators does not scale. agent-media gives you a Python SDK, a TypeScript client, and a CLI to generate UGC-style product videos programmatically. Pass a script, an actor, and a product image. Get a finished mp4 back. ~$3 per video. See pricing.

Python SDK: Generate Videos from Your Product Catalog

Read products from a database or CSV, generate a video for each one. This example loops through a product table and creates UGC videos with product images as B-roll.

import csv
from agent_media{' '}
 import AgentMedia
client = AgentMedia(api_key="your-api-key")
# Read products from CSV
with open("products.csv") as f:
{' '}products = list(csv.DictReader(f))
for product in products:
{' '}video = client.ugc.create(
{' '}script=product["script"],
{' '}actor="sofia",
{' '}product_image=product["image_url"],
{' '}broll=True,
{' '}sync=True,
{' '})
{' '}print(f"{'{'}product['name']{'}'}: {'{'}video.url{'}'}")

TypeScript: Trigger from E-commerce Webhooks

Wire up a Shopify or WooCommerce webhook so every new product automatically gets a video. This example handles a products/create webhook and queues a video generation job.

import {'{ '}AgentMedia{' }'} from "agent-media";
const client = new AgentMedia({'{ '}apiKey: process.env.AGENT_MEDIA_KEY{' }'});
export async function handleProductCreated(product: {'{'}{' '}
{' '}name: string; description: string; image_url: string;
{'}'}) {'{'}
{' '}const script = `I just tried ${'{'}product.name{'}'} and it's amazing. `
{' '}+ `${'{'}product.description{'}'}`;
{' '}const video = await client.ugc.create({'{'}
{' '}script,
{' '}actor: "sofia",
{' '}productImage: product.image_url,
{' '}broll: true,
{' '}{'}'});
{' '}return video.url;
{'}'}

Batch Generation from CSV or Database

Most e-commerce catalogs live in a database or a product feed CSV. The SDK accepts any iterable of product records. Read from Postgres, a Shopify export, or a plain CSV file. Each record needs three fields: a script (or product description to generate one from), an actor name, and a product image URL or local path.

The --product-image flag (CLI) or product_image parameter (SDK) inserts your product photo as a B-roll cutaway in the video. The actor speaks to camera, then the video cuts to your product image before returning to the actor. No separate B-roll shoot required.

For large catalogs (500+ SKUs), use the SDK's async mode. Submit all jobs without waiting, then poll for completion or register a webhook callback. The platform processes jobs in parallel, so 500 videos complete in hours, not days.

CLI: Quick One-off Generation

For quick tests or one-off videos, use the CLI directly. No code required.

# Install
$ npm install -g
 agent-media-cli
$ agent-media login
# Generate a single product video
$ agent-media ugc
 "This moisturizer changed my skin in two weeks." \
{' '}--actor sofia \
{' '}--product-image ./product.jpg \
{' '}--broll --sync
# Batch generate from CSV
$ while IFS=, read -r
 name script img; do
{' '}agent-media ugc "$script" \
{' '}--actor sofia --product-image "$img" --broll --sync
{' '}done {'<'} products.csv

Cost at Scale

Credits cost 30 per second of video. A 10-second product video uses 300 credits (~$3). Async batch jobs run in parallel on the platform. View full pricing.

Why Developers Choose agent-media

Integration Patterns

Shopify webhook pipeline. Listen for products/create and products/update events. Extract the product title, description, and featured image. Call the SDK to generate a video. Upload the result back to the product's media via the Shopify Admin API.

Nightly batch job. Query your product database for items without videos. Run a Python script as a cron job that generates videos for new SKUs overnight. Use async mode for throughput.

A/B testing at scale. For each product, generate 3 to 5 variants with different actors and scripts. Upload all variants to your ad account. Let the ad platform's algorithm optimize for the best-performing creative.

Product image quality. The B-roll cutaway displays your product photo at full frame. Use clean, high-resolution product shots. White background images from your store work best.

Related Pages

Last updated: April 2026