Image generation and editing

Generate images from text and edit existing images with gpt-image-2.

Generate an image

POST /v1/images/generations with JSON. Your key needs access to gpt-image-2.

Shell
curl --fail-with-body -sS https://site6.eokgg.win/v1/images/generations \
  -H "Authorization: Bearer $SITE6_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
    "model":"gpt-image-2",
    "prompt":"A simple blue circle centred on white.",
    "size":"1024x1024",
    "quality":"low",
    "output_format":"png"
  }' -o image-response.json

Successful replies return a JSON object with data[].b64_json. Decode the base64 to recover the image bytes.

Python
import base64
import json
from pathlib import Path

response = json.loads(Path("image-response.json").read_text(encoding="utf-8"))
Path("circle.png").write_bytes(base64.b64decode(response["data"][0]["b64_json"]))

Edit an uploaded image

POST /v1/images/edits with multipart form data. Let curl or your HTTP client set the multipart boundary.

Shell
curl --fail-with-body -sS https://site6.eokgg.win/v1/images/edits \
  -H "Authorization: Bearer $SITE6_API_KEY" \
  -F 'model=gpt-image-2' \
  -F 'prompt=Change the blue circle to red.' \
  -F 'image=@circle.png' \
  -o edit-response.json

Upload PNG, JPEG or WebP images. Repeat image[] for multiple images and use mask for an optional PNG mask. The multipart body limit is 6 MiB.

Image options

Prompts can contain up to 32,000 characters. Use size: "auto" or a supported width × height string. Quality can be low, medium, high or auto. Output can be PNG, JPEG or WebP. Transparent backgrounds require PNG or WebP. Compression is available on JPEG and WebP.

Image generation and editing return one JSON response. If a large result hits the transport limit, request fewer images or use a compressed format. Use 2chat for an interactive image generation and editing interface when your key has access.

Search the docs