OpenAI
Image generation with OpenAIImageGenService, using OpenAI's GPT Image models.
Overview
OpenAIImageGenService: turns eachTextFrameit receives into a prompt for OpenAI's Images API (images.generate) and pushes the result as aURLImageRawFrameof RGB pixels.
Upstream page
Pipecat's documentation for the same service.
Source
packages/openai/src/image.ts.
OpenAI docs
Image models, sizes and quality.
Installation
bun add @pipedog/openaiimport { OpenAIImageGenService } from "@pipedog/openai/image";Prerequisites
- An OpenAI account and an API key from the OpenAI dashboard.
- Pass the key as
apiKey(required). The examples read it fromOPENAI_API_KEY.
OpenAIImageGenService
Configuration
Prop
Type
Settings
Runtime-updatable settings, passed as settings: new OpenAIImageGenService.Settings({...})
(OpenAIImageGenSettings). Any setting you leave out keeps the default below.
| Setting | Type | Default | Description |
|---|---|---|---|
model | string | "gpt-image-2.5-flare" | Image model. |
imageSize | OpenAIImageSize | string | null | null | "auto", "1024x1024", "1536x1024", "1024x1536", ... null leaves it to OpenAI. |
quality | OpenAIImageQuality | string | null | null | "auto", "low", "medium", "high", ... Lower is faster. null lets OpenAI pick. |
moderation | OpenAIImageModeration | string | null | null | Content-moderation level for generated images: "low" for less restrictive filtering, or "auto". null leaves OpenAI's default. |
Usage
import { OpenAIImageGenService } from "@pipedog/openai/image";
const imageGen = new OpenAIImageGenService({
apiKey: process.env.OPENAI_API_KEY ?? "",
settings: new OpenAIImageGenService.Settings({
model: "gpt-image-2.5-flare",
imageSize: "1024x1024",
quality: "low",
}),
});Notes
- Each
TextFrameis pushed on downstream, then used as the prompt. One image is generated per prompt (n: 1). - The GPT Image models return the image inline (base64). When the response carries a URL
instead, the image is downloaded with
fetch(the global one, or thefetchoption) and the URL is set on the frame. - The image is decoded to RGB (alpha dropped) with
decodePngToRgb, a pure JS PNG decoder. PassdecodeImageto decode other formats. - A response with no image data produces an
ErrorFrame. - As upstream, the constructor passes only
settingsto the base service, so the inherited frame processor options (such asname) have no effect.
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/openai/package.json: ✅ means the compat smoke test passes on that runtime.
- The client is the
openaiJS SDK overfetch, and decoding is pure JS (fast-png), so it works on Bun, Node, Deno and Cloudflare Workers. - The
fetchoption replaces upstream's requiredaiohttp_session.decodeImageis a pipedog addition; upstream decodes with Pillow. - The deprecated
imageSizeandmodelconstructor options are not ported. Usesettings. - For Azure OpenAI image generation, see
AzureImageGenServiceREST.
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).