localVarFormParams.getHeaders is not function when using openai.createImageEdit()

this is my function

 const generatedDalleImage = async () => {
    
    await openai.createImageEdit(
      selectedImage,
      selectedMaskImage,
      "human face",
      1,
      "1024x1024"
    ).then((response) => {
      console.log(response);
      console.log(typeof localVarFormParams);
      setGeneratedImage(response.data.data[0].url)
    }).catch(err => {
      console.log(err);
    });


  }

i am getting this error
localVarFormParams.getHeaders is not function when using openai.createImageEdit()

i am really stuck in this one so any help is appreciated

i’ve been having the same issues. i’ve tried three ways of writing the requests to this endpoint (openai npm package, js fetch, and jquery), and i haven’t been able to find the correct request format. this was the error that blocked me when using the npm package, but i didn’t get any closer with the other 2 formats.

let me know if you’re ever able to figure it out!

can you please share your code that you tired with js fetch, and jquery maybe i can get something from it

@ahmedanka67

fetch-

export const fetchEdits = async (image, prompt) => {
  const mask = await getBase64("mask");
  const imageData = dataType64toFile(image, "image.png");
  const maskData = dataType64toFile(mask, "mask.png");
  const imageFile: any = imageData;
  const maskFile: any = maskData;
  const requestOptions = {
    method: "POST",
    headers: {
      "Content-Type": "multipart/form-data",
      Authorization: "Bearer " + configuration.apiKey,
    },
    body: JSON.stringify({
      image: imageFile,
      mask: maskFile,
      prompt: prompt,
      n: 1,
      size: "256x256",
    }),
  };
  const response = (
    await fetch("https://api.openai.com/v1/images/edits", requestOptions)
  ).json();
  return (await response).data.data[0]["url"];
};

jquery-

export const fetchEdits = async (image, prompt) => {
  const mask = await getBase64("mask");
  const imageData = dataType64toFile(image, "image.png");
  const maskData = dataType64toFile(mask, "mask.png");
  const imageFile: any = imageData;
  const maskFile: any = maskData;
  const data = JSON.stringify({
    image: imageFile,
    mask: maskFile,
    prompt: prompt,
    n: 1,
    size: "256x256",
  });
  $.ajax({
    url: "https://api.openai.com/v1/images/edits",
    method: "POST",
    dataType: "json",
    crossDomain: true,
    contentType: "multipart/form-data; charset=utf-8",
    data: JSON.stringify(data),
    cache: false,
    beforeSend: function (xhr) {
      /* Authorization header */
      xhr.setRequestHeader("Authorization", "Bearer " + configuration.apiKey);
    },
  });
};

the problem is i don’t know what the headers are supposed to be. i didn’t get any closer with these two methods than the openai npm package, because all i can get is ‘400 bad request’ error. but maybe you can figure it out :slight_smile:

@yanson

looks like you have to do it with node.js
i create a nodejs server and applied the code there it worked fine
this is a helpful tutorial that i followed since am not experienced with node