Skip to main content

Overview

OpenAIImageGenService provides high-quality image generation capabilities using OpenAI’s DALL-E models. It transforms text prompts into images with various size options and model configurations, offering both artistic and photorealistic image creation capabilities.

Installation

To use OpenAI image generation services, install the required dependencies:
pip install "pipecat-ai[openai]"

Prerequisites

OpenAI Account Setup

Before using OpenAI image generation services, you need:
  1. OpenAI Account: Sign up at OpenAI Platform
  2. API Key: Generate an OpenAI API key from your account dashboard
  3. Model Access: Ensure access to DALL-E models
  4. HTTP Session: Configure aiohttp session for image downloading

Required Environment Variables

  • OPENAI_API_KEY: Your OpenAI API key for authentication

Configuration

api_key
str
required
OpenAI API key for authentication.
aiohttp_session
aiohttp.ClientSession
required
HTTP session for downloading generated images. You must create and manage this yourself.
image_size
Literal['256x256', '512x512', '1024x1024', '1792x1024', '1024x1792']
deprecated
Target size for generated images. Deprecated in v0.0.105. Use settings=OpenAIImageGenService.Settings(image_size=...) instead.
base_url
str
default:"None"
Custom base URL for OpenAI API. If None, uses the default OpenAI endpoint.
model
str
default:"dall-e-3"
deprecated
DALL-E model to use for image generation. Deprecated in v0.0.105. Use settings=OpenAIImageGenService.Settings(model=...) instead.
settings
OpenAIImageGenService.Settings
default:"None"
Runtime-configurable generation settings. See Settings below.

Settings

Runtime-configurable settings passed via the settings constructor argument using OpenAIImageGenService.Settings(...). See Service Settings for details.
ParameterTypeDefaultDescription
modelstrNOT_GIVENDALL-E model identifier. (Inherited from base settings.)
image_sizestr | NoneNOT_GIVENTarget size for generated images.
NOT_GIVEN values are omitted from the request, letting the service use its own defaults ("dall-e-3" for model). Only parameters that are explicitly set are included.

Usage

Basic Setup

import aiohttp
from pipecat.services.openai import OpenAIImageGenService

async with aiohttp.ClientSession() as session:
    image_gen = OpenAIImageGenService(
        api_key=os.getenv("OPENAI_API_KEY"),
        aiohttp_session=session,
        image_size="1024x1024",
    )

With Settings

from pipecat.services.openai.image import OpenAIImageGenSettings

image_gen = OpenAIImageGenService(
    api_key=os.getenv("OPENAI_API_KEY"),
    aiohttp_session=session,
    settings=OpenAIImageGenService.Settings(
        model="dall-e-3",
        image_size="1792x1024",
    ),
)
The InputParams / params= pattern is deprecated as of v0.0.105. Use Settings / settings= instead. See the Service Settings guide for migration details.

Notes

  • HTTP session required: You must provide an aiohttp.ClientSession for downloading the generated images from OpenAI’s URLs.
  • Image sizes vary by model: DALL-E 3 supports 1024x1024, 1792x1024, and 1024x1792. DALL-E 2 supports 256x256, 512x512, and 1024x1024.