# Generate image

`POST /v1/images/generations`

Creates an image given a prompt. [Learn more](https://platform.openai.com/docs/guides/images).

## Authorizations

Bearer authentication — send `Authorization: Bearer <token>`.

## Request Body (application/json)

```json
{
  "type": "object",
  "properties": {
    "model": {
      "type": "string",
      "description": "The model to use for image generation. One of `dall-e-2`, `dall-e-3` or `gpt-image-1`. Defaults to `dall-e-2` unless a parameter specific to `gpt-image-1` is used."
    },
    "prompt": {
      "type": "string",
      "description": "A text description of the desired image(s). The maximum length is 32000 characters for `gpt-image-1`, 1000 characters for `dall-e-2` and 4000 characters for `dall-e-3`."
    },
    "n": {
      "type": "integer",
      "description": "The number of images to generate. Must be between 1 and 10. For `dall-e-3`, only `n=1` is supported."
    },
    "size": {
      "type": "string",
      "description": "The size of the generated images. Must be one of `1024x1024`, `1536x1024` (landscape), `1024x1536` (portrait), or `auto` (default value) for `gpt-image-1`, one of `256x256`, `512x512`, or `1024x1024` for `dall-e-2`, and one of `1024x1024`, `1792x1024`, or `1024x1792` for `dall-e-3`."
    },
    "background": {
      "type": "string",
      "description": "Allows to set transparency for the background of the generated image(s). This parameter is only supported for `gpt-image-1`. Must be one of `transparent`, `opaque` or `auto` (default value). When `auto` is used, the model will automatically determine the best background for the image.\n\nIf `transparent`, the output format needs to support transparency, so it should be set to either `png` (default value) or `webp`."
    },
    "moderation": {
      "type": "string",
      "description": "Control the content-moderation level for images generated by `gpt-image-1`. Must be either `low` for less restrictive filtering or `auto` (default value)."
    },
    "quality": {
      "type": "string",
      "description": "The quality of the image that will be generated."
    },
    "stream": {
      "type": "string"
    },
    "style": {
      "type": "string"
    },
    "user": {
      "type": "string"
    }
  },
  "required": [
    "prompt"
  ]
}
```

## Responses

### 200

```json
{
  "type": "object",
  "properties": {
    "created": {
      "type": "integer"
    },
    "data": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "b64_json": {
            "type": "string"
          },
          "url": {
            "type": "string"
          }
        },
        "required": [
          "url"
        ]
      }
    },
    "usage": {
      "type": "object",
      "properties": {
        "total_tokens": {
          "type": "integer"
        },
        "input_tokens": {
          "type": "integer"
        },
        "output_tokens": {
          "type": "integer"
        },
        "input_tokens_details": {
          "type": "object",
          "properties": {
            "text_tokens": {
              "type": "integer"
            },
            "image_tokens": {
              "type": "integer"
            }
          },
          "required": [
            "text_tokens",
            "image_tokens"
          ]
        }
      },
      "required": [
        "total_tokens",
        "input_tokens",
        "output_tokens",
        "input_tokens_details"
      ]
    }
  },
  "required": [
    "created",
    "data",
    "usage"
  ]
}
```
