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

# Azure OpenAI Image Generation

> Image generation service implementation using Azure OpenAI's REST API

## Overview

`AzureImageGenServiceREST` provides image generation capabilities using Azure's OpenAI service via REST API. It supports asynchronous image generation with automatic polling for completion and image downloading.

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

  <Card title="Azure OpenAI Documentation" icon="book" href="https://learn.microsoft.com/en-us/azure/ai-services/openai/dall-e-quickstart">
    Official Azure OpenAI DALL-E documentation and guides
  </Card>
</CardGroup>

## Installation

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

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

## Prerequisites

### Azure Account Setup

Before using Azure OpenAI image generation services, you need:

1. **Azure Account**: Sign up at [Azure Portal](https://portal.azure.com/)
2. **Azure OpenAI Resource**: Create an Azure OpenAI resource
3. **API Key**: Get your API key from the Azure OpenAI resource
4. **Endpoint**: Note your resource endpoint URL
5. **HTTP Session**: Configure aiohttp session for image downloading

### Required Environment Variables

* `AZURE_API_KEY`: Your Azure OpenAI API key for authentication
* `AZURE_ENDPOINT`: Your Azure OpenAI endpoint URL

## Configuration

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

<ParamField path="endpoint" type="str" required>
  Azure OpenAI endpoint URL.
</ParamField>

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

<ParamField path="image_size" type="str" deprecated>
  Target size for generated images (e.g., `"1024x1024"`). *Deprecated in
  v0.0.105. Use `settings=AzureImageGenServiceREST.Settings(image_size=...)`
  instead.*
</ParamField>

<ParamField path="model" type="str" default="None" deprecated>
  Image generation model to use. *Deprecated in v0.0.105. Use
  `settings=AzureImageGenServiceREST.Settings(model=...)` instead.*
</ParamField>

<ParamField path="api_version" type="str" default="2023-06-01-preview">
  Azure API version string.
</ParamField>

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

### Settings

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

| Parameter    | Type          | Default     | Description                                                          |
| ------------ | ------------- | ----------- | -------------------------------------------------------------------- |
| `model`      | `str`         | `NOT_GIVEN` | Image generation model identifier. *(Inherited from base settings.)* |
| `image_size` | `str \| None` | `NOT_GIVEN` | Target size for generated images (e.g., `"1024x1024"`).              |

<Note>
  `NOT_GIVEN` values are omitted from the request, letting the service use its
  own defaults. Only parameters that are explicitly set are included.
</Note>

## Usage

### Basic Setup

```python theme={null}
import aiohttp
from pipecat.services.azure.image import AzureImageGenServiceREST

async with aiohttp.ClientSession() as session:
    image_gen = AzureImageGenServiceREST(
        api_key=os.getenv("AZURE_API_KEY"),
        endpoint=os.getenv("AZURE_ENDPOINT"),
        aiohttp_session=session,
        settings=AzureImageGenServiceREST.Settings(
            image_size="1024x1024",
        ),
    )
```

<Tip>
  The deprecated `model` and `image_size` constructor parameters are replaced by
  `Settings` 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 both API requests and downloading the generated images.
* **Asynchronous generation**: Azure uses an asynchronous pattern where image generation is submitted and then polled for completion, with a timeout of 120 seconds.
* **REST API**: This service uses Azure's REST API directly (not the OpenAI SDK), requiring an explicit endpoint URL.
