ApiframeApiframe Docs
Image Generation

GPT Image 2

OpenAI's SOTA image generation and editing model on Replicate.

Use in Apiframe Studio

POST /v2/images/generatemodel: "gpt-image-2"

GPT Image 2 is OpenAI's state-of-the-art image model. It handles two workflows in a single endpoint: generating images from text, and editing existing images by passing one or more reference images. It excels at photorealism, dense text rendering (infographics, UI mockups), and precise edits that preserve composition and identity.

Pass gptImage2Params.input_images to switch from text-to-image to editing/composition. The model automatically processes input images at high fidelity — there's no knob to adjust.

Model-specific parameters

ParameterTypeDescription
gptImage2Params.qualitystringlow, medium, high, or auto (default). Drives speed and credit cost.
gptImage2Params.aspect_ratiostring1:1, 3:2, or 2:3.
gptImage2Params.output_formatstringwebp (default), png, or jpeg.
gptImage2Params.backgroundstringauto (default) or opaque. Transparent backgrounds are not supported — use gpt-image-1.5 if you need them.
gptImage2Params.moderationstringauto (default) or low. low applies less restrictive content filtering.
gptImage2Params.input_imagesstring[]One or more reference image URLs. Use one to edit an image, multiple to combine subjects/styles into a single output.
gptImage2Params.number_of_imagesinteger1–10. Cost is multiplied by this value.

Credit cost

QualityCredits per image
low4
medium9
high23
auto23

A request with quality: "medium" and number_of_images: 4 costs 9 × 4 = 36 credits.

Examples

Text to image

curl -X POST https://api.apiframe.ai/v2/images/generate \
  -H "X-API-Key: afk_your_api_key_here" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-image-2",
    "prompt": "Infographic explaining how photosynthesis works, bold sans-serif labels, light academic color palette",
    "gptImage2Params": {
      "quality": "high",
      "aspect_ratio": "3:2"
    }
  }'
import requests

response = requests.post(
    "https://api.apiframe.ai/v2/images/generate",
    headers={
        "X-API-Key": "afk_your_api_key_here",
        "Content-Type": "application/json",
    },
    json={
        "model": "gpt-image-2",
        "prompt": "Infographic explaining how photosynthesis works, bold sans-serif labels, light academic color palette",
        "gptImage2Params": {
            "quality": "high",
            "aspect_ratio": "3:2",
        },
    },
)
print(response.json())
const response = await fetch("https://api.apiframe.ai/v2/images/generate", {
  method: "POST",
  headers: {
    "X-API-Key": "afk_your_api_key_here",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    model: "gpt-image-2",
    prompt:
      "Infographic explaining how photosynthesis works, bold sans-serif labels, light academic color palette",
    gptImage2Params: {
      quality: "high",
      aspect_ratio: "3:2",
    },
  }),
});
console.log(await response.json());

Image editing (input_images)

curl -X POST https://api.apiframe.ai/v2/images/generate \
  -H "X-API-Key: afk_your_api_key_here" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-image-2",
    "prompt": "Change the red hat to a light-blue velvet beret. Preserve the subject'\''s face, pose, and lighting.",
    "gptImage2Params": {
      "input_images": ["https://example.com/portrait.jpg"],
      "quality": "auto"
    }
  }'
import requests

response = requests.post(
    "https://api.apiframe.ai/v2/images/generate",
    headers={
        "X-API-Key": "afk_your_api_key_here",
        "Content-Type": "application/json",
    },
    json={
        "model": "gpt-image-2",
        "prompt": "Change the red hat to a light-blue velvet beret. Preserve the subject's face, pose, and lighting.",
        "gptImage2Params": {
            "input_images": ["https://example.com/portrait.jpg"],
            "quality": "auto",
        },
    },
)
print(response.json())
const response = await fetch("https://api.apiframe.ai/v2/images/generate", {
  method: "POST",
  headers: {
    "X-API-Key": "afk_your_api_key_here",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    model: "gpt-image-2",
    prompt:
      "Change the red hat to a light-blue velvet beret. Preserve the subject's face, pose, and lighting.",
    gptImage2Params: {
      input_images: ["https://example.com/portrait.jpg"],
      quality: "auto",
    },
  }),
});
console.log(await response.json());

Differences vs gpt-image-1.5

  • No transparent background — use gpt-image-1.5 if you need transparent PNGs.
  • No input_fidelity knob — the model always preserves input images at high fidelity.
  • New moderation field for less restrictive content filtering.
  • Default output_format is webp (was png).

Prompt tips

  • Be specific. "Add soft coastal daylight" beats "make it better".
  • Use photo language for realism — lens type, lighting quality, framing.
  • When editing, lock what shouldn't change. "Change only the lighting, preserve the subject's face, pose, and clothing."
  • Put visible text in quotes and describe the typography.

On this page