Acording to the openai documentation i should be able to upload images as base64 encoded strings. but when i do it gives me this error message.
Error code: 400 - {'error': {'message': 'Invalid image.', 'type': 'invalid_request_error', 'param': None, 'code': 'invalid_image'}}
heres my code for reference:
def proofread_text(image: str):
print(image)
response = client.chat.completions.create(
model="gpt-4o",
messages=[
{
"role": "user",
"content": [
{"type": "text", "text": "Proofread this text:"},
{
"type": "image_url",
"image_url": {
"url": image,
}
},
],
}
],
max_tokens=300,
)
return response.choices[0].message.content
if waiting_for_file.get(user_id):
file_bytes = await client.download_media(message, in_memory=True)
if message.document.mime_type == "application/pdf":
try:
images = convert_from_bytes(file_bytes.getbuffer())
for _, image in enumerate(images):
with io.BytesIO() as output:
image.save(output, format="PNG")
output.seek(0)
base64_image_data = base64.b64encode(output.read()).decode('utf-8')
response = proofread_text(base64_image_data)
await message.reply_text(response)