Skip to main content

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.

Installation

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

Prerequisites

Azure Account Setup

Before using Azure OpenAI image generation services, you need:
  1. Azure Account: Sign up at Azure Portal
  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

api_key
str
required
Azure OpenAI API key for authentication.
endpoint
str
required
Azure OpenAI endpoint URL.
aiohttp_session
aiohttp.ClientSession
required
HTTP session for API requests and downloading generated images. You must create and manage this yourself.
image_size
str
deprecated
Target size for generated images (e.g., "1024x1024"). Deprecated in v0.0.105. Use settings=AzureImageGenServiceREST.Settings(image_size=...) instead.
model
str
default:"None"
deprecated
Image generation model to use. Deprecated in v0.0.105. Use settings=AzureImageGenServiceREST.Settings(model=...) instead.
api_version
str
default:"2023-06-01-preview"
Azure API version string.
settings
AzureImageGenServiceREST.Settings
default:"None"
Runtime-configurable generation settings. See Settings below.

Settings

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

Usage

Basic Setup

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",
        ),
    )
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 for migration details.

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.