> ## Documentation Index
> Fetch the complete documentation index at: https://docs.elkapi.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Generate Image

> <ul><li>Create an image from a given prompt. [Learn more](https://platform.openai.com/docs/guides/images).</li></ul>

<RequestExample>
  ```bash cURL theme={null} theme={null}
  curl --request POST \
    --url 'https://api.elkapi.com/v1/images/generations' \
    --header 'Authorization: Bearer <token>' \
    --header 'Content-Type: application/json' \
    --data '{
    "prompt": "A small kitten running through a sunny garden, cinematic, highly detailed",
    "model": "gpt-image-1.5",
    "size": "1024x1024",
    "stream": false
  }'
  ```

  ```python Python theme={null} theme={null}
  import requests

  url = "https://api.elkapi.com/v1/images/generations"
  headers = {
      "Authorization": "Bearer <token>"
  }
  headers["Content-Type"] = "application/json"
  payload = {
      "prompt": "A small kitten running through a sunny garden, cinematic, highly detailed",
      "model": "gpt-image-1.5",
      "size": "1024x1024",
      "stream": False
  }

  response = requests.request("POST", url, headers=headers, json=payload)
  print(response.json())
  ```

  ```javascript JavaScript theme={null} theme={null}
  const url = "https://api.elkapi.com/v1/images/generations";

  const headers = {
    "Authorization": "Bearer <token>"
  };
  headers["Content-Type"] = "application/json";
  const payload = {
    "prompt": "A small kitten running through a sunny garden, cinematic, highly detailed",
    "model": "gpt-image-1.5",
    "size": "1024x1024",
    "stream": false
  };

  const response = await fetch(url, {
    method: "POST",
    headers,
    body: JSON.stringify(payload)
  });

  console.log(await response.json());
  ```
</RequestExample>

<ResponseExample>
  ```json 200 theme={null} theme={null}
  {
    "created": 1,
    "data": [
      {
        "b64_json": "b64_json",
        "url": "https://example.com/image.png"
      }
    ],
    "usage": {
      "total_tokens": 1,
      "input_tokens": 1,
      "output_tokens": 1,
      "input_tokens_details": {
        "text_tokens": 1,
        "image_tokens": 1
      }
    }
  }
  ```
</ResponseExample>

## Authorizations

<ParamField header="Authorization" type="string" required>
  All endpoints require Bearer Token authentication.

  Add it to the request headers:

  ```
  Authorization: Bearer YOUR_API_KEY
  ```
</ParamField>

## Body

<ParamField body="model" type="string" default="gpt-image-1.5">
  Model used for image generation. One of `dall-e-2`, `dall-e-3`, or `gpt-image-1`. Defaults to `dall-e-2` unless a `gpt-image-1`-specific parameter is used.

  Example: `gpt-image-1.5`
</ParamField>

<ParamField body="prompt" type="string" required>
  Text description of the desired image. The maximum length is 32,000 characters for `gpt-image-1`, 1,000 characters for `dall-e-2`, and 4,000 characters for `dall-e-3`.
</ParamField>

<ParamField body="n" type="integer">
  Number of images to generate. Must be between 1 and 10. For `dall-e-3`, only `n=1` is supported.
</ParamField>

<ParamField body="size" type="string">
  Size of the generated image. For `gpt-image-1`, it must be one of `1024x1024`, `1536x1024` (landscape), `1024x1536` (portrait), or `auto` (default). For `dall-e-2`, it must be one of `256x256`, `512x512`, or `1024x1024`. For `dall-e-3`, it must be one of `1024x1024`, `1792x1024`, or `1024x1792`.
</ParamField>

<ParamField body="background" type="string">
  Allows setting background transparency for the generated image. This parameter is only supported by `gpt-image-1`. Must be one of `transparent`, `opaque`, or `auto` (default). When using `auto`, the model automatically determines the best background for the image.

  If the background is `transparent`, the output format must support transparency, so set it to `png` (default) or `webp`.
</ParamField>

<ParamField body="moderation" type="string">
  Controls the content moderation level for images generated by `gpt-image-1`. Use `low` for less restrictive filtering or `auto` (default).
</ParamField>

<ParamField body="quality" type="string">
  The quality of the generated image.
</ParamField>

<ParamField body="stream" type="string" />

<ParamField body="style" type="string" />

<ParamField body="user" type="string" />

## Response

<ResponseField name="created" type="integer" />

<ResponseField name="data" type="array<object>">
  <ResponseField name="data.b64_json" type="string" />

  <ResponseField name="data.url" type="string" required />
</ResponseField>

<ResponseField name="usage" type="object">
  <ResponseField name="usage.total_tokens" type="integer" required />

  <ResponseField name="usage.input_tokens" type="integer" required />

  <ResponseField name="usage.output_tokens" type="integer" required />

  <ResponseField name="usage.input_tokens_details" type="object" required>
    <ResponseField name="usage.input_tokens_details.text_tokens" type="integer" required />

    <ResponseField name="usage.input_tokens_details.image_tokens" type="integer" required />
  </ResponseField>
</ResponseField>
