Skip to content

GPT Image: create image

POST/v1/images/generations

Generate images from a prompt with the GPT Image series; results return in the same request. For reference images use Edit image.

Models and limits

ModelRule groupEndpointsnReference imagesprompt limit (chars)
gpt-image-2GPT Image series/v1/images/generations/v1/images/edits/v1/images/tasks1–41–16images on edits only32,000
gpt-image-2.5GPT Image series/v1/images/generations/v1/images/edits/v1/images/tasks1–41–16images on edits only32,000
gpt-image-2.5-flareGPT Image series/v1/images/generations/v1/images/edits/v1/images/tasks1–41–16images on edits only32,000
gpt-image-2.5-sunburstGPT Image series/v1/images/generations/v1/images/edits/v1/images/tasks1–41–16images on edits only32,000
gpt-image-2.6GPT Image series/v1/images/generations/v1/images/edits/v1/images/tasks1–41–16images on edits only32,000
gpt-image-2.6-flareGPT Image series/v1/images/generations/v1/images/edits/v1/images/tasks1–41–16images on edits only32,000
gpt-image-2.6-sunburstGPT Image series/v1/images/generations/v1/images/edits/v1/images/tasks1–41–16images on edits only32,000

Headers

  • AuthorizationstringRequired

    Bearer <API_KEY>.

  • Content-TypestringRequired

    application/json. Only JSON bodies are supported.

Request bodyJSON

  • modelstringRequired

    A GPT Image model ID, case-sensitive. Available models are listed below.

    GPT Image series
    gpt-image-2gpt-image-2.5gpt-image-2.5-flaregpt-image-2.5-sunburstgpt-image-2.6gpt-image-2.6-flaregpt-image-2.6-sunburst
  • promptstringRequired

    Describe the image to create.

    Must not be empty; up to 32,000 characters.

  • nintegerOptionalDefault 1

    Supports 1–4.

    Billed as per-image price × count, reserved from n at submission.

  • sizestringOptional

    Omit to let the model choose. Common dimensions are listed below. Other sizes are handled according to model capability; check the returned image for its actual dimensions.

    Use a lowercase x between width and height, not ×.

    Supported values

    • 1024x10241:1
    • 1536x10243:2
    • 1024x15362:3
  • response_formatstringOptional

    Omit or send url, then read the image from the returned data.

Returns

HTTP 200 with the list of images.

GPT Image does not accept the image reference field here; use POST /v1/images/edits.

  • createdintegerOptional

    Creation time in Unix seconds.

  • dataobject[]Optional

    Generated images, one per item.

    Show child fields (4)
    • urlstringOptional

      Download URL. Use it as returned and save the image promptly; do not send your API key when downloading.

    • b64_jsonstringOptional

      Base64 image data, which may be returned instead of url. Decode it to save.

    • revised_promptstringOptional

      The prompt the model used, when present.

    • width / height / sizeinteger / stringOptional

      Image dimensions, as width and height or WxH, when present.

  • output_formatstringOptional

    File format, when present.

  • usageobjectOptional

    Token usage, for reference only. Usage logs show the actual charge.

Errors

Errors return {"error": {"message": "...", "type": "...", "code": "..."}}.

HTTPcodeCause and action
400—Invalid parameters such as missing model, n above 128 or × in size; see error.message.
400asset_reference_not_foundThe asset:// asset does not exist or is not yours.
401—The API key is invalid, expired or disabled.
403insufficient_user_quotaInsufficient balance or key quota.
403—The key does not allow this model, or the IP is restricted.
429—Rate limited; retry later.
503model_not_foundNo channel is currently available for the model.
524—Gateway timeout while waiting (an HTML page). The image may still be generated and billed; check usage logs before retrying, or use asynchronous image tasks.
Generate a watercolor illustration
curl -X POST https://ling-light.com/v1/images/generations \
  -H "Authorization: Bearer $LINGLIGHT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "model": "gpt-image-2.6",
  "prompt": "A seated orange cat in soft morning light, watercolor illustration",
  "n": 1,
  "size": "1536x1024"
}'
const response = await fetch('https://ling-light.com/v1/images/generations', {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.LINGLIGHT_API_KEY}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    "model": "gpt-image-2.6",
    "prompt": "A seated orange cat in soft morning light, watercolor illustration",
    "n": 1,
    "size": "1536x1024"
  }),
})
console.log(response.status, await response.json())
import os

import requests

response = requests.post(
    "https://ling-light.com/v1/images/generations",
    headers={
        "Authorization": f"Bearer {os.environ['LINGLIGHT_API_KEY']}",
    },
    json={
        "model": "gpt-image-2.6",
        "prompt": "A seated orange cat in soft morning light, watercolor illustration",
        "n": 1,
        "size": "1536x1024",
    },
    timeout=60,
)
print(response.status_code, response.json())
Response
{
  "created": 1795660800,
  "data": [
    {
      "url": "https://media.example.com/images/example.png",
      "width": 1024,
      "height": 1024,
      "revised_prompt": "An orange cat on a windowsill in soft morning light, clean illustration"
    }
  ],
  "output_format": "png",
  "usage": {
    "input_tokens": 20,
    "output_tokens": 1056,
    "total_tokens": 1076
  }
}
API reference overview
Authentication, media URLs, idempotency and errors.
Integration guide
The full flow from API key to downloaded result.
Last updated