API documentation
GPT Image
Generate and edit images with openai/gpt-image-2.
GPT Image uses OpenAI-compatible image endpoints. Send new image prompts to /v1/images/generations. Send edits with a prompt and source images to /v1/images/edits. Read the result from data[0].b64_json or data[0].url.
Request
GPT Image request
curl https://api.aigate.shop/v1/images/generations \ -H "Authorization: Bearer sk-your-api-key" \ -H "Content-Type: application/json" \ -d '{ "model": "openai/gpt-image-2", "prompt": "A clean studio product photo of a matte black smart speaker on glass, softbox lighting", "quality": "medium", "size": "1024x1024", "n": 1 }'Response
Image response
{ "created": 1779703910, "data": [ { "b64_json": "iVBORw0KGgoAAAANSUhEUgAA..." } ], "usage": { "input_tokens": 712, "output_tokens": 1372, "total_tokens": 2084 }}Edit an existing image
Use /v1/images/edits when the model should change an existing image. Put the edit instruction in prompt and put one or more source images in images. JSON image_url input and multipart uploads are supported when the upstream model supports them.
GPT Image edit request
curl https://api.aigate.shop/v1/images/edits \ -H "Authorization: Bearer sk-your-api-key" \ -H "Content-Type: application/json" \ -d '{ "model": "openai/gpt-image-2", "prompt": "Add a small orange cat sitting on the table. Keep the original lighting and style.", "images": [ { "image_url": "https://picsum.photos/seed/aigate-edit-test/800/600" } ] }'Edit response
{ "created": 1779703910, "data": [ { "b64_json": "iVBORw0KGgoAAAANSUhEUgAA..." } ], "usage": { "input_tokens": 712, "output_tokens": 1372, "total_tokens": 2084 }}Request fields
| Field | Required | Meaning |
|---|---|---|
| model | yes | Use openai/gpt-image-2 or the exact GPT Image id from the catalog. |
| prompt | yes | Natural-language image prompt. |
| images | edits only | Source image array. Each item can contain image_url for JSON requests. |
| quality | no | low, medium, high, or provider default when omitted. |
| size | no | WIDTHxHEIGHT, for example 1024x1024 or 2048x880 when supported. |
| resolution | no | Optional hint such as 1k, 2k, or 4k when supported. |
| n | no | Number of images to generate. |
| background/output_format | no | Forwarded when supported by the model. |
Save base64 output
ts
import { writeFileSync } from "node:fs";const image = response.data[0];if (image.b64_json) { writeFileSync("gpt-image.png", Buffer.from(image.b64_json, "base64"));} else if (image.url) { console.log(image.url);}Prompting
- Start with the subject, then add environment, composition, lighting, style, and constraints.
- For product images, specify material, camera angle, background, and whether text/logos should appear.
- For transparent background, request it explicitly and use a model/output format that supports it.