For the complete documentation index, see llms.txt. Markdown versions of documentation pages are available by appending .md to the page URL.
メインナビゲーション
Theme

画像生成

モデルで画像を生成・編集できます。

画像生成ツールでは、テキストプロンプトから画像を生成できます。必要に応じて、画像も入力として渡せます。このツールは gpt-image-2.5-sunburst、gpt-image-2.5-flare、gpt-image-2、gpt-image-1.5、gpt-image-1-mini などの GPT Image モデルを使用し、より良い結果が得られるように入力テキストを自動で最適化します。

image_generation ツールの model には、画像を精密に編集する場合は gpt-image-2.5-sunburst を、高品質な画像を高速に生成する場合は gpt-image-2.5-flare を指定してください。Responses リクエストのトップレベルの model フィールドには、画像生成ツールに対応するメインモデルを指定してください。

gpt-image-1 は 2026 年 10 月 23 日に提供を終了しました。移行の詳細は廃止に関するお知らせをご覧ください。

画像生成について詳しくは、画像生成ガイドをご覧ください。

使い方

リクエストに image_generation ツールを含めると、モデルは会話のどの時点でどのように画像を生成するかを判断できます。その判断にはプロンプトと、入力画像があればその画像を使います。

image_generation_call の呼び出し結果には、Base64 でエンコードされた画像が含まれます。

個々のエンドユーザーが利用するアプリケーションでは、後続の編集リクエストも含め、すべての Responses リクエストのトップレベルに safety_identifier を指定してください。ユーザーごとに一貫した値を使い、プライバシーを保護してください。これはリクエストパラメーターであり、image_generation ツールのオプションではありません。両方の画像 API での指定方法は、画像の安全性識別子をご覧ください。

画像の生成
from openai import OpenAI
import base64

client = OpenAI()

response = client.responses.create(
    model="gpt-6-astra",
    input="Generate an image of gray tabby cat hugging an otter with an orange scarf",
    tools=[{"type": "image_generation", "model": "gpt-image-2.5-sunburst"}],
)

# Save the image to a file
image_data = [
    output.result
    for output in response.output
    if output.type == "image_generation_call"
]

if image_data:
    image_base64 = image_data[0]
    with open("otter.png", "wb") as f:
        f.write(base64.b64decode(image_base64))

ファイル ID または Base64 データを使って入力画像を指定できます。

画像生成ツールを必ず呼び出すには、tool_choice パラメーターに {"type": "image_generation"} を指定します。

ツールのオプション

画像生成ツールのパラメーターで、以下の出力オプションを設定できます。

  • サイズ:画像の幅と高さ(例:1024 × 1024、1024 × 1536)
  • 品質:レンダリング品質(例:低、中、高)
  • 形式:出力ファイルの形式
  • 圧縮:JPEG 形式と WebP 形式の圧縮レベル(0~100%)
  • 背景:透明、不透明、または自動選択
  • アクション:画像の生成と編集のどちらを行うかをモデルに任せるか、リクエストで指定するか

size、quality、background には auto を指定できます。この場合、モデルがプロンプトに応じて最適な設定を自動で選択します。

gpt-image-2.5-sunburst と gpt-image-2.5-flare では、quality に xhigh と max も指定できます。それ以前の GPT Image モデルでは、これらの値は使用できません。品質のデフォルトは引き続き auto です。

gpt-image-2 では、size に解像度の制約を満たすサイズを柔軟に指定できます。透明な背景はプレビュー機能として利用できます。使用するには background: "transparent" を指定してください。出力形式には png(デフォルト)または webp を使用してください。jpeg は透明な背景に対応していません。

各オプションの詳細は、画像生成ガイドをご覧ください。

Responses API の画像生成ツールを使うと、対応する GPT Image モデルは、新しい画像を生成するか、会話内の既存の画像を編集するかを判断できます。この動作は、任意の action パラメーターで制御できます。判断をモデルに任せる場合は action を auto のままにします。必ず生成する場合は generate を、必ず編集する場合は edit を指定します。省略時は auto です。

書き換え後のプロンプト

画像生成ツールを使用すると、gpt-5.5 などのメインモデルが、より良い結果が得られるようにプロンプトを自動で書き換えます。

書き換え後のプロンプトは、画像生成ツールの呼び出し結果の revised_prompt フィールドで確認できます。

{
  "id": "ig_123",
  "type": "image_generation_call",
  "status": "completed",
  "revised_prompt": "A gray tabby cat hugging an otter. The otter is wearing an orange scarf. Both animals are cute and friendly, depicted in a warm, heartwarming style.",
  "result": "..."
}

プロンプトの書き方のヒント

画像生成では、プロンプトに draw(描く)や edit(編集する)のような動作を表す言葉を使うと、より良い結果が得られます。

たとえば、画像を組み合わせたい場合は、combine(組み合わせる)や merge(合成する)とだけ書く代わりに、「1 枚目の画像を編集して、2 枚目の画像にあるこの要素を追加してください」のように編集内容を指定できます。

複数ターンでの画像編集

以前のレスポンス ID または画像 ID を参照すると、同じ画像を繰り返し編集できます。会話を重ねながら画像を調整できます。

複数ターンでの画像生成
from openai import OpenAI
import base64

client = OpenAI()

response = client.responses.create(
    model="gpt-6-astra",
    input="Generate an image of gray tabby cat hugging an otter with an orange scarf",
    tools=[{"type": "image_generation", "model": "gpt-image-2.5-sunburst"}],
)

image_data = [
    output.result
    for output in response.output
    if output.type == "image_generation_call"
]

if image_data:
    image_base64 = image_data[0]

    with open("cat_and_otter.png", "wb") as f:
        f.write(base64.b64decode(image_base64))


# Follow up

response_fwup = client.responses.create(
    model="gpt-6-astra",
    previous_response_id=response.id,
    input="Now make it look realistic",
    tools=[{"type": "image_generation", "model": "gpt-image-2.5-sunburst"}],
)

image_data_fwup = [
    output.result
    for output in response_fwup.output
    if output.type == "image_generation_call"
]

if image_data_fwup:
    image_base64 = image_data_fwup[0]
    with open("cat_and_otter_realistic.png", "wb") as f:
        f.write(base64.b64decode(image_base64))

ストリーミング

画像生成ツールでは、最終画像が完成するまでの途中経過を画像としてストリーミングできます。ユーザーは早い段階で生成中の画像を確認できるため、体感上の待ち時間が短くなります。

途中経過として送信する画像の枚数(1~3 枚)は、partial_images パラメーターで指定できます。

画像のストリーミング
from openai import OpenAI
import base64

client = OpenAI()


def save_base64_image(filename, image_base64):
    image_bytes = base64.b64decode(image_base64)
    with open(filename, "wb") as f:
        f.write(image_bytes)


stream = client.responses.create(
    model="gpt-6-astra",
    input="Draw a gorgeous image of a river made of white owl feathers, snaking its way through a serene winter landscape",
    stream=True,
    tools=[
        {"type": "image_generation", "model": "gpt-image-2.5-sunburst", "partial_images": 2}
    ],
)

for event in stream:
    if event.type == "response.image_generation_call.partial_image":
        idx = event.partial_image_index
        save_base64_image(f"river-partial-{idx}.png", event.partial_image_b64)
    elif event.type == "response.completed":
        image_data = [
            output.result
            for output in event.response.output
            if output.type == "image_generation_call"
        ]

        if image_data:
            save_base64_image("river-final.png", image_data[0])

対応モデル

以下は、Responses API の画像生成ツールへの対応がドキュメントに明記されているモデルのうち、非推奨になっていないものです。トップレベルの model フィールドには、以下のモデル ID を指定してください。提供状況と利用要件は、各モデルのページで確認できます。

モデルの提供状況と提供終了日については、廃止情報をご覧ください。