Gpt-image-1 b_64json response incomplete or corrupted

I am testing the new gpt-image-1 API to do simple editing, this is my code:

// Always add product image
  const productImageResponse = await fetch(payload.productImageUrl);
  const productImageBlob = await productImageResponse.blob();
  const productImageFile = new File([productImageBlob], "product-image.png", { type: productImageBlob.type });
  
  logger.log("Product image file:", productImageFile);

  // Generate the image using OpenAI with gpt-image-1 model
  const result = await openai.images.edit({
    model: "gpt-image-1",
    prompt: payload.prompt,
    n: 1,
    size: "1024x1024",
    image: productImageFile,
  });

it runs well, but the response’s b64_json seems to be either incomplete or something as I cant even decode it to view the image, this is the response:

{
“created”: 1745519700,
“data”: [
{
“b64_json”: “iVBORw0KGgoAAAANSUhEUgAABAAAAAQACAIAAADwf7zUAAFTUGNhQlgAAVNQanVtYgAAAB5qdW1kYzJwYQARABCAAACqADibcQNjMnBhAAAANxNqdW1iAAAAR2p1bWRjMm1hABEAEIAAAKoAOJtxA3VybjpjMnBhOmViZjE3NGRhLTk1YmYtNDlkZC1hODYwLTQwNzM5M2IxZTZjNgAAAAHhanVtYgAAAClqdW1kYzJhcwARABCAAACqADibcQNjMnBhLmFzc2VydGlvbnMAAAABBWp1bWIAAAApanVtZGNib3IAEQAQgAAAqgA4m3EDYzJwYS5hY3Rpb25zLnYyAAAAANRjYm9yoWdhY3Rpb25zgqNmYWN0aW9ubGMycGEuY3JlYXRlZG1zb2Z0d2FyZUFnZW50v2RuYW1lZkdQVC00b/9xZGlnaXRhbFNvdXJjZVR5cGV4Rmh0dHA6Ly9jdi5pcHRjLm9yZy9uZXdzY29kZXMvZGlnaXRhbHNvdXJjZXR5cGUvdHJhaW5lZEFsZ29yaXRobWljTWVkaWGiZmFjdGlvbm5jMnBhLmNvbnZlcnRlZG1zb2Z0d2FyZUFnZW50v2RuYW1lak9wZW5BSSBBUEn/AAAAq2p1bWIAAAAoanVtZGNib3IAEQAQgAAAqgA4m3EDYzJwYS5oYXNoLmRhdGEAAAAAe2Nib3KlamV4Y2x1c2lvbnOBomVzdGFydBghZmxlbmd0aBk3RWRuYW1lbmp1bWJmIG1hbmlmZXN0Y2FsZ2ZzaGEyNTZkaGFzaFggrfwBIKSW4wQQvItIxyypspV7Nb85MM3QTg6N7B0ij1tjcGFkSAAAAAAAAAAAAAAB5mp1bWIAAAAnanVtZGMyY2wAEQAQgAAAqgA4m3EDYzJwYS5jbGFpbS52MgAAAAG3Y2JvcqZqaW5zdGFuY2VJRHgseG1wOmlpZDo3ZDg3YzRiZC1iNjJmLTRiYmYtOTBiMi04MjBkNzcyYjUzOGR0Y2xhaW1fZ2VuZXJhdG9yX2lu”
}
],
“usage”: {
“input_tokens”: 296,
“total_tokens”: 4456,
“output_tokens”: 4160,
“input_tokens_details”: {
“text_tokens”: 102,
“image_tokens”: 194
}
}
}

Welcome to the community.

Is it giving an error when you try to decode? All requests come back the same?

1 Like

Yep, I’ve tried both on the image edit and generate image

Okay. It’s working here…

How are you decoding it?

1 Like

const result = await openai.images.edit({
model: “gpt-image-1”,
prompt: payload.prompt,
n: 1,
size: “1024x1024”,
image: productImageFile,

  // Get the image data
  const imageBase64 = result.data[0].b64_json;

   const { data, error } = await supabase
.storage
.from("product-images")
.upload(`${productId}/${fileName}`, Buffer.from(imageBase64, "base64"), {
    contentType: "image/png",
    upsert: false
  });

ahh, may I know how are u decoding it?

I’ve also tried throwing the b64_json data into a decoder online Base64 to Image | Base64 Decode | Base64 Converter | Base64,

The b64_json also seems a little bit short to be an image, no?

Sorry in advance for newbie question

Aight, it’s solved, my bad, it was due to other technology that trigger the function

1 Like