-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Invalid file 'image': unsupported mimetype ('application/octet-stream'). Supported file formats are 'image/png'. #1468
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
getting the same error |
Same error here with: Node version Openai |
Getting the same error |
Same error: |
Hi, |
same issue |
Hi, |
Seeing this across both go + node.js clients. Seems like a regression on OpenAI's side |
same issue |
Having the same issue on my end. |
Getting the same issue with this:
Might have to resort to CURL requests for now. |
Same error. |
I am facing the same issue. |
temporary workaround if you are looking for immediate fix: import { fileFromPath } from 'formdata-node/file-from-path';
const file = await fileFromPath(cachedFile, { type: 'image/jpeg' });
const response = await this.client.images.edit({
model: 'gpt-image-1',
prompt,
n: 1,
size: '1024x1024',
image: file,
}); upd: I would recommend method below since it doesnt require any external library #1468 (comment) |
This worked like a charm. Thank you very much! |
My files are on a remote host not locally |
you can download file from remote host first using axios:
and after that you can pass |
Sorry I didn't make myself clear, but in my case I can't save files locally. Thank for your answer.
but not work. |
Here is my solution based on the official documentation: import OpenAI, { toFile } from "openai";
import { createReadStream } from 'fs';
import { resolve } from 'path';
const prompt = 'something';
const result = await this.openAI.images.edit({
model: 'gpt-image-1',
image: await toFile(
createReadStream(resolve(__dirname, './test/sample.png')),
null,
{ type: 'image/png' },
),
prompt,
n: 1,
size: '1024x1024',
// response_format: 'b64_json',
});
console.log(result.data[0].b64_json); |
For people who have the same issue and want to send user uploaded images images (that dont live on the file system of your server) to the openai editing enpoint you can use following utilities from node-fetch: import { Blob, File } from "node-fetch"
// referenceImages: { dataurl: string; mimeType: string }[]
const image: Uploadable[] = input.referenceImages.map((aImg, aIndex) => {
return new File([dataURLtoBlob(aImg.dataurl)], `reference-image-${aIndex}`, {
type: aImg.mimeType,
})
})
client_openAISdk.images.edit({
model: "gpt-image-1",
prompt: input.prompt,
// @ts-ignore
size: input.size,
user: userIdentifier,
quality: input.quality,
n: input.countImagesToGenerate,
background: input.enableTransparency ? "transparent" : "opaque",
moderation: "low",
image: image,
})
function dataURLtoBlob(dataurl: string) {
// DataURL parsen
const arr = dataurl.split(",")
const mimeMatch = arr[0]!.match(/:(.*?);/)
const mime = mimeMatch ? mimeMatch[1] : ""
const bstr = atob(arr[1]!)
let n = bstr.length
const u8arr = new Uint8Array(n)
while (n--) {
u8arr[n] = bstr.charCodeAt(n)
}
return new Blob([u8arr], { type: mime })
} |
Confirm this is a Node library issue and not an underlying OpenAI API issue
Describe the bug
Since yesterday, a call to the "openai.images.edit" API throws an error:
BadRequestError: 400 Invalid file 'image': unsupported mimetype ('application/octet-stream'). Supported file formats are 'image/png'.
The same API call worked for that last year without this error.
To Reproduce
Code snippets
OS
macOS 15.4
Node version
Node v22.14.0
Library version
openai 4.95.0
The text was updated successfully, but these errors were encountered: