GPU Compute / Recipe

Image generation endpoint

Serve a persistent image generation endpoint using badgr serve --task image. Badgr deploys an OpenAI-compatible Diffusers server that exposes POST /v1/images/generations — the same shape as the OpenAI images API. Use it with the OpenAI SDK, no custom HTTP client needed.

Prerequisites: npm install -g badgr-cli then badgr login. Setup guide →

1. Start the endpoint

Pass the HuggingFace model ID and --task image. Badgr selects a GPU, deploys the Diffusers server, and waits for it to be ready:

badgr serve black-forest-labs/FLUX.1-schnell --task image --gpu L40S --max-cost 10

Badgr prints the endpoint URL once the model is loaded (typically 2–5 minutes for large diffusion models). The server keeps running until you call badgr down.

Pass --env HF_TOKEN=$HF_TOKEN for gated models (FLUX.1-dev, etc.).

2. Generate images

Export BADGR_ENDPOINT from the URL printed by badgr serve and use the OpenAI SDK:

Python

import os, base64
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["BADGR_API_KEY"],
    base_url=os.environ["BADGR_ENDPOINT"],
)

resp = client.images.generate(
    model="black-forest-labs/FLUX.1-schnell",
    prompt="A futuristic city at sunset, photorealistic",
    n=1,
    size="1024x1024",
)

png_bytes = base64.b64decode(resp.data[0].b64_json)
with open("output.png", "wb") as f:
    f.write(png_bytes)

curl

curl $BADGR_ENDPOINT/v1/images/generations \
  -H "Authorization: Bearer $BADGR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "black-forest-labs/FLUX.1-schnell",
    "prompt": "A futuristic city at sunset, photorealistic",
    "n": 1,
    "size": "1024x1024"
  }' | python3 -c "import sys,json,base64; d=json.load(sys.stdin); open('output.png','wb').write(base64.b64decode(d['data'][0]['b64_json']))"

3. Stop billing

badgr down <deployment-id>

Terminates the GPU instance. Use badgr receipts to see cost after.

Supported models

Any HuggingFace model compatible with DiffusionPipeline.from_pretrained():

black-forest-labs/FLUX.1-schnellFLUX.1-schnell — fast 4-step model, 16GB+ VRAM, public
black-forest-labs/FLUX.1-devFLUX.1-dev — higher quality, requires HF token
stabilityai/stable-diffusion-xl-base-1.0SDXL — 48GB VRAM recommended
stabilityai/sdxl-turboSDXL-Turbo — 4-step, faster than SDXL

Options

--task imageRequired — selects the OpenAI-compatible Diffusers server
--gpu <type>RTX_4090 or L40S for FLUX.1-schnell; A100 for larger models
--env HF_TOKEN=...Required for gated models (FLUX.1-dev, etc.)
--env IMAGE_MAX_STEPS=NOverride inference steps (default: 4 for schnell/turbo, 20 for others)
--max-cost <$>Auto-stop when total spend reaches this amount
--no-waitReturn immediately; use badgr logs to confirm startup

Next steps