Create Image Edit in Node.js library - watch out for the order of positional arguments

Seen there have been quite a few people struggling with the create image edit method when including a mask image in their api call. I was getting a 400 Bad Request error for a few hours yesterday, and it took me a while to figure out, but the API Reference documents the wrong order for createImageEdit’s positional arguments. The positional order inside OpenAI’s Node.js library is (image → prompt → mask), but the documentation uses (image → mask → prompt)…

Create image edit in API reference:

const response = await openai.createImageEdit(
  fs.createReadStream("otter.png"), # image
  fs.createReadStream("mask.png"), # mask
  "A cute baby sea otter wearing a beret", # prompt
  ...
);

But… the createImageEdit method in ‘openai’ node_module (openai/dist/api.js line 383) reads:

createImageEdit: (image, prompt, mask, n, size, responseFormat, user, options = {}) => __awaiter(this, void 0, void 0, function* () {

Super easy fix - just swap the position of ‘mask’ and ‘prompt’ inside your calls:

# Change this...
const response = await openai.createImageEdit(
  fs.createReadStream("otter.png"),
  fs.createReadStream("mask.png"),
  "A cute baby sea otter wearing a beret",
  ...
);

# to this...
const response = await openai.createImageEdit(
  fs.createReadStream("otter.png"),
  "A cute baby sea otter wearing a beret",
  fs.createReadStream("mask.png"),
  ...
);

This inconsistency shouldn’t exist in other libraries as Node.js seems to be the only one that uses positional arguments for this method.

Hopefully this helps save people some time.

2 Likes