Inference Providers documentation

Text to Image

Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

Text to Image

Generate an image based on a given text prompt.

For more details about the text-to-image task, check out its dedicated page! You will find examples and related materials.

Recommended models

Explore all available models and find the one that suits you best here.

Using the API

from huggingface_hub import InferenceClient client = InferenceClient( provider="fal-ai", api_key="hf_xxxxxxxxxxxxxxxxxxxxxxxx", ) # output is a PIL.Image object image = client.text_to_image( "Astronaut riding a horse", model="black-forest-labs/FLUX.1-dev", )

API specification

Request

Headers
authorizationstringAuthentication header in the form 'Bearer: hf_****' when hf_**** is a personal user access token with “Inference Providers” permission. You can generate one from your settings page.
Payload
inputs*stringThe input text data (sometimes called “prompt”)
parametersobject
        guidance_scalenumberA higher guidance scale value encourages the model to generate images closely linked to the text prompt, but values too high may cause saturation and other artifacts.
        negative_promptstringOne prompt to guide what NOT to include in image generation.
        num_inference_stepsintegerThe number of denoising steps. More denoising steps usually lead to a higher quality image at the expense of slower inference.
        widthintegerThe width in pixels of the output image
        heightintegerThe height in pixels of the output image
        schedulerstringOverride the scheduler with a compatible one.
        seedintegerSeed for the random number generator.

Response

Body
imageunknownThe generated image returned as raw bytes in the payload.
<>Update on GitHub

close