> ## Documentation Index
> Fetch the complete documentation index at: https://docs.pipecat.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# OpenAI Image Generation

> Image generation service implementation using OpenAI's DALL-E models

## 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.

<CardGroup cols={3}>
  <Card title="OpenAI Image Gen API Reference" icon="code" href="https://reference-server.pipecat.ai/en/latest/api/pipecat.services.openai.image.html">
    Pipecat's API methods for OpenAI image generation integration
  </Card>

  <Card title="OpenAI Documentation" icon="book" href="https://platform.openai.com/docs/guides/images">
    Official OpenAI DALL-E API documentation and guides
  </Card>

  <Card title="OpenAI Platform" icon="image" href="https://platform.openai.com/">
    Access DALL-E models and manage API keys
  </Card>
</CardGroup>

## Installation

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

```bash theme={null}
uv add "pipecat-ai[openai]"
```

## Prerequisites

### OpenAI Account Setup

Before using OpenAI image generation services, you need:

1. **OpenAI Account**: Sign up at [OpenAI Platform](https://platform.openai.com/)
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

<ParamField path="api_key" type="str" required>
  OpenAI API key for authentication.
</ParamField>

<ParamField path="aiohttp_session" type="aiohttp.ClientSession" required>
  HTTP session for downloading generated images. You must create and manage this
  yourself.
</ParamField>

<ParamField path="image_size" type="Literal['256x256', '512x512', '1024x1024', '1792x1024', '1024x1792']" deprecated>
  Target size for generated images. *Deprecated in v0.0.105. Use
  `settings=OpenAIImageGenService.Settings(image_size=...)` instead.*
</ParamField>

<ParamField path="base_url" type="str" default="None">
  Custom base URL for OpenAI API. If `None`, uses the default OpenAI endpoint.
</ParamField>

<ParamField path="model" type="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.*
</ParamField>

<ParamField path="settings" type="OpenAIImageGenService.Settings" default="None">
  Runtime-configurable generation settings. See [Settings](#settings) below.
</ParamField>

### Settings

Runtime-configurable settings passed via the `settings` constructor argument using `OpenAIImageGenService.Settings(...)`. See [Service Settings](/pipecat/fundamentals/service-settings) for details.

| Parameter    | Type          | Default     | Description                                                |
| ------------ | ------------- | ----------- | ---------------------------------------------------------- |
| `model`      | `str`         | `NOT_GIVEN` | DALL-E model identifier. *(Inherited from base settings.)* |
| `image_size` | `str \| None` | `NOT_GIVEN` | Target size for generated images.                          |

<Note>
  `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.
</Note>

## Usage

### Basic Setup

```python theme={null}
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

```python theme={null}
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",
    ),
)
```

<Tip>
  The `InputParams` / `params=` pattern is deprecated as of v0.0.105. Use
  `Settings` / `settings=` instead. See the [Service Settings
  guide](/pipecat/fundamentals/service-settings) for migration details.
</Tip>

## 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`.
