
Customize Imagine video SDK poll timeout and interval
Customize Imagine video SDK poll timeout and interval
client.video.generate() and extend() submit the job, then poll until the clip is ready. Defaults are a 10-minute wait (timeout) and a 100 ms status check (interval). Long 1080p or 15-second jobs often need a longer timeout; slow networks sometimes want a calmer interval.
Python SDK
Pass datetime.timedelta values:
import os
from datetime import timedelta
import xai_sdk
client = xai_sdk.Client(api_key=os.getenv("XAI_API_KEY"))
response = client.video.generate(
prompt="Epic cinematic drone shot flying through mountain peaks",
model="grok-imagine-video-1.5",
duration=15,
resolution="1080p",
timeout=timedelta(minutes=15),
interval=timedelta(seconds=5),
)
print(response.url)
If the video is still pending when timeout elapses, the SDK raises TimeoutError. Catch it next to VideoGenerationError from xai_sdk.video when you want a clean retry path. See Handle Imagine video generation errors.
AI SDK (JavaScript)
Use providerOptions.xai.pollTimeoutMs and pollIntervalMs (milliseconds):
import { xai } from "@ai-sdk/xai";
import { experimental_generateVideo as generateVideo } from "ai";
const result = await generateVideo({
model: xai.video("grok-imagine-video-1.5"),
prompt: "Epic cinematic drone shot flying through mountain peaks",
duration: 15,
providerOptions: {
xai: {
resolution: "1080p",
pollTimeoutMs: 15 * 60 * 1000,
pollIntervalMs: 5 * 1000,
},
},
});
console.log(result.providerMetadata?.xai?.videoUrl);
The AI SDK aborts via its AbortSignal when the poll timeout fires.
When to leave the defaults
- Short 480p clips usually finish inside ten minutes.
- REST callers already own the loop:
POST /v1/videos/generationsthenGET /v1/videos/{request_id}every few seconds. The Python SDK also exposesclient.video.start()/client.video.get()when you want that lifecycle without the blockinggenerate()poll knobs.
Pitfalls
- Raising
intervaltoo high delays noticingdone; dropping it to sub-100 ms burns rate limit budget without speeding the model. - Temporary video URLs expire; download promptly if you need a lasting copy.
- Console API credits are a separate bill from SuperGrok's weekly pool on grok.com.