> ## 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.

# 画像を生成

> <ul><li>指定したプロンプトから画像を作成します。[詳細](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": "日差しのある庭を走る小さな子猫、映画的、高精細",
    "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": "日差しのある庭を走る小さな子猫、映画的、高精細",
      "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": "日差しのある庭を走る小さな子猫、映画的、高精細",
    "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>
  すべてのエンドポイントで Bearer Token 認証が必要です。

  リクエストヘッダーに追加します:

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

## Body

<ParamField body="model" type="string" default="gpt-image-1.5">
  画像生成に使用するモデル。`dall-e-2`、`dall-e-3`、`gpt-image-1` のいずれかです。`gpt-image-1` 専用パラメーターを使用しない限り、デフォルトは `dall-e-2` です。

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

<ParamField body="prompt" type="string" required>
  生成したい画像のテキスト説明。最大長は `gpt-image-1` が32,000文字、`dall-e-2` が1,000文字、`dall-e-3` が4,000文字です。
</ParamField>

<ParamField body="n" type="integer">
  生成する画像数。1〜10の範囲で指定します。`dall-e-3` では `n=1` のみ対応します。
</ParamField>

<ParamField body="size" type="string">
  生成画像のサイズ。`gpt-image-1` では `1024x1024`、`1536x1024`（横向き）、`1024x1536`（縦向き）、または `auto`（デフォルト）のいずれかです。`dall-e-2` では `256x256`、`512x512`、`1024x1024` のいずれかです。`dall-e-3` では `1024x1024`、`1792x1024`、`1024x1792` のいずれかです。
</ParamField>

<ParamField body="background" type="string">
  生成画像の背景透明度を設定できます。このパラメーターは `gpt-image-1` のみ対応します。`transparent`、`opaque`、`auto`（デフォルト）のいずれかです。`auto` を使用すると、モデルが画像に最適な背景を自動判定します。

  背景が `transparent` の場合、出力形式は透明度に対応している必要があるため、`png`（デフォルト）または `webp` に設定してください。
</ParamField>

<ParamField body="moderation" type="string">
  `gpt-image-1` が生成する画像のコンテンツモデレーションレベルを制御します。より制限の少ないフィルタリングには `low`、または `auto`（デフォルト）を指定します。
</ParamField>

<ParamField body="quality" type="string">
  生成画像の品質。
</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>
