# gpt-image-2/edit

> OpenAI's GPT Image 2 Edit enables image editing from natural-language instructions with one or more reference images. Ready-to-use REST inference API, best performance, no coldstarts, affordable pricing.

- **Provider:** Openai
- **Category:** image-to-image
- **Price:** $0.0665 (~~$0.0700~~) per run

## Key Features

- Natural-language editing — describe changes in plain English without manual masking or complex tools.
- Reference image support — provide up to 16 input images for context, style transfer, or multi-image composition.
- Flexible aspect ratios — auto-detected from input or manually specified.
- No manual masking required — the model intelligently infers edit regions from your prompt.
- Multiple quality and resolution tiers for cost optimization.
- Seamless blending — edits integrate naturally with the existing image content.

## Parameters

| Parameter | Required | Description |
| --- | --- | --- |
| `prompt` | Yes | Description of the edit to apply. |
| `images` | Yes | 1-16 source image URLs to edit or use as reference. |
| `aspect_ratio` | No | Output aspect ratio (default: auto-detected from input). |
| `resolution` | No | Output resolution: '1k', '2k', or '4k' (default: '1k'). |
| `quality` | No | Quality level: 'low', 'medium' (default), or 'high'. |
| `output_format` | No | Output format: 'png', 'jpeg', or 'webp'. |
| `enable_sync_mode` | No | Enable synchronous response mode. |
| `enable_base64_output` | No | Return base64-encoded image data. |

## How to Use

1. Provide one or more source images (up to 16 URLs).
2. Describe the change you want — be specific about what to add, remove, or modify.
3. Select quality and resolution based on your needs.
4. Generate and download your edited image.

## Code Examples

### Python

```python
import os
import requests

response = requests.post(
    "https://aircube.ai/api/v3/gpt-image-2/edit",
    headers={
        "Authorization": "Bearer " + os.environ["AIRCUBE_API_KEY"],
        "Content-Type": "application/json",
    },
    json={
    "prompt": "Remove the person in the background and replace with a clean beach landscape, maintain warm lighting",
    "images": [
        "https://example.com/beach-photo.jpg"
    ],
    "quality": "medium",
    "resolution": "2k"
},
    timeout=300,
)
data = response.json()

if data["success"]:
    print("ID:", data["data"]["id"], "Status:", data["data"]["status"])
else:
    print("Error:", data["error"]["message"])
```

### Node.js

```javascript
const response = await fetch("https://aircube.ai/api/v3/gpt-image-2/edit", {
  method: "POST",
  headers: {
    "Authorization": "Bearer " + process.env.AIRCUBE_API_KEY,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
  "prompt": "Remove the person in the background and replace with a clean beach landscape, maintain warm lighting",
  "images": [
    "https://example.com/beach-photo.jpg"
  ],
  "quality": "medium",
  "resolution": "2k"
}),
});

const data = await response.json();

if (data.success) {
  console.log("ID:", data.data.id, "Status:", data.data.status);
} else {
  console.error("Error:", data.error.message);
}
```

### cURL

```curl
curl -X POST "https://aircube.ai/api/v3/gpt-image-2/edit" \
  -H "Authorization: Bearer $AIRCUBE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "prompt": "Remove the person in the background and replace with a clean beach landscape, maintain warm lighting",
  "images": [
    "https://example.com/beach-photo.jpg"
  ],
  "quality": "medium",
  "resolution": "2k"
}'
```

### Python (Async)

```python
import os
import time
import requests

# 1. Submit
response = requests.post(
    "https://aircube.ai/api/v3/gpt-image-2/edit",
    headers={
        "Authorization": "Bearer " + os.environ["AIRCUBE_API_KEY"],
        "Content-Type": "application/json",
    },
    json={
    "prompt": "Remove the person in the background and replace with a clean beach landscape, maintain warm lighting",
    "images": [
        "https://example.com/beach-photo.jpg"
    ],
    "quality": "medium",
    "resolution": "2k"
},
    timeout=300,
)
data = response.json()

if not data["success"]:
    print("Error:", data["error"]["message"])
    exit(1)

generation_id = data["data"]["id"]
print(f"Submitted: {generation_id}")

# 2. Poll until completed
while True:
    time.sleep(5)
    r = requests.get(
        f"https://aircube.ai/api/v3/status/{generation_id}",
        headers={"Authorization": "Bearer " + os.environ["AIRCUBE_API_KEY"]},
    )
    result = r.json()["data"]

    if result["status"] == "completed":
        print(result["output_url"])
        break
    elif result["status"] == "failed":
        print("Generation failed")
        break
```

### Node.js (Async)

```javascript
// 1. Submit
const response = await fetch("https://aircube.ai/api/v3/gpt-image-2/edit", {
  method: "POST",
  headers: {
    "Authorization": "Bearer " + process.env.AIRCUBE_API_KEY,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
  "prompt": "Remove the person in the background and replace with a clean beach landscape, maintain warm lighting",
  "images": [
    "https://example.com/beach-photo.jpg"
  ],
  "quality": "medium",
  "resolution": "2k"
}),
});
const data = await response.json();

if (!data.success) {
  console.error("Error:", data.error.message);
  process.exit(1);
}

const generationId = data.data.id;
console.log("Submitted:", generationId);

// 2. Poll until completed
while (true) {
  await new Promise((r) => setTimeout(r, 5000));
  const res = await fetch(
    `https://aircube.ai/api/v3/status/${generationId}`,
    { headers: { "Authorization": "Bearer " + process.env.AIRCUBE_API_KEY } },
  );
  const result = (await res.json()).data;

  if (result.status === "completed") {
    console.log(result.output_url);
    break;
  } else if (result.status === "failed") {
    console.error("Generation failed");
    break;
  }
}
```

### cURL (Async)

```curl
# 1. Submit
RESPONSE=$(curl -s -X POST "https://aircube.ai/api/v3/gpt-image-2/edit" \
  -H "Authorization: Bearer $AIRCUBE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "prompt": "Remove the person in the background and replace with a clean beach landscape, maintain warm lighting",
  "images": [
    "https://example.com/beach-photo.jpg"
  ],
  "quality": "medium",
  "resolution": "2k"
}')

ID=$(echo "$RESPONSE" | jq -r '.data.id')
echo "Submitted: $ID"

# 2. Poll until completed
while true; do
  sleep 5
  STATUS_RES=$(curl -s "https://aircube.ai/api/v3/status/$ID" \
    -H "Authorization: Bearer $AIRCUBE_API_KEY")
  STATUS=$(echo "$STATUS_RES" | jq -r '.data.status')

  if [ "$STATUS" = "completed" ]; then
    echo "$STATUS_RES" | jq -r '.data.output_url'
    break
  elif [ "$STATUS" = "failed" ]; then
    echo "Generation failed"; break
  fi
done
```

## Pricing

| Resolution | Duration | Cost |
| --- | --- | --- |
| 1k | low quality | $0.02 |
| 2k | low quality | $0.03 |
| 4k | low quality | $0.04 |
| 1k | medium quality | $0.07 |
| 2k | medium quality | $0.11 |
| 4k | medium quality | $0.19 |
| 1k | high quality | $0.23 |
| 2k | high quality | $0.41 |
| 4k | high quality | $0.73 |

### Billing Rules

- Pricing varies by quality x resolution combination.
- Low quality: $0.02 (1k), $0.03 (2k), $0.04 (4k).
- Medium quality: $0.07 (1k), $0.11 (2k), $0.19 (4k).
- High quality: $0.23 (1k), $0.41 (2k), $0.73 (4k).
- Failed generations are not charged.

## Best Use Cases

- Product photo enhancement — improve lighting, background, and presentation of product images.
- Creative retouching — modify elements, add effects, or change visual style.
- Marketing asset adaptation — adjust images for different campaigns, audiences, or platforms.
- Social media reformatting — adapt images for different aspect ratios and contexts.
- Design iteration — rapidly explore variations of a concept without manual editing.
- E-commerce optimization — enhance product images for better conversion.

## Pro Tips

- Be specific about what to change — 'replace the red car with a blue bicycle' is better than 'change the vehicle'.
- No manual masking needed — the model infers edit regions from your prompt description.
- Provide multiple reference images (up to 16) for style transfer or multi-image composition tasks.
- Describe the desired result, not the process: 'a sunny sky' rather than 'remove the clouds'.
- Use high-quality source images for the best edit blending.

## Notes

- Supports up to 16 input images per request.
- Aspect ratio auto-detected from input when not specified.
- Output formats: PNG, JPEG, or WebP.
- Median generation time: approximately 64 seconds.

## FAQ

**Q: What is the GPT Image 2 Edit API?**

An image editing API that modifies existing images based on natural language instructions, powered by OpenAI's GPT Image model via AirCube. Supports up to 16 reference images.

**Q: Do I need to provide a mask?**

No — GPT Image 2 Edit does not require manual masking. The model intelligently infers the target region from your prompt description.

**Q: How many images can I provide?**

Up to 16 input images per request — use multiple images for context, style reference, or multi-image composition.

**Q: How much does it cost?**

Starting at $0.02 for low/1k quality, up to $0.73 for high/4k. Each additional input image adds $0.012.

**Q: Can I use edited images commercially?**

Yes — edited outputs are yours to use commercially.

**Q: What edits work best?**

Object addition/removal, background changes, style modifications, product enhancement, and multi-image composition all work well.
