Bug description When invoking the OpenAI API for generating an image, irrespective of the model (dall-e-3 or dall-e-2), the size attribute in the request body is optional and defaults to the string '1024x1024'.
However, when using Spring AI to generate an image, the below exception is encountered when the key spring.ai.openai.image.options.size
is not configured:
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"
}
}
The parameter is being set to a string nullxnull
instead of null
which is causing the OpenAI API to return a 400 Bad request error.
Environment Using the Spring AI version : 1.0.0-M4 with Java 23
Expected behavior
The image should be generated without having to explicitly set a value for the key spring.ai.openai.image.options.size
.
Steps to reproduce and Minimal Complete Reproducible example Reproducible example can be found here. Execute the below command to get the exception:
OPENAI_API_KEY="api-key-goes-here" mvn test -Dtest=ImageGeneratorLiveTest
Comment From: timosalm
Duplicate of #1788
Comment From: hardikSinghBehl
Thanks @timosalm, I'll close this one.