Skip to main content

Setup

To get started, sign into Baseten with Truss and then install the Python requests library.
Sign in to Baseten
uvx truss login --browser
Install requests
uv pip install requests
Pick the model you want to deploy. Each tab is a self-contained recipe.
black-forest-labs/FLUX.1-dev is a 12B-parameter diffusion transformer model.This preset serves FLUX.1 dev on H100 40GB, tuned for text-to-image throughput.

Hardware

H100_40GB

Write the config

Create and move into the project directory:
mkdir flux1-dev-throughput && cd flux1-dev-throughput
Then create a file named config.yaml and paste the following:
config.yaml
external_package_dirs: []
model_metadata:
  example_model_input: {"prompt": 'black forest gateau cake spelling out the words "FLUX DEV", tasty, food photography, dynamic shot'}
  repo_id: black-forest-labs/FLUX.1-dev
model_name: "model:flux1-dev preset:throughput"
python_version: py311
requirements:
  - git+https://github.com/huggingface/diffusers.git@fc6a91e3834c35e57b398ad1c0d99f6f83557e04
  - transformers>=4.0.0,<5.0.0
  - accelerate
  - sentencepiece
  - protobuf
weights:
  - source: "hf://black-forest-labs/FLUX.1-dev@main"
    mount_location: "/models/FLUX.1-dev"
    auth_secret_name: "hf_access_token"
resources:
  accelerator: H100_40GB
  use_gpu: true
secrets:
  hf_access_token: null
system_packages:
  - ffmpeg
  - libsm6
  - libxext6

Deploy

Push the config to Baseten:
uvx truss push
You should see output similar to:
✨ Model flux1-dev-throughput was successfully pushed ✨
🪵 View logs for your deployment at https://app.baseten.co/models/abcd1234/logs/wxyz5678
Your model ID is the string after /models/ in the logs URL (abcd1234 in the example). Use it wherever you see {model_id} in the next section.

Call the model

Your deployment exposes /predict. Replace {model_id} with your model ID and make sure BASETEN_API_KEY is set.The deployment returns the generated image as base64-encoded bytes. Decode the response to write the image to disk.
main.py
import base64
import os
import requests

response = requests.post(
    "https://model-{model_id}.api.baseten.co/environments/production/sync/predict",
    headers={"Authorization": f"Bearer {os.environ['BASETEN_API_KEY']}"},
    json={"prompt": "black forest gateau cake spelling out the words \"FLUX DEV\", tasty, food photography, dynamic shot"},
)

image_b64 = response.json()["data"]
with open("output.png", "wb") as f:
    f.write(base64.b64decode(image_b64))