Skip to main content

Overview

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

OpenAI Image Gen API Reference

Pipecat’s API methods for OpenAI image generation integration

OpenAI Documentation

Official OpenAI image generation API documentation and guides

OpenAI Platform

Access image generation models and manage API keys

Installation

To use OpenAI image generation services, install the required dependencies:

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 image generation models
  4. HTTP Session: Configure aiohttp session for image downloading

Required Environment Variables

  • OPENAI_API_KEY: Your OpenAI API key for authentication

Configuration

str
required
OpenAI API key for authentication.
aiohttp.ClientSession
required
HTTP session for downloading generated images. You must create and manage this yourself.
Literal['256x256', '512x512', '1024x1024', '1792x1024', '1024x1792']
deprecated
Deprecated since 0.0.105, removed in 2.0.0. Use settings=OpenAIImageGenService.Settings(image_size=...) instead.
str
default:"None"
Custom base URL for OpenAI API. If None, uses the default OpenAI endpoint.
str
default:"None"
deprecated
Deprecated since 0.0.105, removed in 2.0.0. Use settings=OpenAIImageGenService.Settings(model=...) instead.
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.

Usage

Basic Setup

With Settings

Notes

  • HTTP session required: You must provide an aiohttp.ClientSession for downloading the generated images from OpenAI’s URLs.
  • Image sizes vary by model: see OpenAI’s image generation guide for the sizes each model accepts.