spring-projects / spring-projects/spring-ai
Cannot Set Image detail Option (e.g., "low") When Using Multimodal Input in Spring AI
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 9.5k
- Forks
- 2.9k
- Avg merge
- 1d 7h
- Merged PRs (30d)
- 6
Description
Expected Behavior
When creating a UserMessage with an image URL using Media, I should be able to specify the image detail option ("low", "high", "auto"), which is supported by the OpenAI API for vision models like GPT-4o.
For example, I expect something like:
UserMessage.builder()
.text("What do you see?")
.media(List.of(Media.builder()
.mimeType(MimeTypeUtils.IMAGE_PNG)
.data(URI.create("https://example.com/image.png"))
.detail("low") // <== This field doesn't currently exist
.build()))
.build();
The resulting request payload should include:
{
"type": "image_url",
"image_url": {
"url": "https://example.com/image.png",
"detail": "low"
}
}
Current Behavior
Currently, the Media abstraction does not support setting a detail value. Even though the internal MediaContent.ImageUrl class accepts a detail parameter, the mapToMediaContent(...) function in OpenAiChatModel uses a constructor that sets it to null.
As a result, it is not possible to control image quality when using image URLs. This is a problem when optimizing for latency or when handling large/multiple images.
Context
I'am building a system using GPT-4o's multimodal capabilities and leveraging Spring AI for easier integration. When sending multiple or large images via URL, being able to reduce the image detail to "low" would provide performance improvements.
However, without this feature:
- The full-size image is always sent
- We experience longer response times from the LLM
- We have no control over performance trade-offs
I am considering customizing OpenAiChatModel and overriding mapToMediaContent to manually inject the detail value, but this workaround adds unnecessary complexity.
If this feature could be added — either by extending the Media class or by offering a more flexible mapping hook — I'd be very happy to contribute.
Thanks again for your great work!
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with OpenAiChatModel.mapToMediaContent(...) and inspect how Media is converted to MediaContent.ImageUrl; the issue identifies that the current constructor receives a null detail value. Trace the Media abstraction and its builder, then verify that a configured detail value appears in the image_url request payload for multimodal input.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- ai
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100