Skip to main content
Lesson 9 of 12 · Create Videos with Grok

Combine editing and extension

Lesson 9 of 12 Updated November 3, 2026 Intermediate
On this page
  1. Advanced production pipelines
  2. Pipeline 1: A 15-second product promo
  3. Pipeline 2: Five contents, one style
  4. Pipeline 3: Deriving variants from a video
  5. Making a chain failure-resistant
  6. Key takeaways

Updated November 2, 2026. Based on the xAI video API reference: the source image goes in an image object, and the video to edit or extend goes in a video object ({"url": ...}), for both extension and editing. Sources: Video Extension · Videos Reference.

Advanced production pipelines

Used in isolation, each endpoint has limits: generation caps at 15 seconds, editing at 8.7 seconds of source, and extension at 10 seconds added. Combined, they form production pipelines that far exceed these bounds and, crucially, give you a control point after each segment. This lesson covers three real-world pipelines, from product clips to stylistic variations, and how to make them reliable.

Pipeline 1: A 15-second product promo

The scenario is classic: you have a smartphone photo and need to deliver a 15-second promo video. The pipeline builds in three 5-second segments, each validated before the next.

The first segment animates the product photo—rotation, play of reflections—via the image-to-video studied in the previous section.

{
  "model": "grok-imagine-video",
  "prompt": "Elegant rotation of the smartphone on a dark background, light reflections on the screen",
  "image": {"url": "https://exemple.com/smartphone.jpg"},
  "duration": 5,
  "aspect_ratio": "16:9",
  "resolution": "720p"
}

The second extends this shot with an extension that brings the camera closer to the screen, reinjecting the URL obtained in the previous step.

{
  "model": "grok-imagine-video",
  "prompt": "Progressive zoom towards the smartphone screen turning on, displaying a colorful interface",
  "video": {"url": "{url_video_etape_1}"},
  "duration": 5
}

The third closes the sequence on a wide shot, starting this time from the output of the second segment.

{
  "model": "grok-imagine-video",
  "prompt": "Zoom out revealing the smartphone placed on a design desk, soft light, slight background blur",
  "video": {"url": "{url_video_etape_2}"},
  "duration": 5
}

Fifteen seconds of new content, at $0.05 per second with grok-imagine-video: expect around $0.75 excluding iterations if each segment is billed at its duration. The actual cost of each step appears in the usage.cost_in_usd_ticks field of its result: verify this on a test pipeline before budgeting a series.

Pipeline 2: Five contents, one style

Different situation, different logic: you need to produce five 5-second videos for a social campaign with a consistent visual style. Here, chaining doesn’t structure the work; reference images do, identical for all generations. The five prompts describe different scenes; the style stays consistent thanks to the same two visuals.

references = [
    {"url": "https://exemple.com/style-campagne-1.jpg"},
    {"url": "https://exemple.com/style-campagne-2.jpg"}
]

prompts = [
    "Coffee pouring into a white ceramic cup, rising steam",
    "Hands typing on a keyboard, blurred screen in background",
    "An open notebook with a pen writing, natural light",
    "A green plant growing in timelapse in a clay pot",
    "A book whose pages turn in the wind on a terrace"
]

for prompt in prompts:
    resp = httpx.post(
        "https://api.x.ai/v1/videos/generations",
        headers=headers,
        json={
            "model": "grok-imagine-video",
            "prompt": prompt,
            "reference_images": references,
            "duration": 5,
            "aspect_ratio": "9:16",
            "resolution": "720p"
        }
    )

Five 5-second clips come to $1.25. Note the 9:16 format applied to all requests: for a vertical campaign, this is the kind of oversight that costs a complete regeneration.

Pipeline 3: Deriving variants from a video

The third scheme chains nothing at all: it applies several different edits in parallel to the same source video. You thus obtain four versions of the same clip, to propose for A/B testing or to distribute across platforms with distinct identities.

video_source = "https://exemple.com/video-base.mp4"

variations = [
    "Cinematic black and white style, film grain",
    "Pop art saturated colors, strong contrasts",
    "Night ambiance, purple and blue neon lights",
    "Watercolor style, soft outlines and washed colors"
]

for variation in variations:
    resp = httpx.post(
        "https://api.x.ai/v1/videos/edits",
        headers=headers,
        json={
            "model": "grok-imagine-video",
            "prompt": variation,
            "video": {"url": video_source}
        }
    )

These three pipelines use four endpoints, summarized below.

EndpointMethodInputOutputMax duration
/v1/videos/generationsPOSTPrompt + optionsNew video1-15s
/v1/videos/editsPOSTVideo + promptModified videoSource up to 8.7s
/v1/videos/extensionsPOSTVideo + promptExtended video+2 to 10s, source up to 15s
/v1/videos/{id}GETrequest_idStatus + URL-

Making a chain failure-resistant

As soon as you chain operations, the probability that at least one fails becomes significant, and a failure at the third link loses the first two if nothing is planned. The following function encapsulates each step in a retry loop and only advances to the next step once the URL is obtained.

async def pipeline_with_retry(steps, max_retries=2):
    video_url = None
    for i, step in enumerate(steps):
        for attempt in range(max_retries + 1):
            try:
                if step["type"] == "generation":
                    result = await generate_video(step["params"])
                elif step["type"] == "extension":
                    step["params"]["video"] = {"url": video_url}
                    result = await extend_video(step["params"])
                elif step["type"] == "edition":
                    step["params"]["video"] = {"url": video_url}
                    result = await edit_video(step["params"])

                video_url = await wait_for_result(result["request_id"])
                break
            except Exception as e:
                if attempt == max_retries:
                    raise Exception(f"Step {i+1} failed: {e}")
                await asyncio.sleep(10)
    return video_url

Around this skeleton, five habits make the difference between a prototype and a service. Download the result at each step, since URLs are temporary and recovery from an incident requires having intermediate versions. Visually validate each segment before proceeding to the next, otherwise you pay for three generations only to discover the first wasn’t suitable. Handle errors with attempts spaced by exponential backoff. Calculate the full budget before launching a long chain, counting probable iterations. And parallelize what you can: in pipeline 2 and pipeline 3, no generation depends on another, so they can run simultaneously.

Pricing verified November 3, 2026 — prices change regularly: before any budget calculation, check the current rates on the official xAI models and pricing page.

Key takeaways

  • The three endpoints (generation, editing, extension) combine into pipelines
  • Reference images ensure stylistic consistency across multiple videos
  • Iterative editing allows deriving a video into several versions
  • Download intermediate results and handle errors at each step
  • Calculate the total budget before launching complex pipelines