Skip to main content
The OpenAI Responses provider exposes an image generation tool that allows you to generate images on the provider.

Enable Image Generation

The image generation tool can be enabled via the chatModelOptions parameter of the Agent constructor:
final agent = Agent(
  'openai-responses',
  chatModelOptions: const OpenAIResponsesChatModelOptions(
    serverSideTools: {OpenAIServerSideTool.imageGeneration},
    imageGenerationConfig: ImageGenerationConfig(
      partialImages: 3,
      quality: ImageGenerationQuality.low,
      size: ImageGenerationSize.square256,
    ),
  ),
);
ImageGenerationConfig lets you request progressive previews (partialImages), choose the quality profile, and select a size. Omit these values to fall back to the provider defaults.

Streaming Previews

Partial renders arrive as base64-encoded bytes inside metadata events:
void handleMetadata(Map<String, dynamic> metadata) {
  final events = metadata['image_generation'] as List?;
  if (events == null) return;

  for (final event in events) {
    final preview = event['partial_image_b64'] as String?;
    if (preview != null) {
      // import 'dart:convert' to use base64Decode
      final bytes = base64Decode(preview);
      savePreview(bytes, event['partial_image_index'] as int);
    }
  }
}
Each event also includes the tool stage (response.image_generation_call.*) so you can display progress indicators while the image renders.

Final Image

Completed images are attached to the assistant message as DataPart instances with an image/* MIME type:
final result = await agent.send(prompt);
for (final msg in result.messages) {
  for (final part in msg.parts) {
    if (part is DataPart && part.mimeType.startsWith('image/')) {
      saveFinalImage(part.bytes);
    }
  }
}
No extra download step is required; Dartantic fetches the file from the provider and hands you the bytes.

Example