SPB Git

Repository Public

editing.md 4.0 KB 109 lines markdown

1<!-- source: https://docs.x.ai/developers/model-capabilities/video/editing (from https://docs.x.ai/llms-full.txt, retrieved 2026-09-19T05:28:55Z) -->2#### Model Capabilities34# Video Editing56Edit an existing video by providing a source video along with your prompt. The model understands the video content and applies your requested changes.78You can provide the source video as a public URL, a base64-encoded data URI, or a `file_id` from the [Files API](/developers/files). See [Imagine → Files API Integration](/developers/model-capabilities/imagine/files/inputs) for using `file_id` inputs.910> [!WARNING]1112The demo below shows video editing in action. `grok-imagine-video` delivers high-fidelity edits with strong scene preservation, modifying only what you ask for while keeping the rest of the video intact:1314In the Vercel AI SDK, video editing is triggered by setting `providerOptions.xai.mode` to `"edit-video"` and passing `providerOptions.xai.videoUrl` with a source video URL. The `prompt` describes the desired modifications; `duration`, `aspectRatio`, and `resolution` are ignored because the output inherits these properties from the input video, capped at 720p.1516## Concurrent Requests1718When you need to apply several edits to the same source video, run requests concurrently. This is useful for branching multiple edits from the same intermediate result.1920```python customLanguage="pythonXAI"21import os22import asyncio23import xai_sdk2425async def edit_concurrently():26    client = xai_sdk.AsyncClient(api_key=os.getenv("XAI_API_KEY"))2728    source_video = "https://data.x.ai/docs/video-generation/portrait-wave.mp4"2930    prompts = [31        "Give the woman a silver necklace",32        "Change the color of the woman's outfit to red",33        "Give the woman a wide-brimmed black hat",34    ]3536    tasks = [37        client.video.generate(38            prompt=prompt,39            model="grok-imagine-video",40            video_url=source_video,41        )42        for prompt in prompts43    ]4445    results = await asyncio.gather(*tasks)4647    for prompt, result in zip(prompts, results):48        print(f"{prompt}: {result.url}")4950asyncio.run(edit_concurrently())51```5253```javascript customLanguage="javascriptAISDK"54import { xai, type XaiVideoModelOptions } from "@ai-sdk/xai";55import { experimental_generateVideo as generateVideo } from "ai";5657const providerOptions = {58    xai: {59        mode: "edit-video",60        videoUrl: "https://example.com/source-video.mp4",61        pollTimeoutMs: 600000,62    } satisfies XaiVideoModelOptions,63};6465const step1 = await generateVideo({66    model: xai.video("grok-imagine-video"),67    prompt: "Add a party hat to the person",68    providerOptions,69});7071const step1VideoUrl = step1.providerMetadata?.xai?.videoUrl as string;7273const [withSunglasses, withScarf] = await Promise.all([74    generateVideo({75        model: xai.video("grok-imagine-video"),76        prompt: "Add sunglasses",77        providerOptions: {78            xai: {79                mode: "edit-video",80                videoUrl: step1VideoUrl,81                pollTimeoutMs: 600000,82            } satisfies XaiVideoModelOptions,83        },84    }),85    generateVideo({86        model: xai.video("grok-imagine-video"),87        prompt: "Add a scarf",88        providerOptions: {89            xai: {90                mode: "edit-video",91                videoUrl: step1VideoUrl,92                pollTimeoutMs: 600000,93            } satisfies XaiVideoModelOptions,94        },95    }),96]);9798console.log(withSunglasses.providerMetadata?.xai?.videoUrl);99console.log(withScarf.providerMetadata?.xai?.videoUrl);100```101102## Related103104* [Video Generation](/developers/model-capabilities/video/generation) — Generate videos from text prompts105* [Image-to-Video](/developers/model-capabilities/video/image-to-video) — Animate a still image106* [Video Extension](/developers/model-capabilities/video/extension) — Extend existing videos107* [API Reference](/developers/rest-api-reference) — Full endpoint documentation108* [Imagine API Landing Page](https://x.ai/api/imagine) — Showcase of the Imagine API in action109
Files main
Menu

Theme