Im trying to use node.js to accept a base64 encoded image as a parameter and send that to openai api. Im sending a base64 encoded image in postman to the server like this:
{
"base64Image": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAw8AAAEoCAYAAAAe6s1xAAAA..."
}
and here is my code but it returns a 400 Invalid base64 image_url
async function imageToResponse(req, res) {
const base64Image = req.body.base64Image;
try {
const response = await openai.chat.completions.create({
model: 'gpt-4-vision-preview',
messages: [
{ role: 'system', content: "you are a model to help identify everything in this image" },
{ role: 'user', content: [
{
type: "image_url",
image_url:
{
"url": "data:image/png;base64,{base64Image}"
}
}
]
},
],
});
console.log(response.data);
res.status(200).json(response.data);
} catch (error) {
console.error('Error calling the OpenAI API:', error);
res.status(500).json({ error: error.message });
}
}