Image Generation

AI Model Hub for free: From December 1, 2024 until March 31, 2025, IONOS offers all foundation models of the AI Model Hub for free. Create your contract now and get your AI journey started today!

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

Supported Image Generation Models

The following models are currently available for image generation, each suited to different types of visual outputs:

Model Provider
Model Name
Purpose

stability.ai (License)

Stable Diffusion XL

Generates photorealistic images, ideal for marketing visuals, product mockups, and natural scenes.

BlackForestLab (License)

FLUX.1-schnell

Generates artistic, stylized images, well-suited for creative projects, digital art, and unique concept designs.

Overview

In this tutorial, you will learn how to generate images using foundation models via the IONOS API. This tutorial 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 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.

Step 1: Retrieve Available Models

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

# Python example to retrieve available models
import requests

IONOS_API_TOKEN = "[YOUR API TOKEN HERE]"

endpoint = "https://openai.inference.de-txl.ionos.com/v1/models"

header = {
    "Authorization": f"Bearer {IONOS_API_TOKEN}", 
    "Content-Type": "application/json"
}
requests.get(endpoint, headers=header).json()

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 with Your Prompt

To generate an image, send a prompt to the /images/generations endpoint. Customize parameters like size for the resolution of the output image.

# Python example for image generation
import requests

IONOS_API_TOKEN = "[YOUR API TOKEN HERE]"
MODEL_NAME = "[MODEL NAME HERE]"
PROMPT = "A futuristic cityscape at sunset, highly detailed"

endpoint = "https://openai.inference.de-txl.ionos.com/v1/images/generations"

header = {
    "Authorization": f"Bearer {IONOS_API_TOKEN}", 
    "Content-Type": "application/json"
}
body = {
    "model": MODEL_NAME,
    "prompt": PROMPT,
    "size": "1024x1024"
}
requests.post(endpoint, json=body, headers=header)

Step 3: Extract and Interpret the Result

The returned JSON includes several key fields, most importantly:

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

  • usage.prompt_tokens: Token count for the input prompt.

  • usage.total_tokens: Token count for the entire process (usually zero for image generation, as billing is per image).

Summary

In this tutorial, 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, refer to our dedicated tutorial on text generation models.

Last updated