Provided is the section of my typescript code. s3ImageURL and resolution variables have valid values.
s3ImageURL looks like https://s3.ap-northeast-2.amazonaws.com/bucketName/fileName
resolution - “auto” | “low” | “high”
const response = await openai.chat.completions.create({
model: 'gpt-4-turbo',
messages: [
{
role: 'user',
content: [
{
type: 'text',
text: 'What’s in this image?'
},
{
type: 'image_url',
image_url: {
url: s3ImageURL,
detail: resolution
}
}
]
}
],
max_tokens: maxTokens
});
I am using gpt-4-turbo to describe an image stored in AWS s3 bucket (public). I pass the correct s3 URL but the API returns an error saying
Error: 400 Invalid image URL: 'messages[0].content[1].image_url.url'. Expected a base64-encoded data URL with an image MIME type (e.g. 'data:image/png;base64,aW1nIGJ5dGVzIGhlcmU='), but got a value without the 'data:' prefix.
I don’t know why it keeps recognizing the image URL as encoded data. Is there any character in the URL that I need to escape? I do not want to download the image locally and convert it to base64 data.
Additional context:
When I run the above section of code in a function from a cmd, it works fine. It successfully describes the image from that imageURL. However, when I call the same function in the express router function, it keeps recognizing imageURL as base64-encoded data URL for some reason and fails.