This experiment demonstrates how to deploy and use a text-to-image model (Stable Diffusion 3.5 Large) using Flexai's inference serving capabilities.
Before starting, make sure you have:
First, create a FlexAI secret that contains your Hugging Face token to access the inference model:
# Enter your HF token value when prompted
flexai secret create MY_HF_TOKENNote: Make sure your Hugging Face token has access to the stabilityai/stable-diffusion-3.5-large model. You may need to accept the model's license terms on Hugging Face first.
Start the FlexAI endpoint for the Stable Diffusion 3.5 Large model:
INFERENCE_NAME=stable-diffusion-35-large
flexai inference serve $INFERENCE_NAME --runtime flexserve --hf-token-secret MY_HF_TOKEN -- --task text-to-image --model stabilityai/stable-diffusion-3.5-largeThis command will:
Once the endpoint is deployed, you'll see the API key displayed in the output. Store it in an environment variable:
export INFERENCE_API_KEY=<API_KEY_FROM_ENDPOINT_CREATION_OUTPUT>Then retrieve the endpoint URL:
export INFERENCE_URL=$(flexai inference inspect $INFERENCE_NAME -j | jq .config.endpointUrl -r)You'll notice these export lines use the jq tool to extract values from the JSON output of the inspect command.
If you don't have it already, you can get jq from its official website: https://jqlang.org/
Now you can generate images by making HTTP POST requests to your endpoint. Here's an example that generates a high-quality image of a golden retriever:
curl -X POST \
-H "Authorization: Bearer $INFERENCE_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"inputs": "A highly detailed, realistic photograph of a happy golden retriever sitting on a sofa, 8k, cinematic",
"parameters": {
"height": 1024,
"width": 1024,
"num_inference_steps": 20,
"seed": 42,
"negative_prompt": "blurry, low quality, distorted, deformed, mutated, extra limbs, cropped, out of frame, ugly, unrealistic, cartoon, drawing, painting, watermark, text, logo, nsfw"
}
}' \
-o dog.png \
"$INFERENCE_URL/v1/images/generations"This will save the generated image as dog.png in your current directory.
The API accepts the following parameters:

To celebrate this launch we’re offering €100 starter credits for first-time users!
Get Started Now