Who it is forAn app developer who wants an image feature that runs on the user's device instead of a paid API.
The problemCalling a hosted image API adds per-image cost and sends user prompts to a third party.
The outcomeYour app generating images through a native library with no cloud dependency.
What you need first
- The sd executable from the releases page, or a build from source following the build guide
- Model weights in .ckpt, .safetensors or .gguf format
- Linux, macOS or Windows; Android works through Termux
- Enough RAM or VRAM for the model; the performance guide covers reducing it
Steps
- Pick the binding for your language from the Bindings list, for example stable-diffusion-cpp-python for Python or diffusion-rs for Rust
- Confirm your model works first with the command line:
./bin/sd-cli -m ../models/v1-5-pruned-emaonly.safetensors -p "a lovely cat" - Follow the binding's own README to load the same weights from your code
- Add LoRA or ESRGAN upscaling later if you need them; both are listed features
- Pin the Stable Diffusion CPP version, since the project warns that the API changes frequently
Prompt for your agent
Add local image generation to my <language> app using the stable-diffusion.cpp binding listed for it in the leejet/stable-diffusion.cpp README. Load <model weights>, expose a generate(prompt) function, and pin the library version.
Caveat. Bindings are third-party projects with their own release pace, so check that the one you pick supports your model.
Use this in your AI agent
Ask your agent
Using the Deduped MCP, get the setup steps for leejet/stable-diffusion.cpp and "Add local image generation to your own app"
Add Deduped to Claude Code once
claude mcp add --transport http deduped https://dedupedai.com/mcp
Every Monday: the 5 hottest repos and exactly how to use them. Free, one email a week, unsubscribe anytime.
Get them freeShare: X LinkedIn Hacker News Email Copy link
Third-party repos we don't own. AI-written use cases can be wrong. Disclaimer