This document contains essential information for agents working with the stable-diffusion.cpp-rest codebase.
This is a C++ REST API server that wraps the stable-diffusion.cpp library, providing HTTP endpoints for image generation with Stable Diffusion models. The project includes both a C++ backend and a Next.js frontend (webui).
Always use todo tools to track the status
# Create build directory and configure
mkdir build && cd build
cmake ..
cmake --build . -j
# Alternative: Use the existing rule file command
cd build
cmake --build . -j
Always use the build directory for compiling the project.
cd webui
npm install
npm run build
# For faster development when only changing the webui
cd webui; npm run build-static
# This builds the webui and copies the static files to build/webui/
# No need to rebuild the entire server or stop it during webui updates
# The server will automatically serve the updated static files
# always cd into the webui directory before run npm
src/ - Source files (.cpp)include/ - Header files (.h)CMakeLists.txt - Main build configuration.clang-format - C++ formatting rules (Chromium-based, 4-space indent)webui/ - Next.js React applicationwebui/package.json - Node.js dependencieswebui/tsconfig.json - TypeScript configurationwebui/next.config.ts - Next.js config (static export with /ui basePath)Models are stored in /data/SD_MODELS/ (not in project root to keep directory clean). Supported model types include:
using json = nlohmann::json;@/* maps to webui rootThe project uses intelligent model detection in src/model_detector.cpp:
ctxParams.model_pathctxParams.diffusion_model_pathMultiple authentication methods supported:
none - No authentication (default)jwt - JWT token authenticationapi-key - Static API keysunix - Unix system authenticationpam - PAM authentication (requires libpam0g-dev)optional - Authentication optionalcd build; ./src/stable-diffusion-rest-server --models-dir /data/SD_MODELS --port 8082 --host 0.0.0.0 --ui-dir ./webui --verbosenpm run build-static to avoid rebuilding the entire serverbuild-static command copies the built webui to build/webui/ for the server to serve/data/SD_MODELS/ (not project root)output: 'export')/ui/uiunoptimized: true)cmake --build . -j4 from build directorycd webui; npm run build-static but do not stop the running API servermcp_gogs_* tools for current repofszontagh/stable-diffusion.cpp-rest.clang-format - C++ code formatting.clang-tidy - C++ static analysiswebui/tsconfig.json - TypeScript configurationwebui/eslint.config.mjs - ESLint configurationwebui/next.config.ts - Next.js build configurationThe project supports various model quantization levels:
f32, f16 - Floating point formatsq8_0, q4_0, q3_k - Quantized formatsRemember: This project serves as a bridge between the C++ stable-diffusion.cpp library and web applications, with emphasis on performance, security, and ease of use.