Build an Automated YouTube Shorts Pipeline with AI Video Generation
Short-form video is the fastest-growing content format in 2026. YouTube Shorts, TikTok, and Instagram Reels together reach over 3 billion daily active users. The bottleneck is not distribution — it is production. This guide shows you how to build a scripted pipeline that generates batches of AI videos from a prompt library, tracks job progress, and organizes outputs for upload. All from the terminal.
The architecture
The pipeline has three layers. First, a JSON prompt library stores your video ideas with metadata about which model and aspect ratio to use. Second, a bash script reads the library and submits each prompt to agent-media CLI as an async job. Third, a monitoring step checks job status and downloads completed outputs into organized folders. Each layer is a simple, standalone script that you can modify, extend, or plug into a larger CI/CD workflow.
Prompt Library (prompts.json) → Batch Script (generate.sh) → Job Monitor (agent-media jobs) → Download (organized outputs/)
Step 1: Set up your prompt library
A prompt library is a JSON file that contains your video ideas. Each entry specifies a prompt, the target model, duration, and aspect ratio. Keeping prompts in a structured file makes it easy to iterate, add new ideas, and track what you have already generated.
[
{
"id": "cooking-01",
"model": "seedance1",
"prompt": "Chef plating a colorful dish, close-up hands, steam rising, restaurant kitchen",
"duration": 5,
"aspect_ratio": "9:16"
},
{
"id": "nature-01",
"model": "kling3",
"prompt": "Bioluminescent jellyfish floating in deep ocean, ethereal blue glow, 4K cinematic",
"duration": 5,
"aspect_ratio": "9:16"
},
{
"id": "urban-01",
"model": "sora2",
"prompt": "Time-lapse of city traffic at dusk, streaking headlights, skyscrapers in background",
"duration": 8,
"aspect_ratio": "9:16"
},
{
"id": "fitness-01",
"model": "seedance1",
"prompt": "Athlete doing dynamic stretches in gym, energetic movement, motivational feel",
"duration": 5,
"aspect_ratio": "9:16"
}
]Notice that all entries use 9:16 aspect ratio — the native format for YouTube Shorts, TikTok, and Reels. The id field helps you track which prompt produced which output file.
Step 2: Write the batch generation script
This bash script reads your prompt library and submits each entry as an async job. It uses jq to parse the JSON and logs each job ID for later tracking. The key is not using --sync — by submitting all jobs asynchronously, they run in parallel on the server instead of sequentially.
#!/bin/bash
PROMPTS_FILE="prompts.json"
LOG_FILE="jobs-$(date +%Y%m%d).log"
echo "Starting batch generation at $(date)"
echo "---" >> "$LOG_FILE"
COUNT=$(jq length "$PROMPTS_FILE")
for i in $(seq 0 $((COUNT - 1))); do
ID=$(jq -r ".[$i].id" "$PROMPTS_FILE")
MODEL=$(jq -r ".[$i].model" "$PROMPTS_FILE")
PROMPT=$(jq -r ".[$i].prompt" "$PROMPTS_FILE")
DURATION=$(jq -r ".[$i].duration" "$PROMPTS_FILE")
RATIO=$(jq -r ".[$i].aspect_ratio" "$PROMPTS_FILE")
echo "Submitting [$ID] to $MODEL..."
RESULT=$(agent-media generate "$MODEL" \
-p "$PROMPT" \
--duration "$DURATION" \
--aspect-ratio "$RATIO")
echo "$ID|$MODEL|$RESULT" >> "$LOG_FILE"
echo " -> $RESULT"
sleep 2 # Brief pause between submissions
done
echo "All $COUNT jobs submitted. See $LOG_FILE"Run the script with bash generate.sh and it will submit all four prompts in under 30 seconds. The log file maps each prompt ID to its job ID for easy tracking.
Step 3: Model selection strategy
Different content types work best with different models. Here is a decision framework for YouTube Shorts:
Talking head / vlog style
seedance1
Best prompt following for human subjects at the lowest credit cost (104 credits). Flexible duration from 1.2 to 12 seconds.
Cinematic / product shots
kling3
Native 4K output with 60fps. The resolution stands out in a feed full of compressed phone video. Worth the 187 credits for hero content.
Fast iteration / testing
sora2
Under 45 seconds per generation. When you are dialing in a prompt, the fast turnaround saves both time and credits from wasted attempts.
Lip sync / dialogue
veo3
The only model with native audio generation. When your Short needs a speaking subject, Veo 3.1 eliminates the need for separate voice synthesis.
Step 4: Monitor job status
After submitting a batch, use the jobs command to track progress. The agent-media jobs list command shows all your recent jobs with their current status.
$ agent-media jobs list
job_a1b2c3 seedance1 completed cooking-01
job_d4e5f6 kling3 processing nature-01
job_g7h8i9 sora2 completed urban-01
job_j0k1l2 seedance1 completed fitness-01
For automated pipelines, you can poll job status in a script. Check individual jobs with agent-media jobs status <job_id> and parse the output to trigger downloads when jobs complete.
Step 5: Download and organize outputs
Once jobs complete, you receive a direct URL to the output file. A download script reads your job log, checks completion status, and saves outputs into an organized folder structure.
#!/bin/bash
OUTPUT_DIR="outputs/$(date +%Y%m%d)"
mkdir -p "$OUTPUT_DIR"
while IFS='|' read -r ID MODEL JOB_ID; do
STATUS=$(agent-media jobs status "$JOB_ID" --json \
| jq -r '.status')
if [ "$STATUS" = "completed" ]; then
URL=$(agent-media jobs status "$JOB_ID" --json \
| jq -r '.output_url')
curl -sL "$URL" -o "$OUTPUT_DIR/$ID-$MODEL.mp4"
echo "Downloaded: $ID-$MODEL.mp4"
else
echo "Skipping $ID ($STATUS)"
fi
done < "jobs-$(date +%Y%m%d).log"
echo "Downloads complete -> $OUTPUT_DIR/"Cost analysis: How many Shorts per plan
The cost of your pipeline depends on which models you use. Here is how many 5-second Shorts each plan tier supports at different model mixes:
| Plan | Credits | Seedance Only | Kling Only | Mixed* |
|---|---|---|---|---|
| Starter ($39/mo) | 2,000 | 19 | 10 | 14 |
| Creator ($69/mo) | 5,000 | 48 | 26 | 35 |
| Pro Plus ($119/mo) | 12,000 | 115 | 64 | 85 |
*Mixed assumes 50% Seedance, 30% Sora, 20% Kling
Pro tips
Aspect ratio matters
Always use 9:16 for Shorts and Reels. Both Seedance and Kling support this natively. Generating in landscape and then cropping wastes credits and introduces framing issues.
Duration sweet spot: 5-8 seconds
YouTube Shorts performs best with content between 5 and 15 seconds. A single 5-second AI clip is a complete Short. For longer content, generate multiple 5-second clips and stitch them in your editor. This is more cost-effective than a single long generation and gives you more control over pacing.
Prototype cheaply with Seedance, then upgrade
Use Seedance at 104 credits per generation to test and refine your prompts. Once you have a prompt that produces great results, run the final version through Kling for 4K quality. This approach saves credits during the creative iteration phase.
Scaling up: GitHub Actions integration
For fully automated pipelines, trigger batch generation from GitHub Actions. Push new prompts to your repository and let CI handle the generation. Here is a minimal workflow that runs your batch script on every push to the prompts file:
name: Generate Shorts
on:
push:
paths: ['prompts.json']
jobs:
generate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with: { node-version: '20' }
- run: npm install -g agent-media-cli
- run: agent-media login --device-key ${{ secrets.AM_DEVICE_KEY }}
- run: bash generate.shStore your device key as a GitHub Actions secret. Every time you add prompts to prompts.json and push, the workflow installs the CLI, authenticates, and runs your batch. The generated videos appear in your agent-media dashboard gallery, ready for download.
Start building your pipeline
One CLI, 7 models, unlimited automation. Plans start at $19/mo.