SGLang Video Generation
Overview
This guide shows how to benchmark text-to-video generation APIs using SGLang and AIPerf. You’ll learn how to set up the SGLang video generation server, create input prompts, run benchmarks, and analyze the results.
Video generation follows an asynchronous job pattern:
- Submit - POST to
/v1/videoswith your prompt, receive a job ID - Poll - GET
/v1/videos/{id}until status iscompletedorfailed - Download - GET
/v1/videos/{id}/contentto retrieve the generated video
AIPerf handles this polling workflow automatically.
References
For the most up-to-date information, please refer to the following resources:
- SGLang Diffusion OpenAI API Reference
- SGLang Diffusion Installation Guide
- SGLang Diffusion CLI Reference
- OpenAI Videos API
Supported Models
AIPerf supports any SGLang-compatible text-to-video model, including:
Setting Up the Server
Option 1: Docker (Recommended)
Export your Hugging Face token as an environment variable:
Start the SGLang Docker container:
Install the diffusion dependencies:
Set the server arguments:
The following arguments set up the SGLang server to use Wan2.1-T2V-1.3B on port 30010.
Adjust --num-gpus, --ulysses-degree, and --ring-degree based on your GPU configuration.
Single GPU setup:
Multi-GPU setup (4 GPUs with sequence parallelism):
Start the SGLang server:
Wait until the server is ready (watch the logs for the following message):
Option 2: Native Installation
Install SGLang with diffusion support:
Start the server:
Running the Benchmark
The following steps are to be performed on your local machine (outside the SGLang Docker container).
Basic Usage: Text-to-Video with Input File
Create an input file with video prompts:
Run the benchmark:
Done! This sends 3 requests to http://localhost:30010/v1/videos and polls until each video is complete.
Sample Output (Successful Run):
Basic Usage: Text-to-Video with Synthetic Prompts
Generate videos using synthetic prompts with configurable token lengths:
Generation Parameters
Control video generation through --extra-inputs:
Video Download Option:
Use --download-video-content to include video content download in the benchmark timing. When enabled, request latency includes the time to download the generated video from the server. By default, only generation time is measured.
The download comes from the url field of the completed job, or from
<poll URL>/content when the job has none. Downloads follow HTTP 301, 302, 303,
307 and 308 redirects using GET. Credentials are checked at every hop against
the original benchmark endpoint, with or without request signing:
- A download from a different host gets no credentials. When
urlnames a different scheme, host or port than--url, onlyUser-Agentis sent: no--api-keyand no-Hheaders. A presigned S3 URL needs nothing more, since it authenticates through its own query string. - Returning to the original origin restores endpoint headers. Requests to that origin receive the original headers and fresh signing when configured.
- Configured URL authentication stays on the original origin. Credentials
in
--urlprovide Basic authentication for same-origin downloads, including hops that return to that origin. They are never sent to foreign origins. Credentials embedded in a job’surlfield or a redirectLocationare rejected. - Foreign origins do not use environment credentials or proxies. Downloads
to a different origin disable
.netrcauthentication and environment proxy settings, includingHTTP_PROXYandHTTPS_PROXY.
The default limit is five redirects. Set AIPERF_HTTP_VIDEO_DOWNLOAD_MAX_REDIRECTS
to an integer from 0 to 100 to change it; 0 refuses redirects while allowing a
direct download. For example:
Relative Location headers are supported. Missing, duplicate or invalid
locations, unsupported redirect statuses and exhausted limits fail with a
VideoDownloadError. The request timeout covers the entire download chain.
Downloaded video bytes contribute to timing but are not stored in benchmark
response records. A CDN that requires authentication should use a presigned URL
in the redirect or the job’s url field.
Example with advanced parameters:
Polling Configuration
AIPerf automatically handles polling for video generation. Configure polling behavior:
Example with custom timeout and polling interval:
Advanced Usage: Extracting Generated Videos
To extract and save the generated videos, use --export-level raw to capture the full response payloads.
Run the benchmark with raw export:
Download the generated videos:
The response contains a URL to download the video. Copy the following script to download_videos.py:
Run the script:
Output:
Benchmark Scenarios
Scenario 1: Throughput Testing
Test maximum throughput with multiple concurrent requests:
Scenario 2: Latency Testing
Test single-request latency for different video sizes:
Scenario 3: Quality vs Speed Trade-off
Compare generation quality at different inference step counts:
Troubleshooting
Connection Refused
If you see Connection refused errors:
- Verify the SGLang server is running:
curl http://localhost:30010/health - Check the port matches your server configuration
- If using Docker, ensure port mapping is correct (
-p 30010:30010)
Timeout Errors
If requests time out during generation:
- Increase the request timeout:
--request-timeout-seconds 1200 - Check server logs for errors
- Reduce video resolution or duration for faster generation
Video Download Fails with a 3xx or 401/403
With --download-video-content, a 3xx error indicates an exhausted redirect
limit, an unsupported status, or a missing/invalid Location. Check the chain
and AIPERF_HTTP_VIDEO_DOWNLOAD_MAX_REDIRECTS (default 5; 0 disables redirects).
A foreign origin that requires endpoint auth headers can return 401/403 because
those credentials are withheld. Have the server return a presigned URL instead.
Foreign downloads also bypass environment proxies and .netrc authentication.
See Video Download Option for details.
Out of Memory
If the server crashes with OOM errors:
- Use a smaller model (e.g., Wan2.1-T2V-1.3B instead of 14B)
- Reduce video resolution:
--extra-inputs "size:720x480" - Enable CPU offloading:
--text-encoder-cpu-offload - Reduce concurrency:
--concurrency 1
Model Not Found
If you see model loading errors:
- Verify your Hugging Face token has access to the model
- Check the model path is correct
- Ensure sufficient disk space for model download
Response Fields
The video generation API returns the following fields:
Conclusion
You’ve successfully set up SGLang for video generation, run benchmarks with AIPerf, and learned how to download the generated videos. You can now experiment with different models, prompts, resolutions, and generation parameters to optimize your text-to-video workloads.
Key takeaways:
- Use
--endpoint-type video_generation - Control video parameters via
--extra-inputs - The transport handles polling automatically
- Use
--export-level rawto capture full responses for video extraction
Now go forth and generate!