Skip to content
Docs

AI Gateway Video Editing

Edit existing videos using text prompts. Describe the changes you want and the model modifies the video accordingly. To upscale or restore a video without changing its content, see Topaz.

Every model here also runs as a background job instead of one long-lived request. See asynchronous generation below.

Grok Imagine Video (by SpaceXAI) can edit existing videos using text prompts. Provide a source video URL and describe the desired edits. Only spacexai/grok-imagine-video supports video editing. The 1.5 models do not.

Browse the latest Grok video models on the AI Gateway Models page.

Video editing output matches the input video's aspect ratio and resolution, capped at 720p. A 1080p input will be downsized to 720p. The duration, aspectRatio, and resolution parameters are not supported for editing.

ParameterTypeRequiredDescription
promptstringYesDescription of the edits to apply to the video
providerOptions.xai.videoUrlstringYesURL of the source video to edit
providerOptions.xai.pollIntervalMsnumberNoHow often to check task status. Defaults to 5000
providerOptions.xai.pollTimeoutMsnumberNoMaximum wait time. Defaults to 600000 (10 minutes)
video-editing.ts
import { experimental_generateVideo as generateVideo } from 'ai';
import fs from 'node:fs';
 
const result = await generateVideo({
  model: 'spacexai/grok-imagine-video',
  prompt: 'Give the person sunglasses and a hat',
  providerOptions: {
    xai: {
      videoUrl: 'https://example.com/source-video.mp4',
      pollTimeoutMs: 600000,
    },
  },
});
 
fs.writeFileSync('output.mp4', result.videos[0].uint8Array);

Video generation can take several minutes. Set pollTimeoutMs to at least 10 minutes (600000ms) for reliable operation. Generated video URLs are ephemeral and should be downloaded promptly.


Seedance 2.5 (bytedance/seedance-2.5) and its lower-cost variant, Seedance 2.5 Flash (bytedance/seedance-2.5-flash), can edit an existing video. Pass the source video as a video reference in inputReferences and describe the edit in your prompt, referring to the video as [Video 1]. To bring a new subject into the video, add image references and refer to them as [Image 1], [Image 2], and so on.

The source video must be an MP4 or MOV file at a URL, between 2 and 30 seconds long and no larger than 200 MB.

Browse the latest Seedance video models on the AI Gateway Models page.

ParameterTypeRequiredDescription
promptstringYesDescription of the edits. Use [Video 1], [Image 1], etc. to refer to each reference
inputReferencesArray<{ data: string; mediaType: string }>YesThe source video, plus any reference images. Tag each URL with an explicit mediaType
durationnumberNoVideo length in seconds, from 4 to 30
generateAudiobooleanNoGenerate audio alongside the video
providerOptions.bytedance.pollIntervalMsnumberNoHow often to check task status. Defaults to 3000
providerOptions.bytedance.pollTimeoutMsnumberNoMaximum wait time. Defaults to 300000 (5 minutes)
seedance-video-editing.ts
import { experimental_generateVideo as generateVideo } from 'ai';
import fs from 'node:fs';
 
const result = await generateVideo({
  model: 'bytedance/seedance-2.5',
  prompt:
    'Replace the cat in [Video 1] with the lion from [Image 1]. The lion lies down and gently interacts with the girl in a warm and tender way.',
  duration: 12,
  inputReferences: [
    { data: 'https://example.com/lion.jpg', mediaType: 'image/jpeg' },
    { data: 'https://example.com/cat-video.mp4', mediaType: 'video/mp4' },
  ],
  generateAudio: true,
  providerOptions: {
    bytedance: {
      pollTimeoutMs: 600000,
    },
  },
});
 
fs.writeFileSync('output.mp4', result.videos[0].uint8Array);

Topaz Labs models enhance a video you already have. They upscale and restore the video, and they do not take a text prompt. Two models are available:

  • topaz/proteus: Upscaling, denoising, and restoration that preserves the source's detail, with automatic adjustments or manual control over detail recovery, compression artifacts, noise, blur, and grain.
  • topaz/starlight-precise-2.6: Generative upscaling and restoration that improves faces, textures, and fine details while keeping frames consistent over time.

Pass the input video through inputReferences with a video mediaType, and set the output size with resolution. Topaz models enhance the whole input video, so they ignore prompt, duration, aspectRatio, generateAudio, and frameImages with a warning. Pass an empty prompt. The output keeps the input's audio track unless you change providerOptions.topaz.output.audioTransfer.

Browse the latest Topaz video models on the AI Gateway Models page. For each model's tuning options, see the Proteus and Starlight Precise 2.6 model pages.

ParameterTypeRequiredDescription
inputReferencesArray<{ data, mediaType }>YesThe video to enhance. Topaz uses the first video reference
resolutionstringYesOutput size as {width}x{height} (for example, '3840x2160'). You can omit it when providerOptions.topaz.source or providerOptions.topaz.output sets the dimensions
providerOptions.topaz.sourceobjectNoMetadata about the input video: width, height, duration (seconds), and frameRate. Setting any of them requires all four. Required for topaz/starlight-precise-2.6
providerOptions.topaz.outputobjectNoOutput settings such as width, height, frameRate, videoEncoder, container, and audioTransfer ('Copy', 'Convert', or 'None', defaults to 'Copy')
topaz-video-enhancement.ts
import { experimental_generateVideo as generateVideo } from 'ai';
import fs from 'node:fs';
 
const result = await generateVideo({
  model: 'topaz/proteus',
  prompt: '',
  inputReferences: [
    { data: 'https://example.com/source-video.mp4', mediaType: 'video/mp4' },
  ],
  resolution: '3840x2160',
});
 
fs.writeFileSync('output.mp4', result.videos[0].uint8Array);

topaz/starlight-precise-2.6 also needs the input video's metadata:

topaz-starlight.ts
import { experimental_generateVideo as generateVideo } from 'ai';
import fs from 'node:fs';
 
const result = await generateVideo({
  model: 'topaz/starlight-precise-2.6',
  prompt: '',
  inputReferences: [
    { data: 'https://example.com/source-video.mp4', mediaType: 'video/mp4' },
  ],
  resolution: '1920x1080',
  providerOptions: {
    topaz: {
      source: { width: 1280, height: 720, duration: 10, frameRate: 24 },
    },
  },
});
 
fs.writeFileSync('output.mp4', result.videos[0].uint8Array);

Pass a webhook factory and the SDK registers your URL with the job instead of polling for it. The factory returns that URL and a received promise it waits on, then it fetches the videos itself.

async-video-editing.ts
const result = await generateVideo({
  model: 'spacexai/grok-imagine-video',
  prompt: 'Give the person sunglasses and a hat',
  providerOptions: {
    xai: {
      // Already a hosted URL, which is what the asynchronous flow needs.
      videoUrl: 'https://example.com/source-video.mp4',
    },
  },
  webhook: async () => ({
    url: callbackUrl,
    received: waitForDelivery(token),
  }),
  poll: { timeoutMs: 10 * 60 * 1000 },
});

The start request AI Gateway persists is capped at 300 KiB, so pass your source video as a hosted URL on this flow rather than inline data.

token, callbackUrl, and waitForDelivery come from webhook-driven completion, which also covers the receiver, signature verification, and the payload shape.


Last updated September 8, 2026

Was this helpful?

supported.