Overview

Use image edits when you already have a source image and want GPT Image 2 to modify style, replace elements, adjust composition, or create variations from that starting point.

Endpoint

  • Method: POST
  • URL: https://api.gptimageapi.dev/v1/images/edit

Authentication

Include your API key in the Authorization header. Don't have one yet? Create an API key here.

Authorization: Bearer YOUR_API_KEY
Content-Type: application/json

Request Body

{
  "prompt": "Turn this product shot into a premium studio image with softer reflections and a pale gray seamless backdrop.",
  "image": "https://example.com/image.jpg",
  "model": "gpt-image-2",
  "size": "4:3",
  "quality": "high",
  "n": 1
}

Parameters

  • prompt (required): The change you want the model to make.
  • image (required): A source image URL or base64 data URL.
  • model (optional): Use gpt-image-2.
  • size (optional): Output aspect ratio such as 1:1, 4:3, 16:9, 9:21, 1:2, or 2:1.
  • quality (optional): low, medium, or high.
  • n (optional): Number of outputs to generate.

Credit usage is based on quality: low = 4, medium = 8, high = 16 per image.

Good edit requests usually include

  • What should stay unchanged.
  • What should be replaced, removed, or restyled.
  • The target aesthetic or lighting direction.
  • Any required text that must appear in the final image.

Response

{
  "code": 0,
  "message": "ok",
  "data": {
    "images": [
      {
        "url": "https://cdn.gptimageapi.dev/edits/1234567890.png"
      }
    ]
  }
}

Prompting notes

  • If part of the source image must stay fixed, say so explicitly.
  • Describe the target aesthetic after you describe the required structural changes.
  • Use one clear source image whenever possible for the first pass.
  • When exact text matters, keep it short and place it in quotes.

Examples

curl

curl -X POST "https://api.gptimageapi.dev/v1/images/edit" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "prompt": "Turn this product shot into a premium studio image with softer reflections and a pale gray seamless backdrop.",
    "image": "https://example.com/image.jpg",
    "model": "gpt-image-2",
    "size": "4:3",
    "quality": "high",
    "n": 1
  }'

Node.js

async function editImage() {
  const res = await fetch('https://api.gptimageapi.dev/v1/images/edit', {
    method: 'POST',
    headers: {
      Authorization: 'Bearer YOUR_API_KEY',
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({
      prompt:
        'Turn this product shot into a premium studio image with softer reflections and a pale gray seamless backdrop.',
      image: 'https://example.com/image.jpg',
      model: 'gpt-image-2',
      size: '4:3',
      quality: 'high',
      n: 1,
    }),
  });

  const result = await res.json();
  if (result.code !== 0) throw new Error(result.message);
  return result.data.images[0].url;
}

Python

import requests


def edit_image():
  url = 'https://api.gptimageapi.dev/v1/images/edit'
  headers = {
    'Authorization': 'Bearer YOUR_API_KEY',
    'Content-Type': 'application/json',
  }
  payload = {
    'prompt': 'Turn this product shot into a premium studio image with softer reflections and a pale gray seamless backdrop.',
    'image': 'https://example.com/image.jpg',
    'model': 'gpt-image-2',
    'size': '4:3',
    'quality': 'high',
    'n': 1,
  }

  res = requests.post(url, headers=headers, json=payload, timeout=60)
  res.raise_for_status()
  result = res.json()
  if result.get('code') != 0:
    raise Exception(result.get('message'))
  return result.get('data', {}).get('images', [])[0].get('url')


print(edit_image())

Next steps

  • Return to the quickstart for the generation endpoint.
  • Read the model guide for capability limits and prompting advice.