> ## 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 公式チャネル 画像生成

> - OpenAI公式のgpt-image-2モデル、/v1/images/generations互換プロトコルに基づく
- 非同期処理モード、後続のクエリ用にtask_idを返す
- テキスト画像生成 / 画像変換 三合一
- 新たにresolutionフィールドを追加、1K / 2K / 4K解像度をサポート
- 13種類のアスペクト比をサポート（4Kはそのうち6つを対応：16:9 / 9:16 / 2:1 / 1:2 / 21:9 / 9:21）
- 参照画像は最大9枚まで、URLとbase64の混在をサポート
- 提出されたプロンプトはプラットフォームの禁止用語 / 安全審査を通過し、違反内容は直接拒否される


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

## Authorizations

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

  API Key の取得：

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

  使用時はリクエストヘッダーに次のように追加します：

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

## Body

<ParamField body="model" type="string" default="gpt_image_2_official" required>
  画像生成モデル名

  固定で `gpt_image_2_official` を入力してください（OpenAI公式のgpt-image-2モデル）
</ParamField>

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

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

      * 日本語・英語対応、詳細に説明することを推奨
      * 提出前にプラットフォームの検閲・安全審査を通過し、不適切な内容があればエラーを返します
    </ParamField>

    <ParamField body="aspect_ratio" type="string" default="1:1">
      画面比率

      外部には比率値を使用し、システム内部で `resolution` により具体的なピクセルに自動マッピングされます。

      13種類の比率に対応：

      * `1:1` - 正方形構図（デフォルト、SNSのプロフィール画像／ロゴ）
      * `3:2` - 横長構図（一眼レフカメラで一般的な比率）
      * `2:3` - 縦長構図（ポスター縦版）
      * `4:3` - 横長構図（クラシックディスプレイ／PPT）
      * `3:4` - 縦長構図
      * `5:4` - 横長構図
      * `4:5` - 縦長構図（Instagram縦型投稿）
      * `16:9` - 横長構図（ワイドスクリーンの動画カバー）
      * `9:16` - 縦長構図（スマホ全画面／ショート動画のカバー）
      * `2:1` - 横長構図（ウェブのバナー）
      * `1:2` - 縦長構図
      * `21:9` - 横長構図（映画の超ワイドスクリーン）
      * `9:21` - 縦長構図

      <Warning>
        比率形式のみ対応、ピクセルサイズ（例：`1024x1024`）を使うとエラーになります
      </Warning>
    </ParamField>

    <ParamField body="resolution" type="string" default="1K">
      解像度設定

      実際の画像の鮮明さを制御：

      * `1K` - 1024基準、コスト節約で日常的に十分（デフォルト）
      * `2K` - 2048基準、ポスターや高解像度が必要な場合
      * `4K` - 3840基準、**6つの比率のみ対応**（`16:9` / `9:16` / `2:1` / `1:2` / `21:9` / `9:21`）

      <Warning>
        非対応の4K組み合わせは400エラーを返します：

        * `1:1` × `4K` ❌（ピクセル数上限超過）
        * `3:2` / `2:3` × `4K` ❌（ピクセル数上限超過）
        * `4:3` / `3:4` × `4K` ❌（ピクセル数上限超過）
        * `5:4` / `4:5` × `4K` ❌（ピクセル数上限超過）

        これらの比率で高解像度が必要な場合は `resolution=2K` を使用してください。
      </Warning>
    </ParamField>

    <ParamField body="quality" type="string" default="low">
      画像品質

      * `low` - 速くてコスト低め、輪郭十分（デフォルト）
      * `medium` - バランス良し
      * `high` - 最高精度（4K + high は処理時間 >120秒）
    </ParamField>

    <ParamField body="image_url" type="array">
      参考画像の配列。渡すと画像生成モードで動作します

      * 最大 **9枚** の参考画像
      * 以下の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>
  </Expandable>
</ParamField>

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

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

## サイズ × 解像度マッピング表

`aspect_ratio × resolution` → OpenAI 実際ピクセル（13 比率 × 3 レベル）：

| aspect\_ratio | `1K`      | `2K`      | `4K`          |
| ------------- | --------- | --------- | ------------- |
| `1:1`         | 1024×1024 | 2048×2048 | ❌ ピクセル上限超過    |
| `3:2`         | 1536×1024 | 2048×1360 | ❌ ピクセル上限超過    |
| `2:3`         | 1024×1536 | 1360×2048 | ❌ ピクセル上限超過    |
| `4:3`         | 1024×768  | 2048×1536 | ❌ ピクセル上限超過    |
| `3:4`         | 768×1024  | 1536×2048 | ❌ ピクセル上限超過    |
| `5:4`         | 1280×1024 | 2560×2048 | ❌ ピクセル上限超過    |
| `4:5`         | 1024×1280 | 2048×2560 | ❌ ピクセル上限超過    |
| `16:9`        | 1536×864  | 2048×1152 | **3840×2160** |
| `9:16`        | 864×1536  | 1152×2048 | **2160×3840** |
| `2:1`         | 2048×1024 | 2688×1344 | **3840×1920** |
| `1:2`         | 1024×2048 | 1344×2688 | **1920×3840** |
| `21:9`        | 2016×864  | 2688×1152 | **3840×1648** |
| `9:21`        | 864×2016  | 1152×2688 | **1648×3840** |

> `3:2` / `2:3` @ 2K は実際には 2048×1360（概算比率、誤差 \< 0.5%）；4K は6つの比率のみサポート（総ピクセルがOpenAI上限超過の組み合わせは使用不可）。

## Response

<ResponseField name="code" type="integer">
  レスポンスステータスコード
</ResponseField>

<ResponseField name="data" type="array">
  返却データの配列

  <Expandable title="プロパティ">
    <ResponseField name="status" type="string">
      タスクステータス

      * `submitted` - 送信済み
    </ResponseField>

    <ResponseField name="task_id" type="string">
      タスクの一意識別子。後続のタスク結果のクエリに使用されます
    </ResponseField>
  </Expandable>
</ResponseField>

## タスク結果の問い合わせ

送信成功後に `task_id` が返され、`GET /v1/tasks/{task_id}` でタスクの状態をポーリングします。詳細は [タスク問い合わせAPI](/jp/api-reference/tasks/get-task) をご参照ください。

### ポーリングの推奨

* **初回問い合わせ遅延**：送信後10〜20秒待ってから問い合わせを開始してください
* **問い合わせ間隔**：3〜5秒に1回が推奨されます
* **タイムアウト目安**：`high + 2K/4K` の組み合わせで最大130秒かかることがあり、クライアントのタイムアウトは180秒以上を推奨します

<RequestExample>
  ```bash cURL 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_official",
      "params": {
        "prompt": "星空の下の古い城",
        "aspect_ratio": "16:9",
        "resolution": "2K",
        "quality": "high"
      },
      "out_task_id": "my_task_123456"
    }'
  ```

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

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

  payload = {
      "model": "gpt_image_2_official",
      "params": {
          "prompt": "星空の下の古い城",
          "aspect_ratio": "16:9",
          "resolution": "2K",
          "quality": "high"
      },
      "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_official",
    params: {
      prompt: "星空の下の古い城",
      aspect_ratio: "16:9",
      resolution: "2K",
      quality: "high",
    },
    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_official",
          "params": map[string]interface{}{
              "prompt":     "星空の下の古い城",
              "aspect_ratio":       "16:9",
              "resolution": "2K",
              "quality":    "high",
          },
          "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_official",
            "params": {
              "prompt": "星空の下の古い城",
              "aspect_ratio": "16:9",
              "resolution": "2K",
              "quality": "high"
            },
            "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_official",
      "params" => [
          "prompt" => "星空の下の古い城",
          "aspect_ratio" => "16:9",
          "resolution" => "2K",
          "quality" => "high"
      ],
      "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_official",
    params: {
      prompt: "星空の下の古い城",
      aspect_ratio: "16:9",
      resolution: "2K",
      quality: "high"
    },
    out_task_id: "my_task_123456"
  }

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

  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_official",
      "params": [
          "prompt": "星空の下の古い城",
          "aspect_ratio": "16:9",
          "resolution": "2K",
          "quality": "high"
      ],
      "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_official"",
              ""params"": {
                  ""prompt"": ""星空の下の古い城"",
                  ""aspect_ratio"": ""16:9"",
                  ""resolution"": ""2K"",
                  ""quality"": ""high""
              },
              ""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);
      }
  }
  ```

  ```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_official',
      'params': {
        'prompt': '星空の下の古い城',
        'aspect_ratio': '16:9',
        'resolution': '2K',
        'quality': 'high',
      },
      '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_official",
    params = list(
      prompt = "星空の下の古い城",
      aspect_ratio = "16:9",
      resolution = "2K",
      quality = "high"
    ),
    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}
  {
    "code": 200,
    "data": [
      {
        "status": "submitted",
        "task_id": "task_01KPTXXXXXXXXXXXXXXX"
      }
    ]
  }
  ```

  ```json 400 theme={null}
  {
    "error": {
      "code": 400,
      "message": "解像度4Kはサイズ1:1でサポートされていません。許可されているのは1K / 2Kです",
      "type": "invalid_request_error"
    }
  }
  ```

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

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

  ```json 429 theme={null}
  {
    "error": {
      "code": 429,
      "message": "リクエストが多すぎます。後ほど再試行してください",
      "type": "rate_limit_error"
    }
  }
  ```

  ```json 500 theme={null}
  {
    "error": {
      "code": 500,
      "message": "サーバー内部エラーが発生しました。後ほど再試行してください",
      "type": "server_error"
    }
  }
  ```
</ResponseExample>
