Reputation: 107
I am trying to use Open ai's gpt-4-turbo model for image-to-text description generation but I am facing this issue- BadRequestError: 400 Invalid content type. image_url is only supported by certain models.
app.post('/analyze-image', cors(corsOptions), async (req, res) => {
try {
const { image } = req.body;
const base64Image = await convertBufferToBase64(image);
// Pass base64Image to OpenAI API
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", url: `data:image/jpeg;base64,${base64Image}` },
],
},
],
});
res.json(response.choices[0]);
} catch (error) {
console.error(error);
res.status(500).send('Error analyzing image');
}
});
Even I tried with a url ,but same error was getting for the Url how to fix this ?
Upvotes: 3
Views: 3976
Reputation: 275
You may try this:
{
type: "image_url",
image_url: { url: encodeURI(image) }
}
Upvotes: 0
Reputation: 1
GPT official documentation says it support image url as input. I used image url first and got an error that "expected object but got a string". Then I wrapped up image url as "url":"xxx' and then got this error. I use gpt4-o
openai.BadRequestError: Error code: 400 - {'error': {'message': 'Invalid image.', 'type': 'invalid_request_error', 'param': None, 'code': 'invalid_image'}}
https://platform.openai.com/docs/api-reference/chat/create
Upvotes: -1