A request that ran the machine out of memory ended in a 500 and left the
server on the configuration that had just failed, so every later request
of that size failed the same way. The context now belongs to a
ContextKeeper (examples/server/recovery.*) and every generation of the
OpenAI, sdapi and sdcpp endpoints goes through ContextKeeper::run().
On out_of_memory or backend (the codes of sd_get_last_error()) it frees
the model, loads it again with the next lighter profile of
max > balanced > lite > lite-disk > lite-cpu and runs the same request
again. Steps that would load the same configuration are skipped, a
device failure jumps to lite-cpu, and from lite on the VAE is decoded in
tiles whatever the request asked. --profile sets the top of the ladder.
After --degradation-cooldown seconds (300; 0 = never) the server climbs
back one profile at the start of the next request. A climb that fails
on its first use is undone and doubles the wait, up to an hour. If the
model cannot be loaded again, requests get 503 "unavailable" and the
load is retried no more than every 15 seconds. --disable-degradation
keeps the old behavior of answering with the error.
Failures are answered with 503 and Retry-After (out of memory, no
context), 400 (invalid_argument) or 500, with a body of
{"error", "code", "retry_after_seconds"}. Async jobs report the same
code in error.code, 429 carries Retry-After, and std::bad_alloc in a
handler becomes a 503. New endpoints: GET /sdcpp/v1/health (status,
profile, counters, last error, queue; it never waits for a running
generation) and GET /sdcpp/v1/resources (system memory and devices).
sd-server now exits with code 1 and a message when it cannot listen or
create its HTTP threads; the second used to end in std::terminate and
the first in a silent exit 0. The lite-disk profile clears --eager-load,
which read every weight into memory and so saved nothing.
test/server_recovery_test.cpp checks the ladder, the step downs, the
climb back, the reload after a failure, the HTTP answers and use from
several threads with a scripted library and clock (114 checks, also
under ASan/UBSan and TSan). Checked with a synthetic SD 1.5 model on
the CPU under address-space limits: a 384x384 request at 2400 MiB steps
down to lite-disk and succeeds, below 2200 MiB it answers 503 and the
server stays up, the climb back and a failed climb behave as described,
and nine parallel requests of the three kinds are all served. The server
and the whole engine built with ASan/UBSan went through the ladder, the
CPU memory-guard scenarios and injected read errors without a report.
Not checked: Windows, GPUs, real models.
Claude-Session: https://claude.ai/code/session_01EhZzDBkuuMp1jBf4WtEySC
52 KiB
stable-diffusion.cpp Server APIs
This document describes the server-facing APIs exposed by examples/server.
The server currently exposes three API families:
OpenAI APIunder/v1/...Stable Diffusion WebUI APIunder/sdapi/v1/...sdcpp APIunder/sdcpp/v1/...
The sdcpp API is the native API surface.
Its request schema is the same schema used by sd_cpp_extra_args.
Global LoRA rule:
- Server APIs do not parse LoRA tags embedded inside
prompt. <lora:...>prompt syntax is intentionally unsupported inOpenAI API,sdapi, andsdcpp API.- LoRA must be passed through structured API fields when the API supports it.
Overview
OpenAI API
Compatibility API shaped like OpenAI image endpoints.
Current generation-related endpoints include:
POST /v1/images/generationsPOST /v1/images/editsGET /v1/models
Stable Diffusion WebUI API
Compatibility API shaped like the AUTOMATIC1111 / WebUI endpoints.
Current generation-related endpoints include:
POST /sdapi/v1/txt2imgPOST /sdapi/v1/img2imgGET /sdapi/v1/progressGET /sdapi/v1/lorasGET /sdapi/v1/upscalersGET /sdapi/v1/latent-upscale-modesGET /sdapi/v1/samplersGET /sdapi/v1/schedulersGET /sdapi/v1/sd-modelsGET /sdapi/v1/options
sdcpp API
Native async API for stable-diffusion.cpp.
Current endpoints include:
GET /sdcpp/v1/capabilitiesGET /sdcpp/v1/healthGET /sdcpp/v1/resourcesPOST /sdcpp/v1/img_genGET /sdcpp/v1/jobs/{id}POST /sdcpp/v1/jobs/{id}/cancelPOST /sdcpp/v1/vid_genPOST /sdcpp/v1/upscale
Failures and recovery
A generation that cannot be served is answered the same way by all three API families
(for sdcpp API jobs, the same code is reported in the error of the failed job).
| Status | code |
Meaning |
|---|---|---|
503 Service Unavailable |
out_of_memory |
The machine ran out of memory, even after the server tried the lighter configurations described below. Retry later, or send a smaller request. |
503 Service Unavailable |
unavailable |
The server has no usable model at this moment, for example because loading it again after a failure did not succeed yet. cause holds the reason. |
503 Service Unavailable |
busy |
The model was in use. |
400 Bad Request |
invalid_argument |
The request cannot be generated as it is (for example a size the model cannot handle). Retrying it unchanged will not help. |
500 Internal Server Error |
model_file, backend, generation_failed |
A model file could not be read, a compute device failed, or the generation failed without a more specific reason. |
The body is a JSON object, and a 503 also carries a Retry-After header:
{
"error": "unet compute buffer allocation failed (out of memory)",
"code": "out_of_memory",
"retry_after_seconds": 30
}
| Field | Type | Notes |
|---|---|---|
error |
string |
Human-readable reason |
code |
string |
One of the codes above |
cause |
string |
Only with unavailable: the code of the failure that left the server without a model |
retry_after_seconds |
integer |
Only with 503: how long to wait before trying again; mirrors the Retry-After header |
Other 4xx answers (400 for a malformed request, 429 when the job queue is full, 401 for a missing API key, ...)
keep their meaning. A 429 carries Retry-After: 10.
Stepping down
A request that fails because the machine ran out of memory (or because a compute device failed) does not end the
server and is not simply refused. The server frees the model, loads it again with the next lighter profile of the
ladder max > balanced > lite > lite-disk > lite-cpu, and runs the same request again:
| Profile | What changes |
|---|---|
balanced |
--memory-guard 90 |
lite |
memory guard 85, text encoder on the CPU, VAE decoded in tiles, no batched CFG |
lite-disk |
weights are streamed from disk (--params-backend disk) instead of being kept in memory; --eager-load is switched off |
lite-cpu |
everything is computed on the CPU (only when the machine has another device) |
Steps that would load the same configuration as the previous one are skipped, so the ladder is shorter when
the server was started with some of these options already. The profile the server was started with
(--profile, default max) is the top of the ladder. From lite on, the VAE is decoded in tiles whatever the
request asked. A device failure goes straight to the last profile of the ladder, lite-cpu.
A request served after a step-down is a normal 200. When even the lightest profile does not fit, the request
fails with the 503 above, and the server stays up, on the lightest profile that could load the model.
After --degradation-cooldown seconds (default 300) the server climbs back one profile, at the beginning of the next
request, which pays for loading the model again. A climb that does not work is undone and the wait doubles (up to an
hour); a climb that works resets it. With --degradation-cooldown 0 the server stays where it stepped down,
and with --disable-degradation it never steps down: such a request is answered with the error at once.
GET /sdcpp/v1/health reports the profile in use.
If the model cannot be loaded again after a failure, requests are answered with 503 / unavailable and
the server tries again from the next request on, no more often than every 15 seconds.
sd_cpp_extra_args
sd_cpp_extra_args is an extension mechanism for the compatibility APIs.
Rules:
- Its JSON schema is the same schema used by the native
sdcpp API. OpenAI APIandsdapican embed it insideprompt.sdcpp APIdoes not need it, because the request body already uses the native schema directly.
Embedding format:
normal prompt text <sd_cpp_extra_args>{"sample_params":{"sample_steps":28}}</sd_cpp_extra_args>
Behavior:
- The server extracts the JSON block.
- The JSON block is parsed using the same field rules as the
sdcpp API. - The block is removed from the final prompt before generation.
Supported use:
- extend
OpenAI APIrequests with nativestable-diffusion.cppcontrols - extend
sdapirequests with nativestable-diffusion.cppcontrols
Unsupported use:
- do not use
sd_cpp_extra_argswith/sdcpp/v1/*
OpenAI API
Purpose
This family exists for client compatibility.
Use it when you want OpenAI-style request and response shapes.
Native Extension
OpenAI API supports sd_cpp_extra_args embedded inside prompt.
The embedded JSON follows the sdcpp API request schema.
Supported Fields
POST /v1/images/generations
Currently supported top-level request fields:
| Field | Type | Notes |
|---|---|---|
prompt |
string |
Required |
n |
integer |
Number of images |
size |
string |
Format WIDTHxHEIGHT |
output_format |
string |
png, jpeg, or webp |
output_compression |
integer |
Range is clamped to 0..100 |
Native extension fields:
- any
sdcpp APIfields embedded throughsd_cpp_extra_argsinsideprompt
Response fields:
| Field | Type | Notes |
|---|---|---|
created |
integer |
Unix timestamp |
output_format |
string |
Final encoded image format |
data |
array<object> |
Generated image list |
data[].b64_json |
string |
Base64-encoded image bytes |
POST /v1/images/edits
Currently supported multipart form fields:
| Field | Type | Notes |
|---|---|---|
prompt |
string |
Required |
image[] |
file[] |
Preferred image upload field |
image |
file |
Legacy single-image upload field |
mask |
file |
Optional mask image |
n |
integer |
Number of images |
size |
string |
Format WIDTHxHEIGHT |
output_format |
string |
png or jpeg |
output_compression |
integer |
Range is clamped to 0..100 |
Native extension fields:
- any
sdcpp APIfields embedded throughsd_cpp_extra_argsinsideprompt
Uploaded images are decoded at their original dimensions. The first decoded
image establishes the generation dimensions if size is omitted. Input
geometry follows image_preprocess: references preserve their dimensions by
default, while init and mask use the generation canvas preset.
Reference encoding then follows model presets and ref_image_args. To skip
input geometry for references and disable resizing before VAE encoding, include
this in prompt:
edit this image <sd_cpp_extra_args>{"image_preprocess":"target=ref,mode=none","ref_image_args":"resize_before_vae=false"}</sd_cpp_extra_args>
Response fields:
| Field | Type | Notes |
|---|---|---|
created |
integer |
Unix timestamp |
output_format |
string |
Final encoded image format |
data |
array<object> |
Generated image list |
data[].b64_json |
string |
Base64-encoded image bytes |
GET /v1/models
Response fields:
| Field | Type | Notes |
|---|---|---|
data |
array<object> |
Available local models |
data[].id |
string |
Currently fixed to sd-cpp-local |
data[].object |
string |
Currently fixed to model |
data[].owned_by |
string |
Currently fixed to local |
Output Options
OpenAI API supports response serialization controls such as:
output_formatoutput_compression
Notes
OpenAI APIis synchronous from the HTTP client's perspective.- Native async job polling is not exposed through this family.
- Prompt-embedded
<lora:...>tags are intentionally unsupported.
Stable Diffusion WebUI API
Purpose
This family exists for client compatibility with WebUI-style tools.
Use it when you want txt2img / img2img-style endpoints and response shapes.
Native Extension
sdapi supports sd_cpp_extra_args embedded inside prompt.
The embedded JSON follows the sdcpp API request schema.
This allows sdapi clients to use native stable-diffusion.cpp controls without changing the outer request format.
Supported Fields
POST /sdapi/v1/txt2img
Currently supported request fields:
| Field | Type | Notes |
|---|---|---|
prompt |
string |
Required |
negative_prompt |
string |
Optional |
width |
integer |
Positive image width |
height |
integer |
Positive image height |
steps |
integer |
Sampling steps |
cfg_scale |
number |
Text CFG scale |
seed |
integer |
-1 means random |
batch_size |
integer |
Number of images |
clip_skip |
integer |
Optional |
sampler_name |
string |
WebUI sampler name |
scheduler |
string |
Scheduler name |
lora |
array<object> |
Structured LoRA list |
extra_images |
array<string> |
Base64 or data URL images |
enable_hr |
boolean |
Enable highres fix for txt2img |
hr_upscaler |
string |
Lanczos, Nearest, a latent mode such as Latent (nearest-exact), or an upscaler model name from /sdapi/v1/upscalers |
hr_scale |
number |
Highres scale when resize target is not set |
hr_resize_x |
integer |
Highres target width, 0 to use scale |
hr_resize_y |
integer |
Highres target height, 0 to use scale |
hr_steps |
integer |
Highres second-pass sample steps, 0 to reuse steps |
denoising_strength |
number |
Highres denoising strength for txt2img |
Native extension fields:
- any
sdcpp APIfields embedded throughsd_cpp_extra_argsinsideprompt
Response fields:
| Field | Type | Notes |
|---|---|---|
images |
array<string> |
Base64-encoded PNG images |
parameters |
object |
Echo of the parsed outer request body |
info |
string |
Currently empty string |
POST /sdapi/v1/img2img
Currently supported request fields:
| Field | Type | Notes |
|---|---|---|
all currently supported txt2img fields |
same as above | Reused |
init_images |
array<string> |
Base64 or data URL images |
mask |
string |
Base64 or data URL image |
inpainting_mask_invert |
integer or boolean |
Treated as invert flag |
denoising_strength |
number |
Clamped to 0.0..1.0 |
Highres fix fields are currently handled for txt2img; img2img uses denoising_strength as image-to-image strength.
Native extension fields:
- any
sdcpp APIfields embedded throughsd_cpp_extra_argsinsideprompt
Response fields:
| Field | Type | Notes |
|---|---|---|
images |
array<string> |
Base64-encoded PNG images |
parameters |
object |
Echo of the parsed outer request body |
info |
string |
Currently empty string |
GET /sdapi/v1/progress
Poll this endpoint while a synchronous SDAPI generation request is running.
An optional id_task query parameter selects the task with the same id_task
provided in the generation request (default: "sdapi"). Set
skip_current_image=true or 1 to omit the preview image.
current_image contains the latest base64 JPEG latent projection, or null
when unavailable. state.sampling_step is the positive logical step and
state.sampling_steps is the actual step count for the current sampling pass,
including schedule and img2img strength adjustments. state.job_no is the
zero-based pass index; state.job_count includes one pass per batch image and
an additional pass per image when highres fix is enabled. progress weights
these passes equally. Sampling progress can reach 1 before final decoding
finishes; eta_relative is currently always 0.
When no SDAPI task is active, or id_task does not match, the endpoint returns
progress=0, state.job="", zero job/step counts, and current_image=null.
Completed and failed requests do not retain an active preview.
Discovery / Compatibility Endpoints
Currently exposed:
GET /sdapi/v1/lorasGET /sdapi/v1/upscalersGET /sdapi/v1/latent-upscale-modesGET /sdapi/v1/samplersGET /sdapi/v1/schedulersGET /sdapi/v1/sd-modelsGET /sdapi/v1/options
Response fields:
GET /sdapi/v1/loras
| Field | Type | Notes |
|---|---|---|
[].name |
string |
Display name derived from file stem |
[].path |
string |
Relative path under the configured LoRA directory |
GET /sdapi/v1/upscalers
| Field | Type | Notes |
|---|---|---|
[].name |
string |
Built-in name or model stem |
[].model_name |
string | null |
Model family label for model-backed upscalers |
[].model_path |
string | null |
Absolute model path for model-backed upscalers |
[].model_url |
string | null |
Currently always null |
[].scale |
integer |
Currently 4 |
Built-in entries include None, Lanczos, and Nearest. Model-backed entries are scanned from the top level of --hires-upscalers-dir; subdirectories are not scanned.
GET /sdapi/v1/latent-upscale-modes
| Field | Type | Notes |
|---|---|---|
[].name |
string |
WebUI-compatible latent upscale mode name |
Built-in latent modes include Latent, Latent (nearest), Latent (nearest-exact), Latent (antialiased), Latent (bicubic), and Latent (bicubic antialiased).
GET /sdapi/v1/samplers
| Field | Type | Notes |
|---|---|---|
[].name |
string |
Sampler name |
[].aliases |
array<string> |
Currently contains the same single sampler name |
[].options |
object |
Currently empty object |
GET /sdapi/v1/schedulers
| Field | Type | Notes |
|---|---|---|
[].name |
string |
Scheduler name |
[].label |
string |
Same value as name |
GET /sdapi/v1/sd-models
| Field | Type | Notes |
|---|---|---|
[].title |
string |
Model stem |
[].model_name |
string |
Same value as title |
[].filename |
string |
Model filename |
[].hash |
string |
Placeholder compatibility value |
[].sha256 |
string |
Placeholder compatibility value |
[].config |
null |
Currently always null |
GET /sdapi/v1/options
| Field | Type | Notes |
|---|---|---|
samples_format |
string |
Currently fixed to png |
sd_model_checkpoint |
string |
Model stem |
Notes
sdapiis synchronous from the HTTP client's perspective.- Prompt-embedded
<lora:...>tags are intentionally unsupported.
sdcpp API
Purpose
This is the native stable-diffusion.cpp API.
Use it when you want:
- async job submission
- explicit native parameter control
- frontend-oriented capability discovery
Job Model
All async generation requests create a job.
Job states:
queuedgeneratingcompletedfailedcancelled
Common job shape:
{
"id": "job_01HTXYZABC",
"kind": "img_gen",
"status": "queued",
"created": 1775401200,
"started": null,
"completed": null,
"queue_position": 2,
"result": null,
"error": null
}
Field types:
| Field | Type |
|---|---|
id |
string |
kind |
string |
status |
string |
created |
integer |
started |
integer | null |
completed |
integer | null |
queue_position |
integer |
result |
object | null |
error |
object | null |
preview |
object | null |
preview sub-fields:
| Field | Type | Notes |
|---|---|---|
preview.pass |
integer |
Sampling pass number, starting at 1 within the job |
preview.step |
integer |
Positive logical sample step within this pass |
preview.total_steps |
integer |
Actual sample steps in this pass, after schedule and strength adjustments |
preview.b64_json |
string |
Base64-encoded PNG of the current preview frame |
The preview is updated in place as sampling progresses; poll GET /sdcpp/v1/jobs/{id} to retrieve the latest frame. Only the most recent preview is retained.
step / total_steps describes the current sampling pass, not overall job completion. A new batch item, high/low-noise stage, or highres pass increments pass and restarts step. Samplers with multiple denoiser evaluations per logical step may update a preview more than once at the same step. The frame and its pass/step metadata are published together.
Endpoints
GET /sdcpp/v1/capabilities
Returns frontend-friendly capability metadata.
The mode-aware fields are the primary interface. The top-level compatibility fields are deprecated mirrors kept for older clients.
Top-level fields:
| Field | Type | Notes |
|---|---|---|
model |
object |
Loaded model metadata |
current_mode |
string |
The native generation mode mirrored by top-level compatibility fields |
supported_modes |
array<string> |
Supported native modes such as img_gen or vid_gen |
defaults |
object |
Deprecated compatibility mirror of defaults_by_mode[current_mode] |
output_formats |
array<string> |
Deprecated compatibility mirror of output_formats_by_mode[current_mode] |
features |
object |
Deprecated compatibility mirror of features_by_mode[current_mode] |
defaults_by_mode |
object |
Explicit defaults for each supported mode |
output_formats_by_mode |
object |
Explicit output formats for each supported mode |
features_by_mode |
object |
Explicit feature flags for each supported mode |
samplers |
array<string> |
Available sampling methods |
schedulers |
array<string> |
Available schedulers |
loras |
array<object> |
Available LoRA entries |
upscalers |
array<object> |
Available highres upscalers, built-in and model-backed |
upscale |
boolean |
Whether a compatible RGB ESRGAN model is available for POST /sdcpp/v1/upscale |
preview_modes |
array<string> |
Available preview modes, e.g. ["none", "proj", "tae", "vae"] |
limits |
object |
Shared queue and size limits |
model
| Field | Type |
|---|---|
model.name |
string |
model.stem |
string |
model.path |
string |
Compatibility rules:
defaults,output_formats, andfeaturesare deprecated compatibility mirrors- those three top-level fields always mirror
current_mode supported_modes,defaults_by_mode,output_formats_by_mode, andfeatures_by_modeare the mode-aware fields
Mode-aware objects:
| Field | Type |
|---|---|
defaults_by_mode.img_gen |
object |
defaults_by_mode.vid_gen |
object |
output_formats_by_mode.img_gen |
array<string> |
output_formats_by_mode.vid_gen |
array<string> |
features_by_mode.img_gen |
object |
features_by_mode.vid_gen |
object |
Shared nested fields:
loras
| Field | Type |
|---|---|
loras[].name |
string |
loras[].path |
string |
upscalers
| Field | Type | Notes |
|---|---|---|
upscalers[].name |
string |
Built-in name or model stem; use this value in hires.upscaler |
upscalers[].model |
boolean |
True for a model-backed upscaler, false for a built-in scaling filter |
upscalers[].image_upscale |
boolean |
Whether this model can be selected by POST /sdcpp/v1/upscale; false for latent upscalers and built-in filters |
Built-in entries include None, Lanczos, Nearest, Latent, Latent (nearest), Latent (nearest-exact), Latent (antialiased), Latent (bicubic), and Latent (bicubic antialiased). Model-backed entries are scanned from the top level of --hires-upscalers-dir; subdirectories are not scanned.
limits
| Field | Type |
|---|---|
limits.min_width |
integer |
limits.max_width |
integer |
limits.min_height |
integer |
limits.max_height |
integer |
limits.max_batch_count |
integer |
limits.max_queue_size |
integer |
limits.max_upscale_width |
integer |
limits.max_upscale_height |
integer |
Shared default fields used by both img_gen and vid_gen:
| Field | Type |
|---|---|
prompt |
string |
negative_prompt |
string |
clip_skip |
integer |
width |
integer |
height |
integer |
strength |
number |
seed |
integer |
sample_params |
object |
sample_params.scheduler |
string |
sample_params.sample_method |
string |
sample_params.sample_steps |
integer |
sample_params.eta |
number | null |
sample_params.shifted_timestep |
integer |
sample_params.flow_shift |
number | null |
sample_params.guidance.txt_cfg |
number |
sample_params.guidance.img_cfg |
number | null |
sample_params.guidance.distilled_guidance |
number |
sample_params.guidance.slg.layers |
array<integer> |
sample_params.guidance.slg.layer_start |
number |
sample_params.guidance.slg.layer_end |
number |
sample_params.guidance.slg.scale |
number |
vae_tiling_params |
object |
vae_tiling_params.enabled |
boolean |
vae_tiling_params.temporal_tiling |
boolean |
vae_tiling_params.tile_size_w |
integer |
vae_tiling_params.tile_size_h |
integer |
vae_tiling_params.target_overlap |
number |
vae_tiling_params.rel_size_w |
number |
vae_tiling_params.rel_size_h |
number |
vae_tiling_params.extra_tiling_args |
string |
cache_mode |
string |
cache_option |
string |
scm_mask |
string |
scm_policy_dynamic |
boolean |
output_format |
string |
output_compression |
integer |
vae_tiling_params.tile_size_w and tile_size_h are in image pixels, with 0 selecting the 256-pixel default. Both encode and decode use these sizes without an encoding multiplier. Positive rel_size_w/rel_size_h values override the corresponding absolute size: values up to 1 are dimension fractions, and values greater than 1 are target tile counts. Set enabled to use spatial tiling. Sizes are aligned down to the VAE scale factor and capped at the input dimensions; explicit sizes below the minimum supported tile size are rejected. These fields previously used latent units; see VAE tiling for migration and OOM retry behavior.
vae_tiling_params.extra_tiling_args accepts a key=value list. Supported video VAEs accept temporal_tile_frames (alias temporal_tile_size, default 4) and temporal_tile_overlap (default 1).
LTX and Wan preserve causal state between temporal tiles. Hunyuan Video and TAEHV use overlap blending. MiniMax H3 keeps its model-specific fixed temporal windows because its latent-to-frame mapping is non-linear.
img_gen-specific default fields:
| Field | Type |
|---|---|
batch_count |
integer |
ref_image_args |
string |
increase_ref_index |
boolean |
control_strength |
number |
ip_adapter_strength |
number |
hires |
object |
hires.enabled |
boolean |
hires.upscaler |
string |
hires.scale |
number |
hires.target_width |
integer |
hires.target_height |
integer |
hires.steps |
integer |
hires.denoising_strength |
number |
hires.custom_sigmas |
array<number> |
hires.upscale_tile_size |
integer |
vid_gen-specific default fields:
| Field | Type |
|---|---|
video_frames |
integer |
fps |
integer |
moe_boundary |
number |
vace_strength |
number |
high_noise_sample_params |
object |
high_noise_sample_params.scheduler |
string |
high_noise_sample_params.sample_method |
string |
high_noise_sample_params.sample_steps |
integer |
high_noise_sample_params.eta |
number | null |
high_noise_sample_params.shifted_timestep |
integer |
high_noise_sample_params.flow_shift |
number | null |
high_noise_sample_params.guidance.txt_cfg |
number |
high_noise_sample_params.guidance.img_cfg |
number | null |
high_noise_sample_params.guidance.distilled_guidance |
number |
high_noise_sample_params.guidance.slg.layers |
array<integer> |
high_noise_sample_params.guidance.slg.layer_start |
number |
high_noise_sample_params.guidance.slg.layer_end |
number |
high_noise_sample_params.guidance.slg.scale |
number |
Fields returned in features_by_mode.img_gen:
init_imagemask_imagecontrol_imageip_adapter_imageref_imagesloravae_tilinghirescachecancel_queuedcancel_generatingpreview
Fields returned in features_by_mode.vid_gen:
init_imageend_imagecontrol_frameshigh_noise_sample_paramsloravae_tilingcachecancel_queuedcancel_generatingpreview
GET /sdcpp/v1/health
Reports whether the server can generate and how it is coping with the memory of the machine. It never waits for a generation in progress, so it answers quickly even while the server is busy. It needs the API key when one is set.
Example response:
{
"status": "degraded",
"model_loaded": true,
"profile": "lite",
"base_profile": "max",
"degradation": true,
"busy": false,
"counters": {
"requests": 12,
"succeeded": 11,
"failed": 1,
"recovered": 2,
"step_downs": 3,
"promotions": 1,
"failed_promotions": 0,
"rebuilds": 4
},
"last_error": {
"code": "out_of_memory",
"message": "unet compute buffer allocation failed (out of memory)",
"at": 1775401204
},
"next_promotion_seconds": 214,
"uptime_seconds": 3601,
"version": "stable-diffusion.cpp ...",
"queue": {
"pending": 0,
"waiting": 0,
"max": 64
}
}
| Field | Type | Notes |
|---|---|---|
status |
string |
ok, degraded (running on a lighter profile than the one it was started with), recovering (the model is being loaded), unavailable (no usable model at the moment), or no_model (started without a model) |
model_loaded |
boolean |
|
profile |
string | null |
Profile in use: max, balanced, lite, lite-disk or lite-cpu; null without a model |
base_profile |
string |
Profile the server was started with |
degradation |
boolean |
false with --disable-degradation |
busy |
boolean |
A generation is running |
counters |
object |
Since the start. requests, succeeded, failed; recovered is the number of requests served after a step-down; step_downs, promotions, failed_promotions and rebuilds (times the model was loaded again) |
last_error |
object | null |
Last failure the server saw (code, message, at as a Unix time). Invalid requests are not recorded |
next_promotion_seconds |
integer | null |
Seconds until the next attempt to climb back; null when the server is on its base profile or does not climb |
uptime_seconds |
integer |
|
version |
string |
|
queue |
object |
Jobs of the async API: pending (queued or generating), waiting (queued) and max (limit before 429) |
Typical status codes:
200 OK503 Service Unavailableonly whenstatusisunavailable; the body is the same
GET /sdcpp/v1/resources
Reports the memory the server can see right now, for clients that want to size a request before sending it. It needs the API key when one is set.
Example response:
{
"system_memory": {
"total_bytes": 17179869184,
"available_bytes": 9126805504,
"process_bytes": 3221225472
},
"devices": [
{
"name": "CUDA0",
"description": "NVIDIA GeForce RTX ...",
"type": "gpu",
"free_memory_bytes": 3758096384,
"total_memory_bytes": 6442450944
}
]
}
| Field | Type | Notes |
|---|---|---|
system_memory |
object | null |
RAM of the machine (total_bytes, available_bytes) and the memory used by the server process (process_bytes); null where the platform does not report it |
devices |
array<object> |
The compute devices, as listed by --list-devices |
devices[].type |
string |
cpu, gpu, igpu, accel or unknown |
POST /sdcpp/v1/img_gen
Submits an async image generation job.
Successful submission returns 202 Accepted.
Example response:
{
"id": "job_01HTXYZABC",
"kind": "img_gen",
"status": "queued",
"created": 1775401200,
"poll_url": "/sdcpp/v1/jobs/job_01HTXYZABC"
}
Response fields:
| Field | Type |
|---|---|
id |
string |
kind |
string |
status |
string |
created |
integer |
poll_url |
string |
GET /sdcpp/v1/jobs/{id}
Returns current job status.
Typical status codes:
200 OK404 Not Found410 Gone
POST /sdcpp/v1/upscale
Runs one RGB ESRGAN upscaler over an image, with no generation involved. Latent upscaler models remain available for hires generation but cannot be used here.
This is the HTTP equivalent of sd-cli -M upscale: no diffusion model, text
encoder or sampling is used, so it is fast enough to answer synchronously and
does not create a job.
Request fields:
| Field | Type | Notes |
|---|---|---|
image |
string |
Required. Base64 or data URL image |
upscaler |
string |
A name from upscalers with image_upscale: true; the first compatible entry when omitted |
repeats |
integer |
Run the upscaler this many times, 1 to 4 (default 1) |
tile_size |
integer |
Tile size, defaulting to the server's --upscale-tile-size |
output_format |
string |
png, jpeg, or webp when built with WebP support (default png); unsupported formats return 400 |
output_compression |
integer |
Range is clamped to 0..100 |
Response fields:
| Field | Type | Notes |
|---|---|---|
images |
array<object> |
One image |
images[].index |
integer |
|
images[].b64_json |
string |
Base64-encoded image bytes |
upscaler |
string |
The upscaler actually used |
scale |
integer |
The model's scale factor |
repeats |
integer |
How many times it was run |
width |
integer |
Result width |
height |
integer |
Result height |
output_format |
string |
Final encoded image format |
Typical status codes:
200 OK400 Bad Request(invalid request, unsupported output format, unreadable image, incompatible upscaler, or output dimensions exceeding the limit)500 Internal Server Error503 Service Unavailablewhen the machine runs out of memory (see Failures and recovery)
Notes:
- Final output dimensions, including all repeats, must not exceed 8192 pixels on either axis (
limits.max_upscale_widthandlimits.max_upscale_height). Requests exceeding this bound are rejected before upscaling. - The upscaler models are three-channel; alpha is not preserved.
- The request holds the generation context lock, so an upscale and a generation never run on the device at the same time.
POST /sdcpp/v1/jobs/{id}/cancel
Attempts to cancel an accepted job.
Typical status codes:
200 OK404 Not Found409 Conflict410 Gone
Request Body
Example:
{
"prompt": "a cat sitting on a chair",
"negative_prompt": "",
"clip_skip": -1,
"width": 1024,
"height": 1024,
"strength": 0.75,
"seed": -1,
"batch_count": 1,
"ref_image_args": "",
"increase_ref_index": false,
"control_strength": 0.9,
"ip_adapter_strength": 1.0,
"embed_image_metadata": true,
"init_image": null,
"ref_images": [],
"mask_image": null,
"control_image": null,
"ip_adapter_image": null,
"sample_params": {
"scheduler": "discrete",
"sample_method": "euler_a",
"sample_steps": 28,
"eta": 1.0,
"shifted_timestep": 0,
"custom_sigmas": [],
"flow_shift": 0.0,
"guidance": {
"txt_cfg": 7.0,
"img_cfg": 7.0,
"distilled_guidance": 3.5,
"slg": {
"layers": [7, 8, 9],
"layer_start": 0.01,
"layer_end": 0.2,
"scale": 0.0
}
}
},
"lora": [],
"hires": {
"enabled": false,
"upscaler": "Latent",
"scale": 2.0,
"target_width": 0,
"target_height": 0,
"steps": 0,
"denoising_strength": 0.7,
"custom_sigmas": [],
"upscale_tile_size": 128
},
"vae_tiling_params": {
"enabled": false,
"temporal_tiling": false,
"tile_size_w": 0,
"tile_size_h": 0,
"target_overlap": 0.5,
"rel_size_w": 0.0,
"rel_size_h": 0.0,
"extra_tiling_args": ""
},
"cache_mode": "disabled",
"cache_option": "",
"scm_mask": "",
"scm_policy_dynamic": true,
"preview": "none",
"preview_interval": 1,
"output_format": "png",
"output_compression": 100
}
LoRA Rules
- The server only accepts explicit LoRA entries from the
lorafield. - Prompt-embedded
<lora:...>tags are intentionally unsupported. - Clients should resolve LoRA usage through the structured
loraarray.
Image Encoding Rules
Native image/video requests and SDAPI accept image_preprocess as a rule string
or array of rule strings. OpenAI-compatible requests can supply it in
sd_cpp_extra_args. See Image preprocessing
for one-time input geometry, native-resolution decoding, mask alignment, and
canny=true for edge detection on any supported image input.
Image generation also accepts ref_image_args as a string (for example,
"resize_before_vae=false") in native and SDAPI requests, or through
sd_cpp_extra_args in OpenAI-compatible requests. It controls downstream
reference encoding and is independent of input geometry rules.
Any image field accepts:
- a raw base64 string, or
- a data URL such as
data:image/png;base64,...
Channel expectations:
init_image: native channels (3 or 4); alpha is preserved and applied per modelref_images[]: native channels (3 or 4); alpha is preserved and applied per modelcontrol_image: 3 channelsip_adapter_image: 3 channelsmask_image: 1 channel
Models that support RGBA (e.g. Qwen-Image 2.1) use the alpha channel of init_image
and ref_images[]. RGB-only models drop it, so sending RGBA is safe for every model.
If omitted or null:
- single-image fields map to an empty
sd_image_t - array fields map to an empty C-style array, represented as
pointer = nullptrandcount = 0
Field Mapping Summary
Top-level scalar fields:
| Field | Type |
|---|---|
prompt |
string |
negative_prompt |
string |
clip_skip |
integer |
width |
integer |
height |
integer |
strength |
number |
seed |
integer |
batch_count |
integer |
ref_image_args |
string |
image_preprocess |
string | array<string> |
increase_ref_index |
boolean |
control_strength |
number |
ip_adapter_strength |
number |
embed_image_metadata |
boolean |
preview |
string |
preview_interval |
integer |
Image fields:
| Field | Type |
|---|---|
init_image |
string | null |
ref_images |
array<string> |
mask_image |
string | null |
control_image |
string | null |
ip_adapter_image |
string | null |
LoRA fields:
| Field | Type |
|---|---|
lora[].path |
string |
lora[].multiplier |
number |
lora[].is_high_noise |
boolean |
Sampling fields:
| Field | Type |
|---|---|
sample_params.scheduler |
string |
sample_params.sample_method |
string |
sample_params.sample_steps |
integer |
sample_params.eta |
number |
sample_params.shifted_timestep |
integer |
sample_params.custom_sigmas |
array<number> |
sample_params.flow_shift |
number |
sample_params.guidance.txt_cfg |
number |
sample_params.guidance.img_cfg |
number |
sample_params.guidance.distilled_guidance |
number |
sample_params.guidance.slg.layers |
array<integer> |
sample_params.guidance.slg.layer_start |
number |
sample_params.guidance.slg.layer_end |
number |
sample_params.guidance.slg.scale |
number |
Other native fields:
| Field | Type |
|---|---|
hires |
object |
hires.enabled |
boolean |
hires.upscaler |
string |
hires.scale |
number |
hires.target_width |
integer |
hires.target_height |
integer |
hires.steps |
integer |
hires.denoising_strength |
number |
hires.custom_sigmas |
array<number> |
hires.upscale_tile_size |
integer |
vae_tiling_params |
object |
vae_tiling_params.enabled |
boolean |
vae_tiling_params.temporal_tiling |
boolean |
vae_tiling_params.tile_size_w |
integer |
vae_tiling_params.tile_size_h |
integer |
vae_tiling_params.target_overlap |
number |
vae_tiling_params.rel_size_w |
number |
vae_tiling_params.rel_size_h |
number |
vae_tiling_params.extra_tiling_args |
string |
cache_mode |
string |
cache_option |
string |
scm_mask |
string |
scm_policy_dynamic |
boolean |
For hires.upscaler, use Lanczos, Nearest, Latent, Latent (nearest), Latent (nearest-exact), Latent (antialiased), Latent (bicubic), Latent (bicubic antialiased), or an upscalers[].name value from GET /sdcpp/v1/capabilities. Model-backed upscalers are resolved as --hires-upscalers-dir / (name + ext) and must live directly in that directory. hires.custom_sigmas, when present, overrides the generated second-pass hires sigma schedule; otherwise the hires schedule is trimmed by hires.denoising_strength.
HTTP-only output fields:
| Field | Type |
|---|---|
output_format |
string |
output_compression |
integer |
Optional Field Handling
Optional sampling fields may be omitted.
When omitted, backend defaults apply to these fields:
sample_params.schedulersample_params.sample_methodsample_params.etasample_params.flow_shiftsample_params.guidance.img_cfg
Preview Interval Semantics
preview_interval controls the period (in sample steps) at which preview frames are generated. The default is 1 (every step). Any non-positive values will be clamped to 1. Note that if preview is set to "none", no previews are produced regardless of the interval.
Completion Result
Example completed job:
{
"id": "job_01HTXYZABC",
"kind": "img_gen",
"status": "completed",
"created": 1775401200,
"started": 1775401203,
"completed": 1775401215,
"queue_position": 0,
"result": {
"output_format": "png",
"images": [
{
"index": 0,
"b64_json": "iVBORw0KGgoAAA..."
}
]
},
"error": null
}
Failure Result
Example failed job:
{
"id": "job_01HTXYZABC",
"kind": "img_gen",
"status": "failed",
"created": 1775401200,
"started": 1775401203,
"completed": 1775401204,
"queue_position": 0,
"result": null,
"error": {
"code": "generation_failed",
"message": "generate_image returned empty results"
}
}
error.code is generation_failed when the cause is not known, or one of out_of_memory, model_file,
backend, invalid_argument, busy or unavailable (see Failures and recovery).
A job that failed for lack of memory has already been tried on every lighter profile the server could use.
Cancelled Result
Example cancelled job:
{
"id": "job_01HTXYZABC",
"kind": "img_gen",
"status": "cancelled",
"created": 1775401200,
"started": null,
"completed": 1775401202,
"queue_position": 0,
"result": null,
"error": {
"code": "cancelled",
"message": "job cancelled by client"
}
}
Submission Errors
POST /sdcpp/v1/img_gen may return:
202 Acceptedwhen the job is created400 Bad Requestfor an empty body, unsupported model mode, invalid JSON, or invalid generation parameters429 Too Many Requestswhen the job queue is full (withRetry-After: 10)500 Internal Server Errorfor unexpected server exceptions during submission
vid_gen
The following section documents the native async contract for video generation.
POST /sdcpp/v1/vid_gen
Submits an async video generation job.
Successful submission returns 202 Accepted.
Example response:
{
"id": "job_01HTXYZVID",
"kind": "vid_gen",
"status": "queued",
"created": 1775401200,
"poll_url": "/sdcpp/v1/jobs/job_01HTXYZVID"
}
Response fields:
| Field | Type |
|---|---|
id |
string |
kind |
string |
status |
string |
created |
integer |
poll_url |
string |
Request Body
Compared with img_gen, the vid_gen request body:
vid_genis a single video sequence job, sobatch_countis not part of the request schemamask_image,control_image,control_strength,ip_adapter_image,ip_adapter_strength, andembed_image_metadataare not part of the request schemaref_imagesis accepted for MiniMax-H3 Ref2VA conditioning; other video model families currently ignore itvid_genaddsend_image,control_frames,high_noise_sample_params,video_frames,fps,moe_boundary, andvace_strength
Example:
{
"prompt": "a cat walking through a rainy alley",
"negative_prompt": "",
"clip_skip": -1,
"width": 832,
"height": 480,
"strength": 0.75,
"seed": -1,
"video_frames": 33,
"fps": 16,
"moe_boundary": 0.875,
"vace_strength": 1.0,
"init_image": null,
"end_image": null,
"ref_images": [],
"control_frames": [],
"sample_params": {
"scheduler": "discrete",
"sample_method": "euler",
"sample_steps": 28,
"eta": 1.0,
"shifted_timestep": 0,
"custom_sigmas": [],
"flow_shift": 0.0,
"guidance": {
"txt_cfg": 7.0,
"img_cfg": 7.0,
"distilled_guidance": 3.5,
"slg": {
"layers": [7, 8, 9],
"layer_start": 0.01,
"layer_end": 0.2,
"scale": 0.0
}
}
},
"high_noise_sample_params": {
"scheduler": "discrete",
"sample_method": "euler",
"sample_steps": -1,
"eta": 1.0,
"shifted_timestep": 0,
"flow_shift": 0.0,
"guidance": {
"txt_cfg": 7.0,
"img_cfg": 7.0,
"distilled_guidance": 3.5,
"slg": {
"layers": [7, 8, 9],
"layer_start": 0.01,
"layer_end": 0.2,
"scale": 0.0
}
}
},
"lora": [],
"vae_tiling_params": {
"enabled": false,
"temporal_tiling": false,
"tile_size_w": 0,
"tile_size_h": 0,
"target_overlap": 0.5,
"rel_size_w": 0.0,
"rel_size_h": 0.0,
"extra_tiling_args": ""
},
"cache_mode": "disabled",
"cache_option": "",
"scm_mask": "",
"scm_policy_dynamic": true,
"preview": "none",
"preview_interval": 1,
"output_format": "webm",
"output_compression": 100
}
Reference Image Rules
ref_imagescontains reference images for MiniMax-H3 Ref2VA conditioning.- Images retain request order and correspond to
<Picture 1>,<Picture 2>, and so on in the prompt. - For MiniMax-H3, non-empty
ref_imagescannot be combined withinit_imageorend_image. A conflicting API request fails during generation; the WebUI checks this before submission. - MiniMax-H3 does not support
control_frames; leave that array empty. - Other video model families currently ignore
ref_images. features_by_mode.vid_gendoes not currently advertiseref_images; its absence is not an indication that MiniMax-H3 reference images are unsupported.
See MiniMax-H3 reference conditioning for model requirements and prompt examples.
LoRA Rules
- The server only accepts explicit LoRA entries from the
lorafield. - Prompt-embedded
<lora:...>tags are intentionally unsupported. lora[].is_high_noisecontrols whether a LoRA applies only to the high-noise stage.
Image and Frame Encoding Rules
Any image field accepts:
- a raw base64 string, or
- a data URL such as
data:image/png;base64,...
Channel expectations:
init_image: 3 channelsend_image: 3 channelsref_images[]: decoded with native channels, then converted to RGB by MiniMax-H3control_frames[]: 3 channels
Frame ordering rules:
control_frames[]order is the conditioning frame ordercontrol_frames[]is preserved in request order
If omitted or null:
- single-image fields map to an empty
sd_image_t - array fields map to an empty C-style array, represented as
pointer = nullptrandcount = 0
Field Mapping Summary
Top-level scalar fields:
| Field | Type |
|---|---|
prompt |
string |
negative_prompt |
string |
clip_skip |
integer |
width |
integer |
height |
integer |
strength |
number |
seed |
integer |
video_frames |
integer |
fps |
integer |
moe_boundary |
number |
vace_strength |
number |
preview |
string |
preview_interval |
integer |
Image and frame fields:
| Field | Type |
|---|---|
init_image |
string | null |
end_image |
string | null |
ref_images |
array<string> |
control_frames |
array<string> |
LoRA fields:
| Field | Type |
|---|---|
lora[].path |
string |
lora[].multiplier |
number |
lora[].is_high_noise |
boolean |
Sampling fields:
| Field | Type |
|---|---|
sample_params.scheduler |
string |
sample_params.sample_method |
string |
sample_params.sample_steps |
integer |
sample_params.eta |
number |
sample_params.shifted_timestep |
integer |
sample_params.custom_sigmas |
array<number> |
sample_params.flow_shift |
number |
sample_params.guidance.txt_cfg |
number |
sample_params.guidance.img_cfg |
number |
sample_params.guidance.distilled_guidance |
number |
sample_params.guidance.slg.layers |
array<integer> |
sample_params.guidance.slg.layer_start |
number |
sample_params.guidance.slg.layer_end |
number |
sample_params.guidance.slg.scale |
number |
High-noise sampling fields:
| Field | Type |
|---|---|
high_noise_sample_params.scheduler |
string |
high_noise_sample_params.sample_method |
string |
high_noise_sample_params.sample_steps |
integer |
high_noise_sample_params.eta |
number |
high_noise_sample_params.shifted_timestep |
integer |
high_noise_sample_params.flow_shift |
number |
high_noise_sample_params.guidance.txt_cfg |
number |
high_noise_sample_params.guidance.img_cfg |
number |
high_noise_sample_params.guidance.distilled_guidance |
number |
high_noise_sample_params.guidance.slg.layers |
array<integer> |
high_noise_sample_params.guidance.slg.layer_start |
number |
high_noise_sample_params.guidance.slg.layer_end |
number |
high_noise_sample_params.guidance.slg.scale |
number |
Other native fields:
| Field | Type |
|---|---|
vae_tiling_params |
object |
vae_tiling_params.enabled |
boolean |
vae_tiling_params.temporal_tiling |
boolean |
vae_tiling_params.tile_size_w |
integer |
vae_tiling_params.tile_size_h |
integer |
vae_tiling_params.target_overlap |
number |
vae_tiling_params.rel_size_w |
number |
vae_tiling_params.rel_size_h |
number |
vae_tiling_params.extra_tiling_args |
string |
cache_mode |
string |
cache_option |
string |
scm_mask |
string |
scm_policy_dynamic |
boolean |
HTTP-only output fields:
| Field | Type |
|---|---|
output_format |
string |
output_compression |
integer |
For vid_gen, output_format and output_compression control container encoding.
fps is request metadata for the generated sequence and is echoed in the completed job result.
Allowed output_format values:
webmwebpavi
Output format behavior:
output_formatdefaults towebmwebpmeans animated WebPavimeans MJPG AVIwebmrequires the server to be built with WebM support; otherwise the request returns400
Result Payload
Completed jobs return one encoded container payload, not a list of per-frame images.
Result fields:
result.b64_jsoncontains the whole encoded container file as base64result.mime_typeidentifies the media typeresult.output_formatechoes the selected container formatresult.fpsechoes the effective playback FPSresult.frame_countreports the actual decoded frame count used to build the container
Expected MIME types:
output_format |
mime_type |
|---|---|
webm |
video/webm |
webp |
image/webp |
avi |
video/x-msvideo |
Optional Field Handling
Optional sampling fields may be omitted.
When omitted, backend defaults apply to these fields:
sample_params.schedulersample_params.sample_methodsample_params.etasample_params.flow_shiftsample_params.guidance.img_cfghigh_noise_sample_params.schedulerhigh_noise_sample_params.sample_methodhigh_noise_sample_params.etahigh_noise_sample_params.flow_shifthigh_noise_sample_params.guidance.img_cfg
high_noise_sample_params may also be omitted entirely.
Frame Count Semantics
video_frames is the requested target length, but the current core video path internally normalizes the effective frame count to the largest 4n + 1 value that does not exceed the requested count.
Examples:
video_frames = 33stays33video_frames = 34becomes33video_frames = 32becomes29
The completed job payload includes the actual decoded frame_count.
Completion Result
Example completed job:
{
"id": "job_01HTXYZVID",
"kind": "vid_gen",
"status": "completed",
"created": 1775401200,
"started": 1775401203,
"completed": 1775401215,
"queue_position": 0,
"result": {
"output_format": "webm",
"mime_type": "video/webm",
"fps": 16,
"frame_count": 33,
"b64_json": "GkXfo59ChoEBQveBAULygQRC84EIQo..."
},
"error": null
}
The response returns the encoded .webm, animated .webp, or .avi container payload directly.
Failure Result
Example failed job:
{
"id": "job_01HTXYZVID",
"kind": "vid_gen",
"status": "failed",
"created": 1775401200,
"started": 1775401203,
"completed": 1775401204,
"queue_position": 0,
"result": null,
"error": {
"code": "generation_failed",
"message": "generate_video returned no results"
}
}
error.code takes the same values as for img_gen jobs.
Cancelled Result
Example cancelled job:
{
"id": "job_01HTXYZVID",
"kind": "vid_gen",
"status": "cancelled",
"created": 1775401200,
"started": null,
"completed": 1775401202,
"queue_position": 0,
"result": null,
"error": {
"code": "cancelled",
"message": "job cancelled by client"
}
}
Submission Errors
POST /sdcpp/v1/vid_gen may return:
202 Acceptedwhen the job is created400 Bad Requestfor an empty body, unsupported model mode, invalid JSON, invalid generation parameters, or an unsupported output format429 Too Many Requestswhen the job queue is full (withRetry-After: 10)500 Internal Server Errorfor unexpected server exceptions during submission