When I call the API with a text only prompt, things work fine. However, when I try to add an image to the prompt as well I’m getting a 400 error. I’ve looked at the spec and everything looks correct. Maybe another set of eyes can see what I’m doing wrong here.
Here is the code:
Message message = new Message();
message.setRole("user");
Content contentText = new Content();
contentText.setType("text");
contentText.setText(promptText);
// Validate and trim the base64 string if necessary
if (base64ImageStr != null && !base64ImageStr.isEmpty()) {
base64ImageStr = base64ImageStr.replace("\n", "").replace("\r", "");
}
Content contentImage = new Content();
contentImage.setType("image");
contentImage.setImage_url("data:image/jpeg;base64," + base64ImageStr);
message.setContent(List.of(contentText, contentImage));
request.setMessages(List.of(message));