Skip to content

Number of images (n)

Only n = 1 is currently supported.

  • Leaving n out, or sending 1, works as usual.
  • Any value above 1 is rejected with HTTP 400 and the message Currently only n=1 is supported. Nothing is charged and no task is created.
  • 0, negative or non-integer values are also rejected with 400.
{
  "error": {
    "code": "invalid_request",
    "message": "Currently only n=1 is supported",
    "type": "invalid_request_error"
  }
}

To generate several images, send several requests. The async endpoint makes this easy: submit all tasks first, then poll them.

prompts = ["a red kite", "a blue kite", "a green kite"]
task_ids = [
    requests.post(f"{BASE_URL}/images/generations/async", headers=headers,
                  json={"model": "gpt-image-2", "prompt": p}, timeout=30).json()["id"]
    for p in prompts
]
# then poll each ID as shown in the async guide