メインコンテンツへスキップ
POST
このルートを使用すると、CometAPI で OpenAI 互換のリクエスト形式によりテキストから画像を作成できます。

公式リファレンス

  • モデル固有のコントロールに依存する前に、 OpenAI の画像生成ガイド をお読みください。これには background、output_compression、ストリーミング、将来の GPT 画像オプションなどが含まれます。
  • 現在のパラメータ一覧については、 OpenAI の画像作成リファレンス を参照してください。

まずモデルを選択

  • gpt-image-2 などの GPT 画像モデルを使用すると、output_format、quality、background などのコントロールを備えたテキストから画像へのリクエストを実行できます
  • 透明な背景、または gpt-image-2.5-sunburst と gpt-image-2.5-flare の品質レベルが必要な場合は、xhigh または max を使用します
  • Qwen-Image、Doubao Seedream、Grok Imagine など、他の画像モデルファミリーでも同じリクエスト形式を使用できます。まずは model と prompt から始めてください
  • 現在の画像モデル 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。他の画像モデルでは、そのモデル向けの非同期タスクサポートが文書化されていない限り、同期生成またはストリーミングを使用してください。 リクエストに 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 の画像生成ガイドに従ってください
  • 他の画像モデルファミリーでは、画像が url ではなく b64_json で返されることがあります。各結果項目に含まれるフィールドを読み取ってください

透明な背景を生成する

背景の塗りつぶしがない被写体のみの画像を生成するには、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 フィールドに返されます。
生成された画像はプロバイダーの利用ポリシーに準拠する必要があります。違法、暴力的、ポルノ、または著作権を侵害するプロンプト(Prompt)を送信しないでください。

承認

Authorization
string
header
必須

Bearer token authentication. Use your CometAPI key.

ボディ

application/json
model
string
デフォルト:gpt-image-2
必須

The image generation model to use. Choose a current model from the Models page.

prompt
string
必須

Text description of the image you want to generate.

例:

"A paper boat floating on calm water at sunrise."

n
integer
デフォルト:1

Number of images to generate. Keep this at 1 for the broadest compatibility.

quality
string

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
enum<string>

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
output_compression
integer
デフォルト:100

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 <= 100
moderation
enum<string>
デフォルト:auto

Content moderation level for GPT image models. low is less restrictive; auto is the default.

利用可能なオプション:
low,
auto
partial_images
integer

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 <= 3
size
string

Requested output size. Supported values depend on the selected model. See the OpenAI image generation guide for the latest model-specific ranges.

例:

"1024x1024"

response_format
enum<string>

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
output_format
string

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"

stream
boolean
デフォルト:false

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.

async
boolean
デフォルト:false

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.

created
integer
必須

Unix timestamp for the completed generation.

data
object[]
必須
background
string

Background mode returned by models that expose it.

output_format
string

Encoded image type returned by GPT image models.

quality
string

Quality level returned by models that expose it.

size
string

Output size returned by models that expose it.

usage
object

Token usage details when returned by the selected model.

最終更新日 2026年10月29日