
Run concurrent Imagine video edits from one source
Run concurrent Imagine video edits from one source
Video edits keep the source duration and aspect ratio (output capped at 720p). When you want several variants from the same clip (necklace, red outfit, hat), fire concurrent AsyncClient jobs against that source instead of waiting for each edit in series.
Python AsyncClient
import os
import asyncio
import xai_sdk
async def edit_concurrently():
client = xai_sdk.AsyncClient(api_key=os.getenv("XAI_API_KEY"))
source_video = "https://data.x.ai/docs/video-generation/portrait-wave.mp4"
prompts = [
"Give the woman a silver necklace",
"Change the color of the woman's outfit to red",
"Give the woman a wide-brimmed black hat",
]
tasks = [
client.video.generate(
prompt=prompt,
model="grok-imagine-video",
video_url=source_video,
)
for prompt in prompts
]
results = await asyncio.gather(*tasks)
for prompt, result in zip(prompts, results):
print(f"{prompt}: {result.url}")
asyncio.run(edit_concurrently())
Source video can be a public URL, a data URI, or a Files API file_id. REST uses POST /v1/videos/edits per variant, then the usual GET /v1/videos/{request_id} poll. See Edit a video with the Imagine API.
Branch after a shared first edit
Finish one edit, then fan out concurrent follow-ups from that intermediate video.url when every branch should share the same base change (party hat first, then sunglasses vs scarf). In the AI SDK set providerOptions.xai.mode to "edit-video" and pass videoUrl.
Pitfalls
- Concurrent edits keep length; concurrent generations create new clips (Concurrent Imagine video generations).
duration,aspect_ratio, andresolutionon an edit call are ignored.- Output URLs expire; download or persist if you need lasting copies.
- Console API credits are a separate bill from SuperGrok's weekly pool on grok.com.