Image Generation
GPT Image 2
OpenAI's SOTA image generation and editing model on Replicate.
POST /v2/images/generate — model: "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
| Parameter | Type | Description |
|---|---|---|
gptImage2Params.quality | string | low, medium, high, or auto (default). Drives speed and credit cost. |
gptImage2Params.aspect_ratio | string | 1:1, 3:2, or 2:3. |
gptImage2Params.output_format | string | webp (default), png, or jpeg. |
gptImage2Params.background | string | auto (default) or opaque. Transparent backgrounds are not supported — use gpt-image-1.5 if you need them. |
gptImage2Params.moderation | string | auto (default) or low. low applies less restrictive content filtering. |
gptImage2Params.input_images | string[] | One or more reference image URLs. Use one to edit an image, multiple to combine subjects/styles into a single output. |
gptImage2Params.number_of_images | integer | 1–10. Cost is multiplied by this value. |
Credit cost
| Quality | Credits per image |
|---|---|
low | 4 |
medium | 9 |
high | 23 |
auto | 23 |
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.5if you need transparent PNGs. - No
input_fidelityknob — the model always preserves input images at high fidelity. - New
moderationfield for less restrictive content filtering. - Default
output_formatiswebp(waspng).
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.