> ## Documentation Index
> Fetch the complete documentation index at: https://heygen-1fa696a7.mintlify.app/llms.txt
> Use this file to discover all available pages before exploring further.

# Social Media Content Pipeline

> Automate social media video creation end-to-end. Use the HeyGen API to convert posts, articles, and product feeds into avatar videos sized for every platform.

## Examples

These were generated with Video Agent from a text prompt — no camera, no editing, no mic.

<Tabs>
  <Tab title="Freelancing story">
    <div style={{maxWidth: "350px", margin: "0 auto"}}>
      <iframe src="https://app.heygen.com/embeds/334591d581314a678d9ecd6efb523b4d" title="HeyGen video player" frameBorder="0" allow="encrypted-media; fullscreen;" allowFullScreen style={{width: "100%", height: "620px", borderRadius: "8px"}} />
    </div>
  </Tab>

  <Tab title="AI editing story">
    <div style={{maxWidth: "350px", margin: "0 auto"}}>
      <iframe src="https://app.heygen.com/embeds/e60f976e0cb3404c9d241bdc77cd20e0" title="HeyGen video player" frameBorder="0" allow="encrypted-media; fullscreen;" allowFullScreen style={{width: "100%", height: "620px", borderRadius: "8px"}} />
    </div>
  </Tab>
</Tabs>

## The Problem

Creating consistent social media video content requires a camera, microphone, editing skills, and hours of time per video. Most teams can't keep up with the pace platforms demand — daily or weekly posts across TikTok, Reels, and Shorts.

## How It Works

```
Choose topics → Write prompts → Batch generate videos → Post
```

You define the topics and tone. Video Agent handles avatar selection, scripting, visuals, and rendering. Generate a week's worth of content in one run.

## Build It

<Steps>
  <Step title="Choose your topics">
    You can source topics manually, from trending data, or from audience research. Here's an example batch of 5 topics for a SaaS marketing account:

    ```python theme={null}
    topics = [
        "Why your onboarding flow is losing users in the first 60 seconds",
        "The 3 metrics every SaaS founder checks before coffee",
        "Stop building features nobody asked for — do this instead",
        "Your pricing page is broken and here's the proof",
        "The hiring mistake that kills startups faster than bad code",
    ]
    ```

    <Tip>
      **Use an LLM for topic research.** Ask Claude or ChatGPT: "Give me 10 trending topics in \[your niche] that would perform well as 30-second TikToks." You can also use web search APIs to find what's trending right now.
    </Tip>
  </Step>

  <Step title="Write prompts optimized for short-form">
    Short-form video has a specific structure: **hook → content → CTA**, all in under 60 seconds. Your prompts should reflect this.

    ```python theme={null}
    def build_prompt(topic):
        return f"""Create a 30-second vertical video (portrait orientation) for TikTok/Reels.

    Topic: {topic}

    Structure:
    - Hook (0-5s): Open with a bold, scroll-stopping statement or question.
    - Content (5-25s): Deliver 2-3 punchy insights. Fast pacing, one idea
      every 5-7 seconds. Use text overlays for key points.
    - CTA (25-30s): End with a clear call-to-action.

    Tone: Casual and energetic, like talking to a friend who's also in the industry.
    Orientation: portrait.
    """

    prompts = [build_prompt(t) for t in topics]
    ```

    See [Prompt Engineering](/cookbook/patterns/prompt-engineering) for more techniques — especially the scene-by-scene structure for longer videos.
  </Step>

  <Step title="Batch generate with rate limit handling">
    Submit all videos to Video Agent. Space them out to respect [rate limits](/docs/pricing).

    ```python theme={null}
    import requests
    import time

    HEYGEN_API_KEY = "your-api-key"
    video_ids = []

    for i, prompt in enumerate(prompts):
        resp = requests.post(
            "https://api.heygen.com/v3/video-agents",
            headers={
                "X-Api-Key": HEYGEN_API_KEY,
                "Content-Type": "application/json",
            },
            json={
                "prompt": prompt,
                "orientation": "portrait",
            },
        )
        data = resp.json()["data"]
        video_ids.append(data["video_id"])
        print(f"[{i+1}/{len(prompts)}] Submitted: {data['video_id']}")

        # Wait between submissions to avoid rate limits
        if i < len(prompts) - 1:
            time.sleep(5)

    print(f"\nAll {len(video_ids)} videos submitted.")
    ```
  </Step>

  <Step title="Poll for completion">
    Wait for all videos to finish rendering.

    ```python theme={null}
    import time

    def poll_videos(video_ids):
        results = {}
        pending = set(video_ids)

        while pending:
            for vid in list(pending):
                resp = requests.get(
                    f"https://api.heygen.com/v3/videos/{vid}",
                    headers={"X-Api-Key": HEYGEN_API_KEY},
                )
                data = resp.json()["data"]

                if data["status"] == "completed":
                    results[vid] = data["video_url"]
                    pending.discard(vid)
                    print(f"Completed: {vid}")
                elif data["status"] == "failed":
                    results[vid] = None
                    pending.discard(vid)
                    print(f"Failed: {vid} — {data.get('failure_message')}")

            if pending:
                print(f"Waiting... {len(pending)} still rendering")
                time.sleep(15)

        return results

    results = poll_videos(video_ids)
    ```

    <Tip>
      For production pipelines, use [webhooks](/docs/webhooks) instead of polling. Pass a `callback_url` in each creation request and handle notifications as they arrive.
    </Tip>
  </Step>

  <Step title="Download and distribute">
    Download all completed videos, then post to your platforms.

    ```python theme={null}
    import os

    os.makedirs("output", exist_ok=True)

    for i, (vid, url) in enumerate(results.items()):
        if url:
            video_data = requests.get(url).content
            filename = f"output/video_{i+1}.mp4"
            with open(filename, "wb") as f:
                f.write(video_data)
            print(f"Saved: {filename}")
    ```
  </Step>
</Steps>

## Platform Optimization

Different platforms have different sweet spots:

| Platform        | Ideal Duration | Orientation      | Tips                                      |
| --------------- | -------------- | ---------------- | ----------------------------------------- |
| TikTok          | 15–60s         | Portrait (9:16)  | Strong hook in first 2s, fast pacing      |
| Instagram Reels | 15–60s         | Portrait (9:16)  | Clean visuals, text overlays              |
| YouTube Shorts  | 15–60s         | Portrait (9:16)  | Slightly more polished, educational angle |
| LinkedIn        | 30–90s         | Landscape (16:9) | Professional tone, industry insights      |

Pass `"orientation": "portrait"` or `"orientation": "landscape"` in your API call. See [Video Agent docs](/docs/video-agent) for all parameters.

## Variations

* **Themed series:** Generate 5 videos on the same topic from different angles (beginner, advanced, myth-busting, case study, hot take)
* **Multi-language:** Generate in English, then use [Video Translation](/docs/video-translate) to create versions in other languages
* **A/B testing:** Generate 2 versions of the same topic with different hooks, measure which performs better

***

## Next Steps

<CardGroup cols={2}>
  <Card title="Prompt Engineering" icon="wand-magic-sparkles" href="/cookbook/patterns/prompt-engineering">
    Write prompts that produce scroll-stopping content.
  </Card>

  <Card title="Content Repurposing" icon="recycle" href="/cookbook/video-agent/content-repurposing">
    Already have blog content? Turn it into video.
  </Card>
</CardGroup>
