black forest labs logoflux-schnell

state-of-the-art image generation model Learn more

Deploy flux-schnell behind an API endpoint in seconds.

Deploy model

Example usage

The model accepts a prompt which is some text describing the image you want to generate. The output images tend to get better as you add more descriptive words to the prompt.

The output JSON object contains a key called data which represents the generated image as a base64 string.

Input
1import httpx
2import os
3import base64
4from PIL import Image
5from io import BytesIO
6# Replace the empty string with your model id below
7model_id = ""
8baseten_api_key = os.environ["BASETEN_API_KEY"]
9# Function used to convert a base64 string to a PIL image
10def b64_to_pil(b64_str):
11    return Image.open(BytesIO(base64.b64decode(b64_str)))
12data = {
13  "prompt": 'red velvet cake spelling out the words "FLUX SCHNELL", tasty, food photography, dynamic shot'
14}
15# Call model endpoint
16res = httpx.post(
17    f"https://model-{model_id}.api.baseten.co/production/predict",
18    headers={"Authorization": f"Api-Key {baseten_api_key}"},
19    json=data
20)
21# Get output image
22res = res.json()
23output = res.get("data")
24# Convert the base64 model output to an image
25img = b64_to_pil(output)
26img.save("output_image.jpg")
27

JSON output
1{
2    "output": "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