Prerequisites
- Python 3.11+ if you plan to use the OpenAI Python SDK.
Serve
Launch the server using thesglang serve command.
Start the server
- —model-path: Path to the model or model ID.
- —served-model-name: Stable model name exposed by the serving APIs. It defaults to
--model-idwhen set, otherwise--model-path. - —port: HTTP port to listen on (default:
30000).
Served model name
--served-model-name separates the public API identity from the checkpoint location. This is useful when replicas use different local mount paths or when a gateway needs one stable model name:
--model-id is not a free-form deployment alias: it selects the registered model configuration for checkpoints whose local path cannot be identified. --served-model-name only controls the name exposed by serving APIs. When both are set, the served name takes precedence for API responses.
Discover the served model
Endpoint:GET /v1/models
Returns the public model name together with diffusion-specific runtime information.
Curl Example:
curl
curl
GET /server_info also reports served_model_name for gateway discovery. Video and action responses use this name when the request does not provide a model explicitly.
Endpoints
Model-specific request fields
The image and video request schemas contain only OpenAI fields and stable SGLang extensions shared across model families. Put model-specific controls inextra_body when using the OpenAI Python client:
Python
extra_params. SGLang forwards model-specific extensions only when the active
model declares them, so a field for one model family does not silently change
another model.
Image Generation
The server implements an OpenAI-compatible Images API under the/v1/images namespace.
Create an image
Endpoint: POST /v1/images/generations
Request quality
quality selects a cumulative request-level optimization tier: lossless keeps the selected deployment’s reference path and all unconditional bit-exact replacements; extra-high additionally enables only request-gated DiT/VAE kernel fusions; high includes the full extra-high set and may also enable model-owned sparse, caching, lower-precision, or other approximate paths. The tier does not override separately configured quantization, attention, or caching options. Omit it (or send OpenAI’s default auto) to keep the lossless runtime default. It is distinct from output_quality, which controls only output-file compression. The same extension is accepted by image edits and video requests.
Python Example (b64_json response):
Python
curl
Note IfEdit an image Endpoint:response_format=urlis used and cloud storage is not configured, the API returns a relative URL like/v1/images/<IMAGE_ID>/content.
POST /v1/images/edits
This endpoint accepts a multipart form upload with input images and a text prompt. The server can return either a base64-encoded image or a URL to download the image.
Curl Example (b64_json response):
Command
Command
response_format=url is used with POST /v1/images/generations or POST /v1/images/edits,
the API returns a relative URL like /v1/images/<IMAGE_ID>/content.
Endpoint: GET /v1/images/{image_id}/content
Curl Example:
Video Generation
The server implements a subset of the OpenAI Videos API under the/v1/videos namespace.
Create a video (text-to-video)
Endpoint: POST /v1/videos
Python Example:
Python
curl
Command
Command
GET /v1/videos
Python Example:
Python
curl
GET /v1/videos/{video_id}/content
Python Example:
Python
curl
LoRA Management
The server supports dynamic loading, merging, and unmerging of LoRA adapters. Important Notes:- Mutual Exclusion: Only one LoRA configuration can be active per target at a time
- Switching: To switch LoRAs, deactivate the current LoRA with
unmerge_lora_weights, thensetthe new one - Caching: The server caches loaded LoRA weights in memory. Switching back to a previously loaded LoRA (same path) has little cost
POST /v1/set_lora
Parameters:
lora_nickname(string or list of strings, required): A unique identifier for the LoRA adapter(s). Can be a single string or a list of strings for multiple LoRAslora_path(string or list of strings/None, optional): Path to the.safetensorsfile(s) or Hugging Face repo ID(s). Required for the first load; optional if re-activating a cached nickname. If a list, must match the length oflora_nicknametarget(string or list of strings, optional): Which transformer(s) to apply the LoRA to. If a list, must match the length oflora_nickname. Valid values:"all"(default): Apply to all transformers"transformer": Apply only to the primary transformer (high noise for Wan2.2)"transformer_2": Apply only to transformer_2 (low noise for Wan2.2)"critic": Apply only to the critic model
strength(float or list of floats, optional): LoRA strength for merge, default 1.0. If a list, must match the length oflora_nickname. Values < 1.0 reduce the effect, values > 1.0 amplify the effectmerge_mode(string, optional):"auto"(default server policy),"merge"(force static merge), or"dynamic"(apply LoRA at forward time)
Command
Command
Command
When using multiple LoRAs:
- All list parameters (
lora_nickname,lora_path,target,strength) must have the same length - If
targetorstrengthis a single value, it will be applied to all LoRAs - Multiple LoRAs applied to the same target are applied in order
With FSDP-sharded weights, manual merge may require a full-gather and can OOM. Use
set_lora with merge_mode="auto" or "dynamic" for the lower-peak path.POST /v1/merge_lora_weights
Parameters:
target(string, optional): Which transformer(s) to merge. One of “all” (default), “transformer”, “transformer_2”, “critic”strength(float, optional): LoRA strength for merge, default 1.0. Values < 1.0 reduce the effect, values > 1.0 amplify the effect
POST /v1/unmerge_lora_weights
Curl Example:
GET /v1/list_loras
Curl Example:
- If LoRA is not enabled for the current pipeline, the server will return an error.
num_lora_layers_with_weightscounts only layers that have LoRA weights applied for the active adapter.
Example: Switching LoRAs
- Set LoRA A:
Command
- Generate with LoRA A…
- Unmerge LoRA A:
Command
- Set LoRA B:
Command
- Generate with LoRA B…
Adjust Output Quality
The server supports adjusting output quality and compression levels for both image and video generation through theoutput-quality and output-compression parameters.
Parameters
-
output-quality(string, optional): Preset quality level that automatically sets compression. Default is"default". Valid values:"maximum": Highest quality (100)"high": High quality (90)"medium": Medium quality (55)"low": Lower quality (35)"default": Auto-adjust based on media type (50 for video, 75 for image)
-
output-compression(integer, optional): Direct compression level override (0-100). Default isNone. When provided (notNone), takes precedence overoutput-quality.0: Lowest quality, smallest file size100: Highest quality, largest file size
Notes
- Precedence: When both
output-qualityandoutput-compressionare provided,output-compressiontakes precedence - Format Support: Quality settings apply to JPEG, and video formats. PNG uses lossless compression and ignores these settings
- File Size vs Quality: Lower compression values (or “low” quality preset) produce smaller files but may show visible artifacts
