# 5. Save the resulting file
img_path_mask_alpha = "mask_alpha.png"
with open(img_path_mask_alpha, "wb") as f:
    f.write(mask_bytes)
```

### Input fidelity

The `gpt-image-1` model supports high input fidelity, which allows you to better
preserve details from the input images in the output. This is especially useful
when using images that contain elements like faces or logos that require
accurate preservation in the generated image.

You can provide multiple input images that will all be preserved with high
fidelity, but keep in mind that the first image will be preserved with richer
textures and finer details, so if you include elements such as faces, consider
placing them in the first image.

To enable high input fidelity, set the `input_fidelity` parameter to `high`. The
default value is `low`.

Responses API

```javascript
import fs from "fs";
import OpenAI from "openai";

const openai = new OpenAI();
const response = await openai.responses.create({
  model: "gpt-4.1",
  input: [
    {
      role: "user",
      content: [
        {
          type: "input_text",
          text: "Add the logo to the woman's top, as if stamped into the fabric.",
        },
        {
          type: "input_image",
          image_url:
            "https://cdn.openai.com/API/docs/images/woman_futuristic.jpg",
        },
        {
          type: "input_image",
          image_url: "https://cdn.openai.com/API/docs/images/brain_logo.png",
        },
      ],
    },
  ],
  tools: [{ type: "image_generation", input_fidelity: "high" }],
});

// Extract the edited image
const imageBase64 = response.output.find(
  (o) => o.type === "image_generation_call",
)?.result;

if (imageBase64) {
  const imageBuffer = Buffer.from(imageBase64, "base64");
  fs.writeFileSync("woman_with_logo.png", imageBuffer);
}
```

```python
from openai import OpenAI
import base64

client = OpenAI()

response = client.responses.create(
    model="gpt-4.1",
    input=[
        {
            "role": "user",
            "content": [
                {"type": "input_text", "text": "Add the logo to the woman's top, as if stamped into the fabric."},
                {
                    "type": "input_image",
                    "image_url": "https://cdn.openai.com/API/docs/images/woman_futuristic.jpg",
                },
                {
                    "type": "input_image",
                    "image_url": "https://cdn.openai.com/API/docs/images/brain_logo.png",
                },
            ],
        }
    ],
    tools=[{"type": "image_generation", "input_fidelity": "high"}],
)