AI Gateway Video Editing
Edit existing videos using text prompts. Describe the changes you want and the model modifies the video accordingly.
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.
Browse the latest Grok video models on the AI Gateway Models page.
| Parameter | Type | Required | Description |
|---|---|---|---|
prompt | string | Yes | Description of the edits to apply to the video |
providerOptions.spacexai.videoUrl | string | Yes | URL of the source video to edit |
providerOptions.spacexai.pollIntervalMs | number | No | How often to check task status. Defaults to 5000 |
providerOptions.spacexai.pollTimeoutMs | number | No | Maximum wait time. Defaults to 600000 (10 minutes) |
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: {
spacexai: {
videoUrl: 'https://example.com/source-video.mp4',
pollTimeoutMs: 600000,
},
},
});
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.
const result = await generateVideo({
model: gateway.videoModel('spacexai/grok-imagine-video'),
prompt: 'Give the person sunglasses and a hat',
providerOptions: {
spacexai: {
// 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.
Was this helpful?