#Send image in api request problem

1 messages · Page 1 of 1 (latest)

thorny kraken
#

I have problem to send image on api request. When i try to send without image it works.

i am encode picture like this:
if (imageInput.files && imageInput.files[0]) {
var reader = new FileReader();
reader.onload = function(e) {
imageBase64 = e.target.result.split(',')[1];
console.log(imageBase64);
sendRequest(question, imageBase64);
};

and when i send run receive this.
code: "invalid_value"
message: "Invalid 'thread.messages[0].content[1].image_url.url'. Expected a valid URL, but got a value with an invalid format."
param:"thread.messages[0].content[1].image_url.url"
type: "invalid_request_error"

i am send with fetch in javascript:
fetch('https://api.openai.com/v1/threads/runs', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': "Bearer ...",
'OpenAI-Beta': 'assistants=v2'
},
body: JSON.stringify({
assistant_id: "...",
thread: {
messages: [
{
role: "user",
content: [
{ type: "text", text: question },
imageBase64 ? { type: "image_url", image_url: { url: "data:image/jpeg;base64," + imageBase64 } } : null
].filter(Boolean)
}
]
}
})
})

#

Send image in api request problem

exotic crown
thorny kraken
thorny kraken