ドキュメント · 導入

画像生成

POST /v1/images/generations creates images from a text prompt. Pick a model of type "Image" from the catalog.

本文は現在英語版のみ提供しています。

curl https://<your-endpoint>/v1/images/generations \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-image-1",
    "prompt": "A lighthouse on a cliff at sunset, watercolor",
    "size": "1024x1024"
  }'

Common parameters

ParameterDescription
modelRequired. An image model ID
promptRequired. What to draw — be specific
sizeFor example 1024x1024; allowed values depend on the model
nNumber of images
Supported sizes, counts and return format (url or b64_json) vary by model — check the model page. Returned URLs are usually temporary, so download them promptly.

Saving the result

import base64
from openai import OpenAI

client = OpenAI(base_url="https://<your-endpoint>/v1", api_key="YOUR_API_KEY")

img = client.images.generate(
    model="gpt-image-1",
    prompt="A minimalist poster of a mountain lake, flat colors",
    size="1024x1024",
    n=1,
)
item = img.data[0]
if item.b64_json:                      # some models return base64
    open("out.png", "wb").write(base64.b64decode(item.b64_json))
else:                                  # others return a temporary URL; download it promptly
    print(item.url)

Image models may be billed per request or per token — see Pricing.