FG
🤖 AI & LLMsOpenAI

Invalid file 'image': unsupported mimetype ('application/octet-stream'). Supported file formats are 'image/png'.

Freshabout 21 hours ago
Mar 14, 20260 views
Confidence Score70%
70%

Problem

Confirm this is a Node library issue and not an underlying OpenAI API issue - [x] This is an issue with the Node library 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 Provide to images, and set the filenames to patchFn and maskFn, both files are PNGs. Call the openai.images.edit API with the following code Code snippets [code block] OS macOS 15.4 Node version Node v22.14.0 Library version openai 4.95.0

Error Output

error:
`BadRequestError: 400 Invalid file 'image': unsupported mimetype ('application/octet-stream'). Supported file formats are 'image/png'.`

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
Unverified Fix
New Fix – Awaiting Verification

Fix Unsupported Mimetype Error for PNG Files in OpenAI API Call

Medium Risk

The error occurs because the Node library is not correctly identifying the mimetype of the provided PNG files, defaulting to 'application/octet-stream'. This can happen if the files are not being read correctly or if the library has a bug in handling file uploads.

Awaiting Verification

Be the first to verify this fix

  1. 1

    Check File Read Method

    Ensure that the files are being read correctly as buffers or streams. Use the 'fs' module to read the files and confirm their mimetype.

    javascript
    const fs = require('fs');
    const patchFn = fs.readFileSync('path/to/patch.png');
    const maskFn = fs.readFileSync('path/to/mask.png');
  2. 2

    Set Correct Mimetype

    Explicitly set the mimetype when uploading the files to the API. This can help the library recognize the files as PNGs.

    javascript
    const formData = new FormData();
    formData.append('image', patchFn, { filename: 'patch.png', contentType: 'image/png' });
    formData.append('mask', maskFn, { filename: 'mask.png', contentType: 'image/png' });
  3. 3

    Update OpenAI Library

    Ensure you are using the latest version of the OpenAI library, as this may contain bug fixes related to file handling.

    bash
    npm install openai@latest
  4. 4

    Test API Call

    After making the above changes, test the API call again to confirm that the error no longer occurs.

    javascript
    const response = await openai.images.edit({ image: patchFn, mask: maskFn });
    console.log(response);

Validation

Confirm that the API call executes successfully without throwing the 'unsupported mimetype' error. Check the response to ensure it contains the expected output.

Sign in to verify this fix

Environment

Submitted by

AC

Alex Chen

2450 rep

Tags

openaigptllmapibugopenai-api