Bug description The image generation fails if image size not set e.g. via spring.ai.image.options.openai.size with (Azure) OpenAI with the following error.

org.springframework.ai.retry.NonTransientAiException: 400 - {
  "error": {
    "code": null,
    "message": "'nullxnull' is not one of ['256x256', '512x512', '1024x1024', '1024x1792', '1792x1024'] - 'size'",
    "param": null,
    "type": "invalid_request_error"
  }
}

It can be fixed by replacing lines https://github.com/spring-projects/spring-ai/blob/e5410d7e8da170c546a79852c2234c2be5a80b97/models/spring-ai-openai/src/main/java/org/springframework/ai/openai/OpenAiImageOptions.java#L156 and https://github.com/spring-projects/spring-ai/blob/e5410d7e8da170c546a79852c2234c2be5a80b97/models/spring-ai-openai/src/main/java/org/springframework/ai/openai/OpenAiImageOptions.java#L177 with this.size = this.getSize();

Has to be also fixed for AzureOpenAiImageOptions.

Environment Spring AI M3/M4, OpenAi, Dall-E 3

Steps to reproduce Use (Azure) OpenAI and Dall-E 3, and execute an image generation request and don't set spring.ai.image.options.openai.size.

Expected behavior Image generation should work without setting spring.ai.image.options.openai.size.

Comment From: dennysfredericci

According to OpenAI documentation, the size can be set to null; in that case, it will fall back to 1024x1024.

However, variations like nullx1024 or 1024xnull are considered invalid dimensions.

I will fix it this week.

Comment From: dennysfredericci

Issue reproduced using spring-ai 1.0.0-M4.

@SpringBootTest
class ImageGenerationTest {

    @Autowired
    private ImageModel imageModel;

    @Test
    void shouldReturnImageUrl() {
        ImagePrompt imagePrompt = new ImagePrompt("A cartoon depicting a parrot on the shoulder of a pirate.");
        ImageResponse imageResponse = imageModel.call(imagePrompt);
        Image image = imageResponse.getResult().getOutput();
        assertThat(image.getUrl()).isNotNull();
    }
}

Exception:

org.springframework.ai.retry.NonTransientAiException: 
400 - {
  "error": {
    "code": null,
    "message": "'nullxnull' is not one of ['256x256', '512x512', '1024x1024', '1024x1792', '1792x1024'] - 'size'",
    "param": null,
    "type": "invalid_request_error"
  }
}

Comment From: dennysfredericci

PR is open at https://github.com/spring-projects/spring-ai/pull/1840

For some reason, I am not able to run all tests locally.

Comment From: henningSaulCM

I only ran into this issue with M4 after including ImageOptions in my ImagePrompt to specify the style (and nothing else).

It looks like OpenAiImageOptions.mergeOptions will lead to setHeight/setWidth being called with null in that case, which will set the size to "nullxnull" which was previously null.

Maybe size should be set to null in setHeight/setWidth when these are called with null? Or maybe get rid of size and setSize() and have getSize() return null if either width or height are null?

Comment From: dennysfredericci

I only ran into this issue with M4 after including ImageOptions in my ImagePrompt to specify the style (and nothing else).

It looks like OpenAiImageOptions.mergeOptions will lead to setHeight/setWidth being called with null in that case, which will set the size to "nullxnull" which was previously null.

Maybe size should be set to null in setHeight/setWidth when these are called with null? Or maybe get rid of size and setSize() and have getSize() return null if either width or height are null?

Hi @henningSaulCM have you seen the pull request #1840?

The size is only updated when width and height are not null.

Comment From: henningSaulCM

Hi @dennysfredericci,

Hi @henningSaulCM have you seen the pull request https://github.com/spring-projects/spring-ai/pull/1840?

No, sorry, I must have missed it in the comments. Was wondering if the PR should show up in the right hand sidebar in the Github browser UI for the issue under "Development" which currently says "No branches or pull requests".

Anyway, thanks for the fix!

Comment From: dennysfredericci

Hi @dennysfredericci,

Hi @henningSaulCM have you seen the pull request #1840?

No, sorry, I must have missed it in the comments. Was wondering if the PR should show up in the right hand sidebar in the Github browser UI for the issue under "Development" which currently says "No branches or pull requests".

Anyway, thanks for the fix!

Ok, and I guess the maintainers could link the PR with this issue.

Comment From: dennysfredericci

@markpollack since #1840 is closed we can close this issue as well.