Stable Diffusion API for Python

Python client for the Stable Diffusion API — SD, SDXL and SDXL-Lightning text-to-image through a hosted endpoint

Run Stable Diffusion in the browser → View on GitHub

Install

pip install git+https://github.com/stable-diffusion-dev/stable-diffusion-api.git
export SYNEXA_API_KEY="sk-..."

Quickstart

import stable_diffusion_api

output = stable_diffusion_api.run({
    "prompt": "an astronaut riding a horse on mars, hd, dramatic lighting"
})
print(output)

Hosted models

About Stable Diffusion

Stable Diffusion is the open latent diffusion model from CompVis at LMU Munich, Runway and Stability AI, released in August 2022. By running diffusion in a compressed latent space it generated 512-pixel images on consumer GPUs and became the foundation of the open image-generation ecosystem; SDXL raised native resolution to 1024 pixels in 2023, and ByteDance's SDXL-Lightning distilled that into a four-step model. This client calls all three as hosted endpoints on Synexa, the same checkpoints their authors released, with no GPU or download on your side.

FAQ

Is there a Stable Diffusion API?

Stability AI offers its own paid API for its current models, and the original weights are open. This package is an independent Python client for three Stable Diffusion-family endpoints hosted on Synexa (stability-ai/stable-diffusion, stability-ai/sdxl and bytedance/sdxl-lightning-4step), served behind one HTTPS API.

How much does the Stable Diffusion API cost?

Per run on Synexa: stability-ai/stable-diffusion $0.0007, bytedance/sdxl-lightning-4step $0.001, stability-ai/sdxl $0.002. Billing is per prediction with no idle charge, and new accounts receive a free trial credit.

Can I run Stable Diffusion without a GPU?

Yes. With this client inference runs on Synexa's GPUs and your code receives image URLs; you need only Python 3.8+ and httpx. Running it locally needs a CUDA (or Apple Silicon) GPU with a few gigabytes of VRAM for SD 1.x and more for SDXL.

Does this client work with the CompVis repo, diffusers, AUTOMATIC1111 or ComfyUI?

No. It does not load local checkpoints, LoRAs, ControlNets or workflows; it is an HTTP client for the hosted endpoints. Use diffusers, AUTOMATIC1111 or ComfyUI when you need custom models or offline inference.

What input formats does it accept?

Input is a JSON object with prompt (string) required on every model. Optional fields include negative_prompt (string), width and height (integers, multiples of 64), num_inference_steps and num_outputs (integers), guidance_scale or cfg_scale (number), scheduler (string), seed (integer) and, on sdxl, input_image as a public image URL with denoising_strength. Output is one or more image URLs.

Is this the official Stable Diffusion SDK?

No. This is an independent, MIT-licensed client and is not affiliated with CompVis, Runway, Stability AI or ByteDance. The original project is at https://github.com/CompVis/stable-diffusion.

Get an API key and run Stable Diffusion →