liveBook · Manning

ImageOptions

As explained in Spring AI in Action

ImageOptions is a Spring AI options object that specifies parameters controlling image generation, such as dimensions and response format.

ImageOptions is Spring AI’s request-configuration object for image generation. It separates image parameters from application logic and lets an ImageModel request specify dimensions, response format, style, model, and image count. section 8.3 section 8.3.1

Configure the generated image with:

  • width(Integer) and height(Integer), which are required at minimum and commonly produce a 1024 × 1024 image. section 8.3
  • responseFormat(String), choosing url for a retrievable image URL or b64_json for Base64-encoded image data. section 8.3
  • style(String), selecting vivid or natural output; natural produces a more photorealistic result. section 8.3.1
  • model(String) and n(Integer), selecting the model and number of generated images. section 8.3.1
  • Provider-specific options such as OpenAI quality and user, or Azure OpenAI deploymentName. section 8.3.1

Configure a high-definition natural image

ImageOptions options = OpenAiImageOptions.builder() .height(1024) .width(1024) .responseFormat(format) .style("natural") .quality("hd") .build(); The same values can become application defaults through properties such as spring.ai.openai.image.options.height, width, style, and quality. An image service can then pass these options with an ImagePrompt to an ImageModel, returning either a URL or image bytes. section 8.3.1 section 8.3

Table 8.1 ImageOptionsBuilder methods for setting image options
Method
Description
height(Integer)
The height of the image
model(String)
The name of the model to use. Either dall-e-2 or dall-e-3. Default: dall-e-3.
N(Integer)
The number of images to generate
responseFormat(String)
The format of the returned image. Either url or b64_json. Default: url.
style(String)
The image style. Either vivid or natural.
width(Integer)
The width of the image

Browse the ImageOptionsBuilder method table for dimensions, model selection, image count, response format, and style. section 8.3.1

How Spring AI in Action covers it

How deep it goes
Defines builder methods, configuration-property defaults, response formats, and provider-specific extensions without detailing provider HTTP internals.
Examples
Demonstrates 1024 × 1024 burger images returned as URLs or bytes, including natural style and high-definition quality.
What it assumes
Assumes a Spring AI image service using ImageModel and ImagePrompt, while exposing basic dimensions and formats through examples.
What you can do after
Build it from scratch by constructing ImageOptions in Java or setting equivalent Spring configuration defaults.
How it connects
Connects ImageModel, ImagePrompt, image generation, configuration properties, OpenAI, and Azure OpenAI.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Spring AI in Action. The section links point to the parts of the book it draws on.