Azure OpenAI
Image generation through Azure OpenAI's REST API, with AzureImageGenServiceREST.
Overview
AzureImageGenServiceREST: turns eachTextFrameit receives into a prompt for Azure OpenAI's asynchronous image generation API. It submits the job, polls it once a second until it succeeds, downloads the image and pushes it as aURLImageRawFrameof RGB pixels.
Upstream page
Pipecat's documentation for the same service.
Source
packages/azure/src/image.ts.
Azure docs
Image generation on Azure OpenAI.
Installation
bun add @pipedog/azureimport { AzureImageGenServiceREST } from "@pipedog/azure/image";Prerequisites
- An Azure OpenAI resource whose region offers image generation, and its API key. The examples
read it from
AZURE_OPENAI_API_KEY. - The resource endpoint, ending in
/(the service appendsopenai/images/...to it).
AzureImageGenServiceREST
Configuration
Prop
Type
Settings
Runtime-updatable settings, passed as settings: new AzureImageGenServiceREST.Settings({...})
(AzureImageGenSettings). Any setting you leave out keeps the default below.
| Setting | Type | Default | Description |
|---|---|---|---|
model | string | null | null | Not sent: the endpoint decides the model. |
imageSize | string | null | null | Sent as size (for example "1024x1024"). null leaves it out. |
Usage
import { AzureImageGenServiceREST } from "@pipedog/azure/image";
const imageGen = new AzureImageGenServiceREST({
apiKey: process.env.AZURE_OPENAI_API_KEY ?? "",
// The resource endpoint, with its trailing slash.
endpoint: "https://my-resource.openai.azure.com/",
settings: new AzureImageGenServiceREST.Settings({ imageSize: "1024x1024" }),
});Notes
- The request is
POST {endpoint}openai/images/generations:submit?api-version=...with the key in theapi-keyheader and{ prompt, n: 1, size }as the body. The job's status is read from theoperation-locationURL the submission returns. - Polling gives up after 119 attempts, about two minutes, with an
ErrorFrame("Image generation timed out"). A finished job without an image URL gives"Image generation failed". - A submission without an
operation-locationheader (a 429, for example) throws, as upstream. apiVersiondefaults to"2023-06-01-preview", the version this asynchronous API was published under.
Runtime notes
| Runtime | Works | What it needs |
|---|---|---|
| Bun | ✅ yes | Nothing. |
| Node.js | ✅ yes | Nothing. |
| Deno | ✅ yes | Nothing. |
| Cloudflare Workers | ✅ yes | Nothing. |
Generated from pipecat.runtimes and pipecat.compat in packages/azure/package.json: ✅ means the compat smoke test passes on that runtime.
- All requests go through
fetch(the global one, or thefetchoption), which replaces upstream's requiredaiohttp_session. The service works on Bun, Node, Deno and Cloudflare Workers. - The image is decoded to RGB with
decodePngToRgbfrom@pipedog/openai/image, a pure JS PNG decoder, and the frame'sformatis always"RGB". Upstream decodes with Pillow and reports Pillow's mode. PassdecodeImageto decode other formats. - The deprecated
imageSizeandmodelconstructor options are not ported. Usesettings.
pipedog is an unofficial community TypeScript port of Pipecat. It is not affiliated with or endorsed by Daily or the Pipecat project.
Portions adapted from the Pipecat documentation, Copyright (c) 2024–2025 Daily, BSD-2-Clause (see apps/docs/LICENSE-pipecat-docs).