Prompt: A movie still of an astronaut with a dark visor with a lightning bolt superhero icon on his chest

Stability AI logoSDXL Lightning

A variant of Stable Diffusion XL that generates 1024x1024 px images in 4 UNet steps, enabling near real-time image creation. Learn more

Deploy SDXL Lightning behind an API endpoint in seconds.

Deploy model

Example usage

The model accepts a single input, prompt, and returns a base64 string of the image as the key result.

This implementation uses the 4-step UNet checkpoint to balance speed and quality. You can deploy your own version with either 2 steps for even faster results on 8 steps for even higher quality.

Input
1import base64
2import requests
3import os
4
5# Replace the empty string with your model id below
6model_id = ""
7baseten_api_key = os.environ["BASETEN_API_KEY"]
8BASE64_PREAMBLE = "data:image/png;base64,"
9
10data = {
11    "prompt": "a picture of a rhino wearing a suit",
12}
13
14# Call model endpoint
15res = requests.post(
16    f"https://model-{model_id}.api.baseten.co/production/predict",
17    headers={"Authorization": f"Api-Key {baseten_api_key}"},
18    json=data
19)
20
21# Get output image
22res = res.json()
23img_b64 = res.get("result")
24img = base64.b64decode(img_b64)
25
26# Save the base64 string to a PNG
27img_file = open("sdxl-output-1.png", "wb")
28img_file.write(img)
29img_file.close()
30os.system("open sdxl-output-1.png")
JSON output
1{
2    "result": "iVBORw0KGgoAAAANSUhEUgAABAAAAAQACAIAAA..."
3}
Preview

Deploy any model in just a few commands

Avoid getting tangled in complex deployment processes. Deploy best-in-class open-source models and take advantage of optimized serving for your own models.

$

truss init -- example stable-diffusion-2-1-base ./my-sd-truss

$

cd ./my-sd-truss

$

export BASETEN_API_KEY=MdNmOCXc.YBtEZD0WFOYKso2A6NEQkRqTe

$

truss push

INFO

Serializing Stable Diffusion 2.1 truss.

INFO

Making contact with Baseten 👋 👽

INFO

🚀 Uploading model to Baseten 🚀

Upload progress: 0% | | 0.00G/2.39G