Maximum Polling Timeout for Video vs Image Generation in Open-Generative-AI

Video generation polls the MuAPI for up to 30 minutes (900 attempts with 2-second intervals), while image generation has a 2-minute maximum (60 attempts with 2-second intervals).

The Open-Generative-AI repository by Anil-matcha implements distinct maximum polling timeouts for asynchronous video and image generation tasks to match their differing computational requirements. These timeout limits are defined in the core MuAPI client at src/lib/muapi.js and respected throughout the React frontend components that handle pending job states. Understanding these thresholds helps developers implement proper error boundaries and loading states when integrating with this generative AI platform.

How Polling Timeouts Work in the MuAPI Client

The pollForResult method in src/lib/muapi.js defines the default polling behavior for all asynchronous generation tasks:

/**
 * @param {string} requestId - The request ID from the submit response
 * @param {string} key - The API key
 * @param {number} maxAttempts - Maximum polling attempts (default 60 = ~2 min)
 * @param {number} interval - Polling interval in ms (default 2000)
 */
async pollForResult(requestId, key, maxAttempts = 60, interval = 2000) { … }

This method polls the API endpoint repeatedly until the job completes or the maximum attempts are exhausted. According to the source code at lines 23–27, the default configuration supports a 2-minute maximum timeout (60 attempts × 2 seconds).

Video Generation: 30-Minute Maximum Timeout

Video generation tasks—including Text-to-Video, Image-to-Video, and Video-to-Video—require significantly more processing time. To accommodate this, the generateVideo and generateI2V methods explicitly override the default timeout in src/lib/muapi.js:

const result = await this.pollForResult(requestId, key, 900, 2000);

This call at lines 171–176 sets the maximum polling timeout to approximately 30 minutes (900 attempts × 2,000ms intervals).

The UI layer persists this extended timeout in src/components/VideoStudio.js when scheduling pending jobs:

savePendingJob({
  requestId: rid,
  studioType: 'video',
  historyMeta,
  maxAttempts: 900,
  interval: 2000,
  submittedAt: Date.now()
});

As shown at line 999, the video studio stores the 900-attempt limit to ensure job recovery works correctly across browser sessions.

Image Generation: 2-Minute Maximum Timeout

Image tasks rely on the default polling parameters defined in the pollForResult signature. In src/lib/muapi.js, the generateImage method calls:

const result = await this.pollForResult(requestId, key);

Without overriding the defaults, this uses 60 attempts at 2-second intervals, resulting in a 2-minute maximum timeout as shown at lines 98–99.

Similarly, src/components/ImageStudio.js stores these defaults for pending image jobs at line 1258:

savePendingJob({
  requestId: rid,
  studioType: 'image',
  historyMeta,
  maxAttempts: 60,
  interval: 2000,
  submittedAt: Date.now()
});

Practical Implementation Examples

When implementing custom polling logic or handling timeout errors, reference these patterns from the codebase:

Video Generation with Extended Timeout:

// From src/lib/muapi.js - generateVideo method
const result = await this.pollForResult(requestId, key, 900, 2000);
// Total timeout: 900 * 2000ms = 1,800,000ms (30 minutes)

Image Generation with Default Timeout:

// From src/lib/muapi.js - generateImage method
const result = await this.pollForResult(requestId, key);
// Total timeout: 60 * 2000ms = 120,000ms (2 minutes)

Checking Job Status in UI Components:

Both VideoStudio.js and ImageStudio.js use the savePendingJob helper defined in src/lib/pendingJobs.js to persist polling metadata. This ensures that if the user refreshes the browser, the application knows how many attempts remain for each pending request.

Summary

  • Video generation uses a 30-minute maximum polling timeout (900 attempts at 2-second intervals) defined explicitly in generateVideo and generateI2V.
  • Image generation uses a 2-minute maximum polling timeout (60 attempts at 2-second intervals) via the default pollForResult parameters.
  • Both timeouts use the same 2-second interval but differ in maximum attempt counts.
  • The limits are hardcoded in src/lib/muapi.js and mirrored in the UI components (VideoStudio.js and ImageStudio.js) for session persistence.

Frequently Asked Questions

What is the default polling interval for both generation types?

Both video and image generation use a 2-second polling interval (2000ms). This consistent interval is defined as the default parameter in pollForResult at src/lib/muapi.js line 25, ensuring uniform request spacing regardless of content type.

Why does video generation require a longer maximum polling timeout?

Video generation involves computationally intensive tasks like frame synthesis and temporal consistency processing, which typically take 5–15 minutes to complete depending on resolution and model parameters. The 30-minute timeout (900 attempts) accommodates these longer processing queues while preventing premature timeout errors that would occur with the standard 2-minute image timeout.

Can I modify the maximum polling timeout for custom implementations?

Yes, you can override the defaults by passing custom maxAttempts values to pollForResult. For example, calling this.pollForResult(requestId, key, 120, 2000) extends an image job to 4 minutes. However, note that the UI components in VideoStudio.js and ImageStudio.js hardcode their expectations (900 and 60 respectively), so custom implementations should maintain consistency between the API client and UI state management.

Where are pending jobs stored during the polling process?

Pending jobs are persisted using the savePendingJob helper defined in src/lib/pendingJobs.js. This utility stores the requestId, studioType, maxAttempts, and interval in browser storage, allowing the application to resume polling if the user refreshes the page or navigates between views in the React application.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →