Skip to main content

Image generation

The selected image service is ctx.imageGeneration. It returns self-contained Blob objects rather than remote URLs.

const result = await ctx.imageGeneration.generate('A lighthouse in a winter storm', {
count: 1,
references: [{data: portrait, description: 'Preserve this character'}],
signal,
})

const [{data, mediaType, revisedPrompt}] = result.images

count must be a positive integer. References contain an image blob and an optional provider-neutral description. A provider may impose its own count and input limits.

OpenAI-compatible options​

OptionMeaning
sizeProvider-supported size such as 1024x1024
qualityProvider-supported quality such as auto, low, medium, or high
styleProvider-specific style such as vivid or natural
backgroundauto, opaque, or transparent
outputFormatpng, jpeg, or webp
outputCompressionInteger from 0 to 100
userOptional end-user identifier

Requests without references call POST /images/generations with JSON. Requests with references call POST /images/edits as multipart form data. Base64 responses become blobs directly; URL responses are downloaded before the call completes.