画像を作成
CometAPI POST /v1/images/generations を使用して、OpenAI互換の画像モデルとモデル固有のコントロールで画像を作成します。
公式リファレンス
- 次の OpenAI画像生成ガイド を読み、
background、output_compression、ストリーミング(Streaming)、または今後のGPT画像オプションなど、モデル固有のコントロールを利用する前に確認してください。 - 最新のパラメータ一覧については、 OpenAIの画像作成リファレンス を参照してください。
まずモデルを選択する
gpt-image-2などのGPT画像モデルを使用すると、output_format、quality、backgroundなどのコントロールを備えたテキストから画像へのリクエストを実行できます。- 透明な背景、または
gpt-image-2.5-sunburstとgpt-image-2.5-flareの品質レベルが必要な場合は、xhighまたはmaxを使用してください。 - そのプロバイダーを特に必要とする場合は
qwen-imageを使用しますが、nは1に設定したままにしてください。 - 現在の画像モデルIDは、次のページから選択してください: モデルページ
安全な最初のリクエスト
- まずは
gpt-image-2から始めてください。 sizeは1024x1024に設定したままにしてください。- GPT画像モデルは、base64エンコードされた画像データを
b64_jsonで返します。画像ファイルを保存するにはデコードしてください。 output_formatは、jpegなど特定のエンコード済み画像形式が必要な場合にのみ追加してください。- バッチ生成やスタイル調整を追加する前に、1つのプロンプトと1枚の出力画像を使用してください。
非同期画像タスクを実行する
長時間実行される画像ジョブで、クライアントが1つのHTTP接続を開いたままにするのではなく送信してポーリングするフローを望む場合は、async: true を使用してください。作成リクエストは data.task_id を返します。
ポーリングする 画像生成タスクを取得する を、data.status が success または failure になるまでポーリングしてください。
async フィールドは、このルート用のCometAPI拡張であり、OpenAIパラメータではありません。OpenAIはGPT画像モデル向けに stream と partial_images を文書化しています。CometAPIの非同期タスクモードはJSONタスクメタデータを返し、ポーリングを使用します。
次の文書化されたモデルIDで非同期タスクモードを使用してください:gpt-image-2 と doubao-seedream-4-0-250828。その他の画像モデルでは、そのモデルで非同期タスクのサポートが文書化されている場合を除き、同期生成またはストリーミング(Streaming)を使用してください。
リクエストに async: true と stream: true の両方が含まれる場合、非同期タスクモードが優先されます。作成リクエストはSSEストリームではなくJSONタスクメタデータを返します。
モデル固有のリクエスト動作
response_formatはDALL·Eモデルにのみ適用されます。GPT画像モデルはbase64データを返し、これを無視します。- GPT画像モデルでは、GPT-only のコントロールとして
output_format、quality、background、output_compressionを使用します。 qualityは、GPT画像モデルでlow、medium、high、autoを受け付けます。gpt-image-2.5-sunburstとgpt-image-2.5-flareでは、xhighとmaxも受け付けます。output_compressionは、output_formatがwebpまたはjpegの場合に適用されます。pngには影響しません。partial_imagesは、streamがtrueの場合にのみ適用されます。- 最新のモデル固有オプションについては、OpenAI画像生成ガイドに従ってください。
qwen-imageはn > 1をサポートしていません。
透明な背景を生成する
背景の塗りつぶしがない被写体のみの画像を生成するには、background を transparent に設定します。これは gpt-image-2.5-sunburst および gpt-image-2.5-flare でサポートされています。
透明化にはアルファチャネルを備えた出力形式が必要です。output_format を png または webp に設定します。JPEG にはアルファチャネルがないため、output_format: "jpeg" を指定した透明化リクエストは拒否されます。
レスポンスでは、アルファチャネルを含む base64 画像データが b64_json に返されます。ファイルとして保存するには、これをデコードします。
background を opaque に設定すると単色背景を強制でき、auto に設定するとモデルに判断させることができます。レスポンスでは、適用された値がトップレベルの background フィールドに返されます。
承認
Bearer token authentication. Use your CometAPI key.
ボディ
The image generation model to use. Choose a current model from the Models page.
Text description of the image you want to generate.
"A paper boat floating on calm water at sunrise."
Number of images to generate. Keep this at 1 for the broadest compatibility.
Quality setting for models that support it. GPT image models accept low, medium, high, and auto. gpt-image-2.5-sunburst and gpt-image-2.5-flare also accept xhigh and max. dall-e-3 accepts standard and hd. See the OpenAI image generation guide for the latest model-specific values.
"low"
Background mode for the generated image. Set transparent to generate an isolated subject with no background fill; this requires output_format set to png or webp, and returns an error with jpeg. Set opaque for a solid background, or auto to let the model decide. Supported on gpt-image-2.5-sunburst and gpt-image-2.5-flare.
transparent, opaque, auto Compression level for the output image, from 0 to 100. Applies when output_format is webp or jpeg. Lower values produce smaller files with more compression artifacts.
0 <= x <= 100Content moderation level for GPT image models. low is less restrictive; auto is the default.
low, auto Number of partial images to emit while a streaming response is in progress, from 0 to 3. Each partial image arrives as an image_generation.partial_image event before the final image_generation.completed event. Applies when stream is true.
0 <= x <= 3Requested output size. Supported values depend on the selected model. See the OpenAI image generation guide for the latest model-specific ranges.
"1024x1024"
The response container for dall-e-2 and dall-e-3. This parameter is not supported for GPT image models, which return base64-encoded image data.
url, b64_json The encoded image type for GPT image model results, such as png, jpeg, or webp. See the OpenAI image generation guide for current GPT image output controls.
"jpeg"
Set this to true to receive server-sent image generation events instead of waiting for the completed JSON response. Streaming responses use text/event-stream and can include final events such as image_generation.completed. When stream and async are both true, async task mode takes precedence and the create request returns JSON instead of a streaming image response.
CometAPI asynchronous task mode. Set this to true to return immediately with data.task_id, then poll GET /v1/images/generations/{task_id} for the final image data. Documented model IDs for this mode: gpt-image-2 and doubao-seedream-4-0-250828. This is a CometAPI extension, not an OpenAI parameter. When async and stream are both true, async takes precedence and returns JSON task metadata instead of an SSE stream.
レスポンス
Image generation result. Synchronous requests return completed image data. Async requests return a task response with data.task_id.
- Completed image response
- Async task response
Unix timestamp for the completed generation.
Background mode returned by models that expose it.
Encoded image type returned by GPT image models.
Quality level returned by models that expose it.
Output size returned by models that expose it.
Token usage details when returned by the selected model.