本文へスキップ

画像を生成

OpenAI Images 互換のテキストからの画像生成:GPT Image、Gemini Banana、Seedream。Seedream と Gemini はここで参照画像も渡せます。

POST/v1/images/generations

プロンプトから画像を生成します。GPT Image と Gemini は data[].b64_json を、Seedream は data[].url(24 時間有効)を返します。Seedream と 2 つの Gemini グループは、このエンドポイントで image / images を使った画像から画像への生成にも対応します。

モデルごとにパラメータと上限が異なります:下でモデルを選ぶとパラメータ表が切り替わります。数値はプラグインの検証コードからエクスポートした仕様(/spec/models/<model>.json と同じソース)です。GPT Image の生成が約 40 秒を超えると、サーバーは先に 200 を返して空白のキープアライブを書き込み、その後に失敗しても 200 のままです。成否はレスポンスボディに error が含まれるかで判断し、クライアントの読み取りタイムアウトは 300 秒以上にしてください。

Kling と Midjourney もこのエンドポイントで送信しますが、すべて非同期(202 + id、動画タスクを照会でポーリング)です。モデル選択で「Kling」「Midjourney」を選ぶと確認できます。Grok Imagine は Grok Imagine 画像生成 を参照してください。

  • GPT Image は公式のストリーミングフィールド partial_images に対応していないため、省略してください。stream: true で返るのは HopBase Images SSE で、1 枚ずつのプレビューイベントではありません。
  • output_compression、moderation、user、response_format は同期のテキストから画像 JSON と同期の multipart 編集でのみそのまま渡されます。JSON 編集と非同期タスクではこれらのフィールドは保持されません。GPT Image の非同期で保持されるのは model、prompt、n、size、quality、background、output_format、input_fidelity と、編集用の画像 / mask のみです。
  • Gemini の課金:「Gemini 全モデル(画像生成含む)」は 1 枚あたりの固定価格(1K / 2K / 4K 同額)、「Gemini 公式ダイレクト」は token 課金(出力 token × 単価)です。
  • Chat Completions から Images へのブリッジ経路では参照画像は先頭 6 枚までしか保持されません。14 枚使う場合はこのエンドポイントを直接呼び出してください。

ヘッダー

Authorization:必須string

Bearer sk-…:コンソールの「API キー」で作成したキー。キーのグループにリクエストするモデルが含まれている必要があります

Prefer:任意string

respond-async:GPT Image / Gemini は即座に 202 Accepted、task_id、status_url を返すので、GET /v1/images/tasks?task_id=… でポーリングします。2K / 4K の大きな画像を生成する場合に推奨します。Seedream はこのヘッダーを無視し、通常どおり同期で返します

取りうる値respond-async

リクエストボディJSON

モデル画像リクエストビルダーで開く モデルのドキュメント
グループ:GPT Image 全モデル。 結果は data[].b64_json から読み取ります。 参照画像は最大 16 枚。
model:必須"gpt-image-2"

まず現在のキーの GET /v1/models にこの ID が含まれていることを確認してください

prompt:必須string

生成または編集の指示。空の場合は 400 prompt must not be empty。ゲートウェイでは長さを制限せず、上限は公式上限に従います

制限前後の空白を除いて空にはできません。空の場合は 400「prompt must not be empty」長さ1–32000 文字

size:任意"auto" または string

例:1024x1024、2048x2048、3840x2160。不正な値は生成前に 400 を返し、課金されません。1K / 2K / 4K は受け付けません

制限auto または 幅x高さ:辺の長さは 16 の倍数、1 辺 3840 以下、長辺と短辺の比 3:1 以下、総ピクセル数 655360–8294400

quality:任意string

レベルが高いほど出力トークンが増え、費用も高くなります。1024x1024 の実測では low 約 200、high 約 1,760、xhigh 約 3,120、max 約 7,020 出力トークンです

取りうる値autolowmediumhigh

制限ゲートウェイでは検証せず、そのまま転送。レベルが高いほど出力トークンが増えます

n:任意integer

一部のグループは 1 のみ対応で、それより大きい値は 400 を返します。0 以下は 1 として扱います

範囲1–10デフォルト1

background:任意string

transparent は png または webp と組み合わせる必要があります。2.0 の透明背景はプレビュー機能です

取りうる値autoopaquetransparent

output_format:任意string

b64_json をデコードした後の形式を決めます

取りうる値pngjpegwebp

output_compression:任意integer

jpeg / webp のみ。同期の generations JSON と multipart の編集でのみ保持されます

範囲0–100デフォルト100

moderation:任意string

コンテンツの安全性チェックを無効にするものではありません

取りうる値autolow

user:任意string

エンドユーザー識別用の文字列。HopBase のアカウント ID ではなく、課金の帰属も変わりません

response_format:任意string

何を指定しても b64_json で返され、url でダウンロードリンクは取得できません。省略してください

stream:任意boolean

true にすると HopBase Images SSE になります(その間キープアライブを送信し、最後の data: イベントだけが Images JSON で、[DONE] で終わります)。OpenAI ネイティブの画像ごとのプレビューイベントではありません。SDK では false のままにしてください

制限true で HopBase Images SSE を返します。SDK では false のままにしてくださいデフォルトfalse

input_fidelity:任意string

互換用フィールド。GPT Image 2 は既定で参照画像を高忠実度で処理するため、省略してください

取りうる値lowhigh

  • transparent には png または webp が必要です
  • output_compression は jpeg / webp でのみ有効です

レスポンス

200同期で成功

202非同期受理:GPT Image / Gemini は Prefer: respond-async を付けたとき。Kling と Midjourney は常にこの形

created:任意integer

Unix 秒

data:必須array of object

画像 1 枚につき 1 項目

usage:任意object

返される場合あり

エラー

400パラメータ不正(生成前に拒否、課金なし)。コンテンツ安全性によるブロックは safety_rejected
401キー未指定、キーが無効または期限切れ(missing_api_key / invalid_api_key / api_key_expired)
402残高、またはキー・メンバー・部門のクォータを使い切った(insufficient_quota)
404モデルがこのキーのグループにない(model_not_found)、またはパスがそのグループに属さない(route_not_found)
413リクエストボディが 60 MB を超えた(request_too_large)
429アカウントまたはキーの同時実行数が上限に達した(user_concurrency_limit / apikey_concurrency_limit)。Retry-After 付き
GPT Image のエラーメッセージ原文
# size: 上表のサイズ規則に従って修正
size must be WIDTHxHEIGHT or auto
size side length exceeds 3840px (4096x2048)
size width and height must be multiples of 16 (1000x1000)
size aspect ratio must not exceed 3:1 (3840x1024)
size total pixel count must be at least 655360 (512x512=262144)
size total pixel count must not exceed 8294400 (3840x3840=14745600)

# prompt が空
prompt must not be empty

# edits JSON: 参照画像は "image" に文字列または {"url": ...} で指定。"images" は読み取らない
/v1/images/edits requires at least one image
image object is missing the url field
image must be a data URL or an http(s) URL

# リモート参照画像:image/* を返す公開 URL で、1 枚 25 MiB 以下
image download returned HTTP 404
image is too large
image Content-Type is not image/*: text/html
reference image URL must not point to an internal address
image is too large, please compress it to under 4MB and retry

# コンテンツセーフティによるブロック (error.code: safety_rejected)
Your request was rejected by the safety system.

# HTTP 413
Request body exceeds the size limit (60 MB)
Gemini のエラーメッセージ原文
# 「Gemini 全モデル(画像生成含む)」
prompt must not be empty
n must be between 1 and 10 for model gemini-3-pro-image
n=3 is too large for 4K output on model gemini-3-pro-image; at most 2 images per request at this size (response size limit); lower n or send separate requests
model gemini-3.1-flash-image does not support tier 4K; supported: 1K, 2K
model gemini-3-pro-image: size "big" is not valid; expected WIDTHxHEIGHT (any aspect ratio, mapped to the nearest official tier) or 1K/2K/4K
aspect_ratio "7:3" is not supported for model gemini-3-pro-image; allowed values: 1:1, 2:3, 3:2, 3:4, 4:3, 4:5, 5:4, 9:16, 16:9, 21:9
image_size "4K" is not supported for model gemini-3.1-flash-image; supported: 1K, 2K
background=transparent is not supported for model gemini-3-pro-image; Gemini image models cannot output transparent images
mask is not supported for Gemini image models; remove mask and describe the region to edit in the prompt
too many reference images: at most 14 are supported for this model, got 15

# 「Gemini 公式ダイレクト」
missing prompt
Gemini image generation does not support stream=true; send a non-streaming request
n must be at most 10
n=6 is too large for 2K output on model gemini-3.1-flash-image; at most 5 images per request at this size (response size limit); lower n or send separate requests
Images generations only accepts a JSON request body: ...
size 4K is not supported for model gemini-3.1-flash-image; supported tiers: 1K, 2K
size "banana" is not valid for model gemini-3-pro-image; use auto, WIDTHxHEIGHT (e.g. 1024x1024, mapped to the nearest supported aspect ratio and capped at the model's largest tier), or one of: 1K, 2K, 4K
image_config.aspect_ratio "7:3" is not supported; allowed values: 1:1, 2:3, 3:2, 3:4, 4:3, 4:5, 5:4, 9:16, 16:9, 21:9
image_config.image_size "4K" is not supported for model gemini-3.1-flash-image; allowed values: 1K, 2K
mask is not supported for model gemini-3-pro-image; remove mask and describe the region to edit in the prompt
background=transparent is not supported for model gemini-3-pro-image; Gemini image models cannot output transparent images
reference image 1: reference image exceeds the 20MB limit
reference image 1: reference image URL must not point to an internal address
reference image 1: reference image download returned HTTP 404
reference image 1: reference file is not a supported image type
Seedream のエラーメッセージ原文
model seedream-5-0-pro only supports size 1K, 1.5K, 2K or a valid WIDTHxHEIGHT pixel size   # 例:"size": "auto"
model seedream-5-0-lite requires the total pixel count of size to be between 3686400 and 16777216
size aspect ratio must be between 1:16 and 16:1
missing prompt
response_format only supports url
only a single output is supported (n=1)
model seedream-4-5 only supports output_format jpeg
optimize_prompt_options must be an object
image must be a URL/data URL string or an array of strings
every item in the image array must be a URL or data URL string
image must not be empty
at most 10 reference images are supported
reference image 1 is invalid: data URL must be base64-encoded
reference image 1 is invalid: unsupported image format image/svg+xml
reference image 1 is invalid: a single image must not exceed 30 MB
image edits require at least one image reference            # /v1/images/edits で画像なし
seedream does not accept a traditional mask; ...            # /v1/images/edits に "mask" があれば拒否(null でも同じ)

関連ページ