ImageResponse class

A response from the images API.

Contains the generated image(s) as URLs or base64-encoded data. For GPT image models (e.g. gpt-image-2), also includes token-based pricing info in usage and request-echo metadata (background, outputFormat, quality, size). These extra fields are null for DALL-E responses.

Example

final response = await client.images.generate(request);

for (final image in response.data) {
  if (image.b64Json case final b64?) {
    final bytes = base64Decode(b64);
    // …save bytes to disk
  }
}
print('Total tokens: ${response.usage?.totalTokens}');
Annotations
  • @immutable

Constructors

ImageResponse({required int created, required List<GeneratedImage> data, ImageBackground? background, ImageOutputFormat? outputFormat, ImageQuality? quality, ImageSize? size, ImagesUsage? usage})
Creates an ImageResponse.
const
ImageResponse.fromJson(Map<String, dynamic> json)
Creates an ImageResponse from JSON.
factory

Properties

background ImageBackground?
Background used (GPT image models only).
final
created int
The Unix timestamp when the images were created.
final
data List<GeneratedImage>
The list of generated images.
final
first GeneratedImage
Gets the first generated image.
no setter
firstBase64 String?
Gets the base64 data of the first image.
no setter
firstUrl String?
Gets the URL of the first image.
no setter
hashCode int
The hash code for this object.
no setteroverride
outputFormat ImageOutputFormat?
Output format used (GPT image models only).
final
quality ImageQuality?
Quality used (GPT image models only).
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
size ImageSize?
Size used (GPT image models only).
final
usage ImagesUsage?
Token usage (GPT image models only).
final

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toJson() Map<String, dynamic>
Converts to JSON.
toString() String
A string representation of this object.
override

Operators

operator ==(Object other) bool
The equality operator.
override