sgl-project/sglang · error · RuntimeError

Failed to generate video: {str(e)}

Error message

Failed to generate video: {str(e)}

What it means

RuntimeError wrapper raised by generate_video for requests exceptions that escape the polling loop's specific handlers — typically the initial job-submission POST failing, or a RequestException not caught by the ConnectionError/timeout branches.

Source

Thrown at python/sglang/multimodal_gen/apps/ComfyUI_SGLDiffusion/core/server_api.py:358

                        raise RuntimeError(
                            f"Lost connection to server after {consecutive_errors} consecutive errors. "
                            f"Server may be unavailable: {str(e)}"
                        )
                except requests.exceptions.RequestException as e:
                    # Other network errors - continue polling but track errors
                    consecutive_errors += 1
                    if consecutive_errors >= max_consecutive_errors:
                        raise RuntimeError(
                            f"Network error after {consecutive_errors} consecutive failures: {str(e)}"
                        )

                time.sleep(poll_interval)

            raise TimeoutError(
                f"Video generation timed out after {max_wait_time} seconds"
            )
        except requests.exceptions.RequestException as e:
            raise RuntimeError(f"Failed to generate video: {str(e)}")

    def _build_image_common_params(
        self,
        prompt: str,
        size: str,
        n: int,
        response_format: str,
        negative_prompt: Optional[str] = None,
        guidance_scale: Optional[float] = None,
        num_inference_steps: Optional[int] = None,
        seed: Optional[int] = None,
        enable_teacache: bool = False,
        background: Optional[str] = None,
        output_format: Optional[str] = None,
        generator_device: Optional[str] = None,
    ) -> Dict[str, Any]:
        """
        Build common parameters for both image generation and editing.

View on GitHub (pinned to 0132848349)

Solutions

  1. Verify the server is reachable and the video endpoint exists (curl base_url).
  2. Check the embedded message for status codes: fix api_key/paths accordingly.
  3. Retry after the server is fully loaded; video endpoints may register late.
  4. Inspect server logs during submit.
Defensive patterns

Strategy: try-catch

Validate before calling

import requests
requests.post(f"{base_url}/video/generate", json={'prompt':'ping'}, headers=headers, timeout=10)

Try / catch

try:
    job = api.generate_video(prompt=p)
except RuntimeError as e:
    if 'ConnectionError' in str(e) or 'refused' in str(e):
        wait_for_server(); job = api.generate_video(prompt=p)
    else: raise

Prevention

When it happens

Trigger: The initial generate request to the server fails (server down, 4xx/5xx on submit, connection refused) before polling ever starts.

Common situations: Server not started; wrong base_url; auth failure on the video endpoint; submit request timing out.

Understand the failure class

Background: 'Something went wrong' / 'Request failed (500)' / 'HTTP error! status: 404' — what failed HTTP requests actually mean and how to find the real cause — this error's family across 28 libraries.

Related errors


AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28). Data as JSON: /api/errors/a76b0cb88fcfe0c6. Report an issue: GitHub.