Skip to main content
Version: Latest

Image Generation

Generate images from text prompts using the OpenAI-compatible Images API.

Prerequisites

What you'll learn:

  • How to generate images from text prompts
  • How to decode and save generated images
  • Available image generation models

Basic Usage

import base64
from openai import OpenAI

client = OpenAI()

prompt = """
A background with server racks and cables, with a futuristic city skyline
visible through a large window at sunrise. The room has blue and green LED
lights illuminating the equipment.
"""

result = client.images.generate(
model="gpt-image-1",
prompt=prompt,
)

# Decode and save the image
image_bytes = base64.b64decode(result.data[0].b64_json)
with open("generated_image.png", "wb") as f:
f.write(image_bytes)

print("Image saved to generated_image.png")

Available Models

ModelProviderDescription
gpt-image-1AzureOpenAI's image generation model

Next Steps

© Deutsche Telekom AG