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

# GPT-Image-2 画像生成

> - 非同期処理モードで、後続クエリ用にタスクIDを返します
- OpenAI Images互換プロトコルに基づき、テキストから画像生成および画像から画像生成をサポート
- 13種類の画像比率を aspect_ratio フィールドで指定可能
- resolution フィールドを追加し、1K / 2K / 4K 解像度選択（4Kは全比率対応）をサポート
- size フィールドを追加し、ピクセルサイズのカスタマイズをサポート（aspect_ratio / resolution と排他、合計ピクセル数が2,088,960以上で正確な出力可能)
- 参照画像は最大10枚まで、URLとbase64混在可能
- 提出されたプロンプトはプラットフォームの禁止語句および安全審査を通過し、違反内容は即時拒否されます


export const apiKeyUrl = 'https://aireiter.com/keys';

## Authorizations

<ParamField header="Authorization" type="string" required>
  すべてのエンドポイントはBearer Tokenで認証が必要です

  APIキーの取得方法：

  <a href={apiKeyUrl} target="_blank">API Key 管理ページ</a>にアクセスしてAPIキーを取得してください

  使用時はリクエストヘッダーに以下を追加します：

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

## Body

<ParamField body="model" type="string" required>
  モデル名

  固定値：`"gpt_image_2"`
</ParamField>

<ParamField body="params" type="object" required>
  モデルのパラメーターオブジェクト

  <Expandable title="params オブジェクトのプロパティ">
    <ParamField body="prompt" type="string" required>
      画像生成のテキスト説明

      * 日本語と英語をサポートし、詳細な説明を推奨します
      * 提出前にプラットフォームの敏感語 / セキュリティ審査を経て、違反内容が検出された場合はエラーを直接返します
    </ParamField>

    <ParamField body="image_url" type="string[]">
      参考画像の配列。渡すと画像生成モードになります

      * 最大 10 枚の参考画像まで
      * 以下の2つの形式がサポートされています：
        1. 公開アクセス可能な URL
        2. Base64エンコード形式
           * 完全な Data URI 形式を使用する必要があります：`data:image/{形式};base64,{base64データ}`
           * 対応画像形式：jpeg、png、webp
           * 例：`data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEAYABg...`
           * ⚠️ 注意：`data:image/jpeg;base64,` のプレフィックス部分が必須です
    </ParamField>

    <ParamField body="aspect_ratio" type="string" default="auto">
      画像生成のアスペクト比

      デフォルト値は `resolution` によって変わります：

      * `resolution` が `1K` / `2K` の場合、未指定は `auto`
      * `resolution` が `4K` の場合、未指定は `16:9`

      以下の値をサポートします：

      * `auto` - 自動的に最適な比率を選択
      * `1:1` - 正方形
      * `16:9` / `9:16` - ワイドスクリーン横 / 縦
      * `4:3` / `3:4` - 標準横 / 縦
      * `3:2` / `2:3` - クラシック横 / 縦
      * `5:4` / `4:5` - ほぼ正方形横 / 縦
      * `2:1` / `1:2` - ワイド横 / 縦長
      * `21:9` / `9:21` - 超ワイド横 / 超縦長

      <Warning>
        比率は文字列または `auto` のみサポートしており、ピクセルサイズ（例：`1024x1024`）を渡すとエラーになります
      </Warning>
    </ParamField>

    <ParamField body="resolution" type="string" default="1K">
      解像度のレベル

      実際の生成画像の鮮明さを制御します：

      * `1K` - 1024基準、コスト削減の日常利用に十分（デフォルト）
      * `2K` - 2048基準、ポスターや高精細のニーズに適合
      * `4K` - 3840基準、**13 全ての比率をサポート**

      <Warning>
        `size` を渡す場合、`resolution` と `aspect_ratio` は同時に渡せません。両方渡すと400エラーを返します。
      </Warning>
    </ParamField>

    <ParamField body="size" type="string">
      カスタムのピクセルサイズ（`aspect_ratio` / `resolution` と**排他**）

      形式は `幅x高さ` で、例：`2048x1536`、`3840x2160`。

      **使用制限：**

      * 形式は `^\d+x\d+$` のみで、例：`2048x1536`。他の形式はサポートしません
      * `aspect_ratio`、`resolution` と排他で、3つのうち1つのみ選択可能。同時に渡すと400エラー
      * 総ピクセル数（幅×高さ）は **655,360 ～ 8,294,400** の範囲内である必要があります

      **実測のピクセル下限：**

      | 総ピクセル範囲            | 上流の動作                               |
      | ------------------ | ----------------------------------- |
      | ≥ 2,088,960（約2.0M） | 渡した `size` で正確に生成 ✅                 |
      | \< 2,088,960       | 約1.57Mの近い比率に静かに置き換え（`size`未指定と同等）⚠️ |

      <Warning>
        総ピクセル数が約2,088,960未満の場合、上流からはエラーが出ませんが静かにサイズを置き換えて出力します。正確に制御したい場合は、**総ピクセル数を2,088,960以上にすることを推奨します**。

        小サイズのニーズがある場合は `aspect_ratio` と `resolution=1K` の組み合わせを使用してください。
      </Warning>

      **推奨利用パターン：**

      | ニーズ            | 推奨方法                             |
      | -------------- | -------------------------------- |
      | ピクセルサイズを正確に制御  | `size` かつ総ピクセル数 ≥ 2,088,960      |
      | 小サイズ（2Mピクセル未満） | `aspect_ratio` + `resolution=1K` |
      | 中・大サイズの任意比率    | `size`、2K / 4K 範囲内で任意の比率で正確に生成可能 |
    </ParamField>
  </Expandable>
</ParamField>

<ParamField body="out_task_id" type="string" required>
  発注者のタスクID

  ユーザーがカスタムで定義するタスク識別子、必須
</ParamField>

## サイズ × 解像度対応表

`aspect_ratio × resolution` → 実際のピクセル（13の比率 × 3つのレンジ）：

| aspect\_ratio | `1K`                  | `2K`      | `4K`          |
| ------------- | --------------------- | --------- | ------------- |
| `1:1`         | 1024×1024 / 1254×1254 | 2048×2048 | **2880×2880** |
| `3:2`         | 1536×1024             | 2048×1360 | **3520×2336** |
| `2:3`         | 1024×1536             | 1360×2048 | **2336×3520** |
| `4:3`         | 1024×768              | 2048×1536 | **3312×2480** |
| `3:4`         | 768×1024              | 1536×2048 | **2480×3312** |
| `5:4`         | 1280×1024 / 1448×1086 | 2560×2048 | **3216×2576** |
| `4:5`         | 1024×1280 / 1122×1402 | 2048×2560 | **2576×3216** |
| `16:9`        | 1536×864 / 1672×941   | 2048×1152 | **3840×2160** |
| `9:16`        | 864×1536 / 941×1672   | 1152×2048 | **2160×3840** |
| `2:1`         | 2048×1024 / 1774×887  | 2688×1344 | **3840×1920** |
| `1:2`         | 1024×2048 / 887×1774  | 1344×2688 | **1920×3840** |
| `21:9`        | 2016×864 / 1915×821   | 2688×1152 | **3840×1648** |
| `9:21`        | 864×2016 / 821×1915   | 1152×2688 | **1648×3840** |

> `3:2` / `2:3` @ 2K は実際には2048×1360（近似比率、誤差 \< 0.5%）です；4Kは現在13種の比率すべてに対応しています。

## カスタムサイズ（size パラメータ）

ピクセルサイズを正確に制御する場合、`aspect_ratio` + `resolution` の組み合わせの代わりに `size` パラメータを使用できます。

**有効範囲：** 合計ピクセル数 655,360 ～ 8,294,400（上流公式制限）

**実測有効下限：** 合計ピクセル数 ≥ **2,088,960**（約 1440×1452 または 2048×1020 の同等面積）

下限より少ない場合、上流ではエラーが発生しませんが、約1.57Mピクセルの近い比率サイズに静かに置き換えられます。

### よく使う size の例

| size 値      | 合計ピクセル数   | 推奨用途          |
| ----------- | --------- | ------------- |
| `2048x2048` | 4,194,304 | 正方形の高解像度      |
| `2048x1536` | 3,145,728 | 4:3 横向き       |
| `1536x2048` | 3,145,728 | 3:4 縦向き       |
| `2048x1152` | 2,359,296 | 16:9 横向き      |
| `1152x2048` | 2,359,296 | 9:16 縦向き      |
| `3840x2160` | 8,294,400 | 4K 16:9（最高品質） |
| `2688x1344` | 3,612,672 | 2:1 幅広横向き     |

<Warning>
  **`aspect_ratio` または `resolution` と同時に渡さないでください。そうしないと 400 が返されます。**
</Warning>

## Response

<ResponseField name="out_task_id" type="string">
  発注者のタスクID。結果の照会に使用可能
</ResponseField>

<ResponseField name="status" type="string">
  初期ステータス。固定で `"pending"`
</ResponseField>

<ResponseField name="estimated_credits" type="number">
  推定消費クレジット
</ResponseField>

<ResponseField name="created_at" type="string">
  作成日時（ISO形式）
</ResponseField>

<RequestExample>
  ```bash cURL（aspect_ratio） theme={null}
  curl --request POST \
    --url https://aireiter.com/api/openapi/submit \
    --header 'Authorization: Bearer <token>' \
    --header 'Content-Type: application/json' \
    --data '{
      "model": "gpt_image_2",
      "params": {
        "prompt": "窓辺に座って夕日を見ている茶トラ猫、水彩画風",
        "aspect_ratio": "16:9"
      },
      "out_task_id": "my_task_123456"
    }'
  ```

  ```bash cURL（size カスタムサイズ） theme={null}
  curl --request POST \
    --url https://aireiter.com/api/openapi/submit \
    --header 'Authorization: Bearer <token>' \
    --header 'Content-Type: application/json' \
    --data '{
      "model": "gpt_image_2",
      "params": {
        "prompt": "窓辺に座って夕日を見ている茶トラ猫、水彩画風",
        "size": "2048x1152"
      },
      "out_task_id": "my_task_size_001"
    }'
  ```

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

  url = "https://aireiter.com/api/openapi/submit"

  payload = {
      "model": "gpt_image_2",
      "params": {
          "prompt": "窓辺に座って夕日を見ている茶トラ猫、水彩画風",
          "aspect_ratio": "16:9"
      },
      "out_task_id": "my_task_123456"
  }

  headers = {
      "Authorization": "Bearer <token>",
      "Content-Type": "application/json"
  }

  response = requests.post(url, json=payload, headers=headers)

  print(response.json())
  ```

  ```javascript JavaScript theme={null}
  const url = "https://aireiter.com/api/openapi/submit";

  const payload = {
    model: "gpt_image_2",
    params: {
      prompt: "窓辺に座って夕日を見ている茶トラ猫、水彩画風",
      aspect_ratio: "16:9"
    },
    out_task_id: "my_task_123456"
  };

  const headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
  };

  fetch(url, {
    method: "POST",
    headers: headers,
    body: JSON.stringify(payload)
  })
    .then(response => response.json())
    .then(data => console.log(data))
    .catch(error => console.error('Error:', error));
  ```

  ```go Go theme={null}
  package main

  import (
      "bytes"
      "encoding/json"
      "fmt"
      "io/ioutil"
      "net/http"
  )

  func main() {
      url := "https://aireiter.com/api/openapi/submit"

      payload := map[string]interface{}{
          "model": "gpt_image_2",
          "params": map[string]interface{}{
              "prompt":       "窓辺に座って夕日を見ている茶トラ猫、水彩画風",
              "aspect_ratio": "16:9",
          },
          "out_task_id": "my_task_123456",
      }

      jsonData, _ := json.Marshal(payload)

      req, _ := http.NewRequest("POST", url, bytes.NewBuffer(jsonData))
      req.Header.Set("Authorization", "Bearer <token>")
      req.Header.Set("Content-Type", "application/json")

      client := &http.Client{}
      resp, err := client.Do(req)
      if err != nil {
          panic(err)
      }
      defer resp.Body.Close()

      body, _ := ioutil.ReadAll(resp.Body)
      fmt.Println(string(body))
  }
  ```

  ```java Java theme={null}
  import java.net.http.HttpClient;
  import java.net.http.HttpRequest;
  import java.net.http.HttpResponse;
  import java.net.URI;

  public class Main {
      public static void main(String[] args) throws Exception {
          String url = "https://aireiter.com/api/openapi/submit";

          String payload = """
          {
            "model": "gpt_image_2",
            "params": {
              "prompt": "窓辺に座って夕日を見ている茶トラ猫、水彩画風",
              "aspect_ratio": "16:9"
            },
            "out_task_id": "my_task_123456"
          }
          """;

          HttpClient client = HttpClient.newHttpClient();
          HttpRequest request = HttpRequest.newBuilder()
              .uri(URI.create(url))
              .header("Authorization", "Bearer <token>")
              .header("Content-Type", "application/json")
              .POST(HttpRequest.BodyPublishers.ofString(payload))
              .build();

          HttpResponse<String> response = client.send(request,
              HttpResponse.BodyHandlers.ofString());

          System.out.println(response.body());
      }
  }
  ```

  ```php PHP theme={null}
  <?php

  $url = "https://aireiter.com/api/openapi/submit";

  $payload = [
      "model" => "gpt_image_2",
      "params" => [
          "prompt" => "窓辺に座って夕日を見ている茶トラ猫、水彩画風",
          "aspect_ratio" => "16:9"
      ],
      "out_task_id" => "my_task_123456"
  ];

  $ch = curl_init($url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_POST, true);
  curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload));
  curl_setopt($ch, CURLOPT_HTTPHEADER, [
      "Authorization: Bearer <token>",
      "Content-Type: application/json"
  ]);

  $response = curl_exec($ch);
  curl_close($ch);

  echo $response;
  ?>
  ```

  ```ruby Ruby theme={null}
  require 'net/http'
  require 'json'
  require 'uri'

  url = URI("https://aireiter.com/api/openapi/submit")

  payload = {
    model: "gpt_image_2",
    params: {
      prompt: "窓辺に座って夕日を見ている茶トラ猫、水彩画風",
      aspect_ratio: "16:9"
    },
    out_task_id: "my_task_123456"
  }

  http = Net::HTTP.new(url.host, url.port)

  request = Net::HTTP::Post.new(url)
  request["Authorization"] = "Bearer <token>"
  request["Content-Type"] = "application/json"
  request.body = payload.to_json

  response = http.request(request)
  puts response.body
  ```

  ```swift Swift theme={null}
  import Foundation

  let url = URL(string: "https://aireiter.com/api/openapi/submit")!

  let payload: [String: Any] = [
      "model": "gpt_image_2",
      "params": [
          "prompt": "窓辺に座って夕日を見ている茶トラ猫、水彩画風",
          "aspect_ratio": "16:9"
      ],
      "out_task_id": "my_task_123456"
  ]

  var request = URLRequest(url: url)
  request.httpMethod = "POST"
  request.setValue("Bearer <token>", forHTTPHeaderField: "Authorization")
  request.setValue("application/json", forHTTPHeaderField: "Content-Type")
  request.httpBody = try? JSONSerialization.data(withJSONObject: payload)

  let task = URLSession.shared.dataTask(with: request) { data, response, error in
      if let error = error {
          print("Error: \(error)")
          return
      }

      if let data = data, let responseString = String(data: data, encoding: .utf8) {
          print(responseString)
      }
  }

  task.resume()
  ```

  ```csharp C# theme={null}
  using System;
  using System.Net.Http;
  using System.Text;
  using System.Threading.Tasks;

  class Program
  {
      static async Task Main(string[] args)
      {
          var url = "https://aireiter.com/api/openapi/submit";

          var payload = @"{
              ""model"": ""gpt_image_2"",
              ""params"": {
                  ""prompt"": ""窓辺に座って夕日を見ている茶トラ猫、水彩画風"",
                  ""aspect_ratio"": ""16:9""
              },
              ""out_task_id"": ""my_task_123456""
          }";

          using var client = new HttpClient();
          client.DefaultRequestHeaders.Add("Authorization", "Bearer <token>");

          var content = new StringContent(payload, Encoding.UTF8, "application/json");
          var response = await client.PostAsync(url, content);
          var result = await response.Content.ReadAsStringAsync();

          Console.WriteLine(result);
      }
  }
  ```

  ```c C theme={null}
  #include <stdio.h>
  #include <curl/curl.h>

  int main(void) {
      CURL *curl;
      CURLcode res;

      curl_global_init(CURL_GLOBAL_DEFAULT);
      curl = curl_easy_init();

      if(curl) {
          const char *url = "https://aireiter.com/api/openapi/submit";
          const char *payload = "{"
              "\"model\":\"gpt_image_2\","
              "\"params\":{"
                  "\"prompt\":\"窓辺に座って夕日を見ている茶トラ猫、水彩画風\","
                  "\"aspect_ratio\":\"16:9\""
              "},"
              "\"out_task_id\":\"my_task_123456\""
          "}";

          struct curl_slist *headers = NULL;
          headers = curl_slist_append(headers, "Authorization: Bearer <token>");
          headers = curl_slist_append(headers, "Content-Type: application/json");

          curl_easy_setopt(curl, CURLOPT_URL, url);
          curl_easy_setopt(curl, CURLOPT_POSTFIELDS, payload);
          curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);

          res = curl_easy_perform(curl);

          if(res != CURLE_OK) {
              fprintf(stderr, "curl_easy_perform() failed: %s\n",
                      curl_easy_strerror(res));
          }

          curl_slist_free_all(headers);
          curl_easy_cleanup(curl);
      }

      curl_global_cleanup();
      return 0;
  }
  ```

  ```objectivec Objective-C theme={null}
  #import <Foundation/Foundation.h>

  int main(int argc, const char * argv[]) {
      @autoreleasepool {
          NSURL *url = [NSURL URLWithString:@"https://aireiter.com/api/openapi/submit"];

          NSDictionary *payload = @{
              @"model": @"gpt_image_2",
              @"params": @{
                  @"prompt": @"窓辺に座って夕日を見ている茶トラ猫、水彩画風",
                  @"aspect_ratio": @"16:9"
              },
              @"out_task_id": @"my_task_123456"
          };

          NSError *error;
          NSData *jsonData = [NSJSONSerialization dataWithJSONObject:payload
                                                            options:0
                                                              error:&error];

          NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
          [request setHTTPMethod:@"POST"];
          [request setValue:@"Bearer <token>" forHTTPHeaderField:@"Authorization"];
          [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
          [request setHTTPBody:jsonData];

          NSURLSessionDataTask *task = [[NSURLSession sharedSession]
              dataTaskWithRequest:request
              completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
                  if (error) {
                      NSLog(@"Error: %@", error);
                      return;
                  }
                  NSString *result = [[NSString alloc] initWithData:data
                                                          encoding:NSUTF8StringEncoding];
                  NSLog(@"%@", result);
              }];

          [task resume];
          [[NSRunLoop mainRunLoop] run];
      }
      return 0;
  }
  ```

  ```ocaml OCaml theme={null}
  (* Requires cohttp and yojson libraries *)
  open Lwt
  open Cohttp
  open Cohttp_lwt_unix

  let url = "https://aireiter.com/api/openapi/submit"

  let payload = {|{
    "model": "gpt_image_2",
    "params": {
      "prompt": "窓辺に座って夕日を見ている茶トラ猫、水彩画風",
      "aspect_ratio": "16:9"
    },
    "out_task_id": "my_task_123456"
  }|}

  let () =
    let headers = Header.init ()
      |> fun h -> Header.add h "Authorization" "Bearer <token>"
      |> fun h -> Header.add h "Content-Type" "application/json"
    in
    let body = Cohttp_lwt.Body.of_string payload in

    let response = Client.post ~headers ~body (Uri.of_string url) >>= fun (resp, body) ->
      body |> Cohttp_lwt.Body.to_string >|= fun body_str ->
      print_endline body_str
    in
    Lwt_main.run response
  ```

  ```dart Dart theme={null}
  import 'dart:convert';
  import 'package:http/http.dart' as http;

  void main() async {
    final url = Uri.parse('https://aireiter.com/api/openapi/submit');

    final payload = {
      'model': 'gpt_image_2',
      'params': {
        'prompt': '窓辺に座って夕日を見ている茶トラ猫、水彩画風',
        'aspect_ratio': '16:9'
      },
      'out_task_id': 'my_task_123456'
    };

    final response = await http.post(
      url,
      headers: {
        'Authorization': 'Bearer <token>',
        'Content-Type': 'application/json'
      },
      body: jsonEncode(payload),
    );

    print(response.body);
  }
  ```

  ```r R theme={null}
  library(httr)
  library(jsonlite)

  url <- "https://aireiter.com/api/openapi/submit"

  payload <- list(
    model = "gpt_image_2",
    params = list(
      prompt = "窓辺に座って夕日を見ている茶トラ猫、水彩画風",
      aspect_ratio = "16:9"
    ),
    out_task_id = "my_task_123456"
  )

  response <- POST(
    url,
    add_headers(
      Authorization = "Bearer <token>",
      `Content-Type` = "application/json"
    ),
    body = toJSON(payload, auto_unbox = TRUE),
    encode = "raw"
  )

  cat(content(response, "text"))
  ```
</RequestExample>

<ResponseExample>
  ```json 200 theme={null}
  {
      "statusCode": 200,
      "message": "",
      "data": {
          "out_task_id": "my_task_123456",
          "status": "pending",
          "estimated_credits": 100,
          "created_at": "2025-12-22T06:03:28.242Z"
      }
  }
  ```

  ```json 400 theme={null}
  {
      "statusCode": 400,
      "message": "リクエストパラメータが無効です",
      "ok": false
  }
  ```

  ```json 401 theme={null}
  {
    "error": {
      "code": 401,
      "message": "認証に失敗しました。APIキーを確認してください"
    }
  }
  ```

  ```json 433 theme={null}
  {
    "error": {
      "code": 433,
      "message": "アカウント残高が不足しています。チャージ後再試行してください"
    }
  }
  ```

  ```json 500 theme={null}
  {
    "error": {
      "code": 500,
      "message": "サーバ内部エラー。後でもう一度お試しください"
    }
  }
  ```
</ResponseExample>
