User Guide
Image Generation Model

GPT Image 2

Describes the integration status of `gpt-image-2` in the current project, as well as the request fields and response structure of the unified image interface.

  • The page path is retained to illustrate the integration status in the current project
  • Unified image interface: POST /v1/images/generations
  • Successful responses are synchronous ImageResponse

Current Integration Status

  • Magick API already supports the gpt-image-2 model

Public Image Interface Design

Request Routing

POST /v1/images/generations

Successful Response Structure

{
  "created": 1712345678,
  "data": [
    {
      "url": "https://example.com/generated-image.png",
      "b64_json": "",
      "revised_prompt": ""
    }
  ]
}

Standard Request Fields

The current project guarantees that the following standard fields will be properly parsed by the public image DTO:

  • model
  • prompt
  • n
  • size
  • quality
  • response_format

It is not recommended to directly rely on non-standardized fields at the top level of the public image interface.

Ready-to-Use Call Examples

The following examples apply when "the backend has already mapped gpt-image-2 as an available model":

cURL

curl --request POST \
  --url https://api.magickapi.com/v1/images/generations \
  --header 'Authorization: Bearer YOUR_API_KEY' \
  --header 'Content-Type: application/json' \
  --data '{
    "model": "gpt-image-2",
    "prompt": "一只橘猫坐在窗台上看夕阳,水彩画风格",
    "n": 1,
    "size": "1024x1024",
    "response_format": "url"
  }'

Python

import requests

url = "https://api.magickapi.com/v1/images/generations"
headers = {
    "Authorization": "Bearer YOUR_API_KEY",
    "Content-Type": "application/json",
}
payload = {
    "model": "gpt-image-2",
    "prompt": "一只橘猫坐在窗台上看夕阳,水彩画风格",
    "n": 1,
    "size": "1024x1024",
    "response_format": "url",
}

response = requests.post(url, headers=headers, json=payload, timeout=300)
response.raise_for_status()

result = response.json()
print(result)
print("image_url:", result["data"][0]["url"])

Node.js

const url = "https://api.magickapi.com/v1/images/generations";
const payload = {
  model: "gpt-image-2",
  prompt: "一只橘猫坐在窗台上看夕阳,水彩画风格",
  n: 1,
  size: "1024x1024",
  response_format: "url",
};

const response = await fetch(url, {
  method: "POST",
  headers: {
    Authorization: "Bearer YOUR_API_KEY",
    "Content-Type": "application/json",
  },
  body: JSON.stringify(payload),
});

if (!response.ok) {
  throw new Error(await response.text());
}

const result = await response.json();
console.log(result);
console.log("image_url:", result.data?.[0]?.url);

If you prefer to receive Base64 content directly, change response_format to b64_json and read data[0].b64_json.

Image Editing

If the channel corresponding to this model supports editing capabilities, the unified editing endpoints in the current project are:

  • POST /v1/images/edits
  • POST /v1/edits

Notes

  • Asynchronous image tasks are supported. Please check the generated images in [Task Log] -> [Image Generation Log].

Last updated on

On this page