For the complete documentation index, see llms.txt. This page is also available as Markdown.

Image Generation

The IONOS CLOUD AI Model Hub provides an OpenAI-compatible API that enables high-quality image generation using state-of-the-art foundation models. By inserting descriptive prompts, users can create detailed images directly through the API without the need for managing underlying hardware, or infrastructure.

Supported image generation models

AI Model Hub offers varied text-to-image models. For more information, see models list.

Overview

In this guide, you will learn how to generate images using foundation models through the IONOS CLOUD API. This guide is intended for developers with basic knowledge of:

  • REST APIs

  • A programming language for handling REST API endpoints (Python and Bash examples are provided)

By the end, you will be able to:

  1. Retrieve a list of available image generation models in the IONOS CLOUD AI Model Hub.

  2. Use prompts to generate images with these models.

Getting started with image generation

To use image generation models, first set up your environment and authenticate using the OpenAI-compatible API endpoints.

Download the respective code files to use image generation-specific scripts and examples and generate the intended output:

Download this Python Notebook file to use image generation-specific scripts and examples and generate the intended output.

Download this Python code file to use image generation-specific scripts and examples and generate the intended output.

Download this Bash code file to use image generation-specific scripts and examples and generate the intended output. The file has a .txt extension. To run it, rename it to .sh or run it with bash, for example bash ai-model-hub-image-generation.txt.

Step 1: Retrieve Available Models

Fetch a list of models to see which are available for your use case:

This query returns a JSON document listing each model's name, which you’ll use to specify a model for image generation in later steps.

Step 2: Generate an image using a prompt and FLUX.1-schnell

To generate an image, send a prompt to the /images/generations endpoint. Note the following parameter restrictions for FLUX.1-schnell:

  • size: Must be one of "1024x1024", "1792x1024", or "1024x1792".

  • n: Defaults to 1. Only 1 is accepted.

Step 3: Generate an image using a prompt and FLUX.2-klein-4B

To generate an image, send a prompt to the /images/generations endpoint. Note the following parameter restrictions for FLUX.2-klein-4B:

  • size: A string specifying the dimensions in widthxheight format. Both dimensions must be between 64 and 2048 (inclusive) and are automatically rounded down to the nearest multiple of 16. Default: 1024x1024. Examples: 1024x1024, 1536x1024, 1024x1536, 2048x2048, 2048x1152.

  • n: Number of images to generate. Defaults to 1. Accepts values from 1 to 10 if the request produces at most 12,582,912 pixels in total (n × width × height), for example three 2048x2048 images or ten 1024x1024 images.

  • output_format: Format of the returned image. Accepted values: jpg, jpeg, png, webp.

Requests that do not meet these limits are rejected with a 400 Bad Request error detailing the exceeded limit.

Step 4: Extract and interpret the result

The returned JSON includes several key fields, most importantly:

  • data.[].b64_json: The generated image in base64 format.

What you learned

In this guide, you learned how to:

  1. Access available image generation models.

  2. Use descriptive prompts to generate high-quality images, ideal for applications in design, creative work, and more.

For information on text generation, see our dedicated guide on Text Generation models.

Last updated

Was this helpful?