GuideImage GenerationOpenai

Image Generation

OpenAI image generation API reference: create images from prompts with dall-e-3 or gpt-image models, covering size, background, quality and response format.

Create images from a prompt using the native OpenAI format.


📌 Basics

  • Endpoint: POST /v1/images/generations/
  • Request domain: https://anyrouter.win
  • Authentication: Bearer Token
  • Content type: application/json

📥 Request Parameters (Request Body)

ParameterTypeRequiredDefaultDescription
modelstringNodall-e-2Model to use: dall-e-2, dall-e-3, or gpt-image-1, gpt-image-1.5, gpt-image-2.
promptstringYes-Text description of the image. Up to 32k characters for GPT-image-1.
nintegerNo1Number of images (1-10). dall-e-3 only supports 1.
sizestringNo1024x1024Size. gpt-image-1 supports 1024x1024, 1536x1024, 1024x1536, or auto.
backgroundstringNoautoBackground transparency (gpt-image-1 only): transparent, opaque, auto.
moderationstringNoautoContent moderation level: low (less restrictive) or auto.
qualitystringNo-Quality of the generated image (HD/Standard).
stylestringNo-Image style.

📤 Response

Status code: 200 OK

FieldTypeDescription
createdintegerUnix timestamp when the request was created.
dataarrayList of image objects.
└─ urlstringHosted URL of the image.
└─ b64_jsonstringBase64-encoded image data.
usageobjectUsage statistics.
└─ total_tokensintegerTotal tokens consumed by this request.

📝 Request Example

{
  "model": "gpt-image-1",
  "prompt": "A cute baby sea otter",
  "n": 1,
  "size": "1024x1024",
  "background": "transparent"
}

📝 Response Example

{
  "created": 1713833628,
  "data": [
    {
      "url": "https://example.com/generated_image.png",
      "b64_json": ""
    }
  ],
  "usage": {
    "total_tokens": 100,
    "input_tokens": 50,
    "output_tokens": 50,
    "input_tokens_details": {
      "text_tokens": 10,
      "image_tokens": 40
    }
  }
}

💡 Notes

  1. Transparency support: When background is set to transparent, make sure the backend returns a format that supports an alpha channel, such as png or webp.
  2. Model differences: Different models (DALL-E vs GPT-image) have different limits on size and n; choose a model based on your actual business needs.

On this page