Prerequisites
Before starting, make sure you have:- A Flexai account with access to the platform
- A Hugging Face token with access to the
stabilityai/stable-diffusion-3.5-largemodel - The
flexaiCLI installed and configured
Setup FlexAI Secret for Hugging Face Token
First, create a FlexAI secret that contains your Hugging Face token to access the inference model: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 Inference Endpoint
Start the FlexAI endpoint for the Stable Diffusion 3.5 Large model:- Create an inference endpoint named
stable-diffusion-35-large - Use the
flexserveruntime optimized for text-to-image tasks - Load the Stable Diffusion 3.5 Large model from Hugging Face
- Configure it for text-to-image generation
Get Endpoint Information
Once the endpoint is deployed, you’ll see the API key displayed in the output. Store it in an environment variable: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/Generate Images
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:dog.png in your current directory.
Parameters Explanation
The API accepts the following parameters:- inputs: The text prompt describing the image you want to generate
- height: Output image height in pixels
- width: Output image width in pixels
- num_inference_steps: Number of denoising steps (higher = better quality but slower)
- seed: Random seed for reproducible results
- negative_prompt: Description of what you don’t want in the image (helps improve quality)