Skip to main content

Flux API usage

For an overview of Flux fine-tuning, see Flux fine-tuning

  • Unlike SD15 checkpoint training, Flux is trained as a LoRA model type. As such, inference is taking place on a base model such as Flux1.dev and prompt.text should specify the loaded lora such as <lora:123456:1> - will load lora with id=123456 and strength=1
  • Flux1.Dev requires commercial license which Astria provides to its customers, and as such LoRA downloading is not available for API usage.

See LoRA docs on lora syntax

info

To avoid cloning inference details of different model types such as Flux LoRA vs SD1.5 checkpoint, please consider using the Packs API. Packs will help you abstract the inference logic so that you do not have to hard-code prompts and parameters such as w,h, cfg_scale in your backend. Moreover this will allow the creative department to launch packs, make modifications and even track likes, without needing to touch the backend code.

Step 1: Fine-tune a lora model

POST /tunes

# With images as multipart/form-data
# Hard coded tune id of Flux1.dev from the gallery - https://www.astria.ai/gallery/tunes
# https://www.astria.ai/gallery/tunes/1504944/prompts
curl -X POST -H "Authorization: Bearer $API_KEY" https://api.astria.ai/tunes \
-F tune[title]="John Doe - UUID - 1234-6789-1234-56789" \
-F tune[name]=man \
-F tune[preset]=flux-lora-portrait \
-F tune[callback]="https://optional-callback-url.com/webhooks/astria?user_id=1&tune_id=1" \
-F tune[base_tune_id]=1504944 \
-F tune[model_type]="lora" \
-F "tune[images][][email protected]" \
-F "tune[images][][email protected]" \
-F "tune[images][][email protected]" \
-F "tune[images][][email protected]"

# With image_urls as form-data
curl -X POST -H "Authorization: Bearer $API_KEY" https://api.astria.ai/tunes \
-F tune[title]="Grumpy cat - UUID - 1234-6789-1234-56789" \
-F tune[name]=cat \
-F tune[preset]=flux-lora-portrait \
-F tune[callback]="https://optional-callback-url.com/to-your-service-when-ready?user_id=1&tune_id=1" \
-F tune[base_tune_id]=1504944 \
-F tune[model_type]="lora" \
-F "tune[image_urls][]=https://i.imgur.com/HLHBnl9.jpeg" \
-F "tune[image_urls][]=https://i.imgur.com/HLHBnl9.jpeg" \
-F "tune[image_urls][]=https://i.imgur.com/HLHBnl9.jpeg" \
-F "tune[image_urls][]=https://i.imgur.com/HLHBnl9.jpeg"

# As JSON
cat > data.json <<- EOM
{
"tune": {
"title": "Grumpy Cat - UUID - 1234-6789-1234-56789",
"name": "cat",
"base_tune_id": 1504944,
"model_type": "lora",
"callback": "https://optional-callback-url.com/to-your-service-when-ready?user_id=1&tune_id=1",
"image_urls": [
"https://i.imgur.com/HLHBnl9.jpeg",
"https://i.imgur.com/HLHBnl9.jpeg",
"https://i.imgur.com/HLHBnl9.jpeg",
"https://i.imgur.com/HLHBnl9.jpeg"
]
}
}
EOM

curl -X POST -H"Content-Type: application/json" -H "Authorization: Bearer $API_KEY" --data @data.json https://api.astria.ai/tunes

Step 2: Generate images using the fine-tuned model

POST /tunes/:id/prompts

# Note the hard-coded 1504944 which is the tune_id of Flux1.dev from the gallery
curl -X POST -H "Authorization: Bearer $API_KEY" https://api.astria.ai/tunes/1504944/prompts \
-F prompt[text]="<lora:tune_id:strength> a painting of ohwx man in the style of Van Gogh" \
-F prompt[callback]="https://optional-callback-url.com/to-your-service-when-ready?prompt_id=1"