stable-diffusion.cpp/examples/server
leejet 1d0a58a350
Some checks failed
CI / ubuntu-latest-cmake (push) Has been cancelled
CI / ubuntu-latest-cmake-vulkan (push) Has been cancelled
CI / Build and push container images (push) Has been cancelled
CI / macOS-latest-cmake (push) Has been cancelled
CI / windows-latest-cmake (cpu, -DGGML_NATIVE=OFF -DSD_BUILD_SHARED_LIBS=ON -DSD_BUILD_SHARED_GGML_LIB=ON -DGGML_BACKEND_DL=ON -DGGML_CPU_ALL_VARIANTS=ON) (push) Has been cancelled
CI / windows-latest-cmake (cuda12, -DSD_CUDA=ON -DSD_BUILD_SHARED_LIBS=ON -DCMAKE_CUDA_ARCHITECTURES='61;70;75;80;86;89;90;100;120' -DCMAKE_CUDA_FLAGS='-Xcudafe "--diag_suppress=177" -Xcudafe "--diag_suppress=550"' -DGGML_NATIVE=OFF -DSD_BUILD_SHARED_GGML_L… (push) Has been cancelled
CI / windows-latest-cmake (vulkan, -DSD_VULKAN=ON -DSD_BUILD_SHARED_LIBS=ON -DGGML_NATIVE=OFF -DSD_BUILD_SHARED_GGML_LIB=ON -DGGML_BACKEND_DL=ON -DGGML_CPU_ALL_VARIANTS=ON) (push) Has been cancelled
CI / windows-latest-rocm (push) Has been cancelled
CI / ubuntu-latest-rocm (10.1.0, x64, gfx900;gfx906;gfx908;gfx90a;gfx90c;gfx942;gfx950;gfx1010;gfx1011;gfx1012;gfx1030;gfx1031;gfx1032;gfx1033;gfx1034;gfx1035;gfx1036;gfx1100;gfx1101;gfx1102;gfx1103;gfx1150;gfx1151;gfx1152;gfx1153;gfx1200;gfx1201) (push) Has been cancelled
CI / release (push) Has been cancelled
chore: move parameter and tokenizer diagnostics to debug (#2135)
2026-10-13 23:37:58 +08:00
..
frontend@8e7c115059 sync: update frontend 2026-10-06 20:04:34 +08:00
api.md docs: document video reference image support and constraints 2026-10-06 20:03:52 +08:00
async_jobs.cpp feat: Server: Add support for previews via sdcpp API (#2093) 2026-10-06 19:20:02 +08:00
async_jobs.h feat: Server: Add support for previews via sdcpp API (#2093) 2026-10-06 19:20:02 +08:00
CMakeLists.txt fix: keep the server frontend install out of a parent pnpm workspace (#2056) 2026-09-25 16:11:21 +08:00
main.cpp chore: move parameter and tokenizer diagnostics to debug (#2135) 2026-10-13 23:37:58 +08:00
README.md feat: add per-module automatic flash attention selection (#2132) 2026-10-13 22:58:45 +08:00
routes.h feat: add sdcpp api support (#1407) 2026-04-11 17:49:00 +08:00
routes_index.cpp feat: add sdcpp api support (#1407) 2026-04-11 17:49:00 +08:00
routes_openai.cpp feat: add configurable image input preprocessing (#2028) 2026-09-23 02:12:49 +08:00
routes_sdapi.cpp feat: enable sdapi latent2RGB previews (#2096) 2026-10-06 19:28:30 +08:00
routes_sdcpp.cpp feat: Server: Add support for previews via sdcpp API (#2093) 2026-10-06 19:20:02 +08:00
runtime.cpp fix: avoid scanning cwd during server startup (#2086) 2026-10-08 23:40:43 +08:00
runtime.h feat: Server: Add support for previews via sdcpp API (#2093) 2026-10-06 19:20:02 +08:00

Example

The following example starts sd-server with a standalone diffusion model, VAE, and LLM text encoder:

.\bin\Release\sd-server.exe --diffusion-model  ..\models\diffusion_models\z_image_turbo_bf16.safetensors --vae ..\models\vae\ae.sft  --llm ..\models\text_encoders\qwen_3_4b.safetensors --offload-to-cpu -v --cfg-scale 1.0

What this example does:

  • --diffusion-model selects the standalone diffusion model
  • --vae selects the VAE decoder
  • --llm selects the text encoder / language model used by this pipeline
  • --offload-to-cpu reduces VRAM pressure by keeping weights in RAM when possible
  • -v enables verbose logging (equivalent to --log-level verbose)
  • --cfg-scale 1.0 sets the default CFG scale for generation

Logging defaults to info. Use --log-level <level> to select debug, verbose, info, warn, or error (from most to least detailed). Each level includes messages at that level and all less detailed levels. -v and --verbose are equivalent to --log-level verbose. If repeated, the last logging option wins.

After the server starts successfully:

  • the web UI is available at http://127.0.0.1:1234/
  • the native async API is available under /sdcpp/v1/...
  • the compatibility APIs are available under /v1/... and /sdapi/v1/...

If you want to use a different host or port, pass:

--listen-ip <ip> --listen-port <port>

Frontend

Build with Frontend

The server can optionally build the web frontend and embed it into the binary as gen_index_html.h.

Requirements

Install the following tools:

npm install -g pnpm

Verify installation:

node -v
pnpm -v

Install frontend dependencies

Go to the frontend directory and install dependencies:

cd examples/server/frontend
pnpm install

Build the server with CMake

Enable the frontend build option when configuring CMake:

cmake -B build -DSD_SERVER_BUILD_FRONTEND=ON
cmake --build build --config Release

If pnpm is available, the build system will automatically run:

pnpm run build
pnpm run build:header

and embed the generated frontend into the server binary.

Frontend Repository

The web frontend is maintained in a separate repository, https://github.com/leejet/sdcpp-webui.

If you want to modify the UI or frontend logic, please submit pull requests to the frontend repository.

This repository (stable-diffusion.cpp) only vendors the frontend periodically. Changes from the frontend repo are synchronized:

  • approximately every 1–2 weeks, or
  • when there are major frontend updates

Because of this, frontend changes will not appear here immediately after being merged upstream.

Using an external frontend

By default, the server uses the embedded frontend generated during the build (gen_index_html.h).

You can also serve a custom frontend file instead of the embedded one by using:

--serve-html-path <path-to-index.html>

For example:

sd-server --serve-html-path ./index.html

In this case, the server will load and serve the specified index.html file instead of the embedded frontend. This is useful when:

  • developing or testing frontend changes
  • using a custom UI
  • avoiding rebuilding the binary after frontend modifications

Usage

For detailed command-line arguments, run:

./bin/sd-server -h

For completely black or white images or videos, NaNs, and the --linear-scale / --attn-scale startup options, see Troubleshooting.