画像生成
POST /v1/images/generations
テキストプロンプトから画像を生成します。OpenAI 互換 —— OpenAI の画像 API と同じエンドポイント・同じ SDK 呼び出し(client.images.generate)で、1つの API key により OpenAI、Google、Alibaba、ByteDance の画像モデルへルーティングします。
現在、アクセスは許可リスト制(特定の workspace / ユーザー)で制限されています。許可リストに登録されていない key は 403 image_gateway_not_allowlisted を受け取ります。あなたの workspace で有効化するには、管理者にお問い合わせください。
リクエストボディ
| パラメータ | 型 | 説明 |
|---|---|---|
model* | string | 使用する画像モデル(例:gpt-image-1、qwen-image-2.0、seedream-4-0-250828)。利用可能なすべてのモデルは GET /v1/images/models で一覧表示できます。 |
prompt* | string | 希望する画像のテキスト説明。 |
n | integer | 生成する画像の枚数(デフォルトは 1)。 |
size | string | 画像サイズ(例:1024x1024)。対応状況はモデルによって異なります —— 特定のサイズのみ受け付けるものもあります。省略するとモデルのデフォルト値が使用されます。 |
quality | string | モデルが対応している場合の品質/レンダリングのヒント(例:standard、hd)。 |
response_format | string | b64_json(デフォルト)は base64 の画像バイトを返します。url は上流が対応している場合に取得可能な URL を返します。 |
seed | integer | 再現可能な出力のための任意のシード(対応している場合)。 |
negative_prompt | string | 避けたい内容を記述する任意のテキスト(対応している場合)。 |
image | string | string[] | 画像から画像への入力:base64 または data URI(文字列、または複数の参照画像の場合は配列)。これを含めると、テキストのみから生成するのではなく、プロンプトに従って入力画像を編集します。http(s) URL はまだ対応していません。 |
利用可能なモデル
モデルの利用可否はデプロイ環境によって異なります。最新でコンプライアンスに対応した一覧は次から取得します: GET /v1/images/models で取得できます。代表的なモデル:
どのモデルを選べばいいか迷ったら?必要な条件で選びましょう
| 必要なもの | 備考 | 推奨モデル |
|---|---|---|
| 最も安価 | $0.03 / image | wan2.7-image seedream-4-0-250828 |
| 最高品質 | — | gemini-3-pro-image-preview gpt-image-2 |
| 画像編集(image-to-image) | image フィールドを送信 | gpt-image-2 seedream-4-0-250828 wan2.7-image |
| データを中国本土の外に保持 | 欧米ベンダー | gpt-image-2 gemini-3-pro-image-preview |
| 低速 / 越境のクライアント回線 | response_format: "url" | wan2.7-image qwen-image-2.0 |
| モデル | プロバイダー | 料金 | レスポンス | 編集 (i2i) | 備考 |
|---|---|---|---|---|---|
gpt-image-2 | OpenAI | token · $5→$30 /1M | b64 only | ≤16 | フラッグシップ。組織認証が必要 |
gpt-image-1.5 | OpenAI | token · $5→$32 /1M | b64 only | ≤16 | 非推奨 |
gpt-image-1 | OpenAI | token · $5→$40 /1M | b64 only | ≤16 | 非推奨 |
gpt-image-1-mini | OpenAI | token · $2→$8 /1M | b64 only | ≤16 | 非推奨。OpenAI で最も安価 |
gemini-3-pro-image-preview | token · $2→$120 /1M | b64 only | ≤14 | プレビュー。最高品質 | |
gemini-3.1-flash-image-preview | token · $0.5→$60 /1M | b64 only | ≤14 | プレビュー | |
gemini-3.1-flash-lite-image | token · $0.25→$30 /1M | b64 only | ≤14 | プレビュー。最速の Gemini | |
gemini-2.5-flash-image | token · $0.3→$30 /1M | b64 only | ≤3 | 2026-10-02 に提供終了 | |
qwen-image-2.0 | Alibaba | $0.035 / image | b64 · url ✓ | ≤3 | — |
qwen-image-2.0-pro | Alibaba | $0.075 / image | b64 · url ✓ | ≤3 | より高品質 |
wan2.7-image | Alibaba | $0.03 / image | b64 · url ✓ | ≤9 | 最も安価 |
wan2.7-image-pro | Alibaba | $0.075 / image | b64 · url ✓ | ≤9 | — |
seedream-4-0-250828 | ByteDance | $0.03 / image | b64 · url ✓ | ≤10 | 1024×1024 に対応 |
seedream-4-5-251128 | ByteDance | $0.04 / image | b64 · url ✓ | ≤10 | size ≥ 1920×1920 |
seedream-5-0-260128 | ByteDance | $0.035 / image | b64 · url ✓ | ≤10 | 5.0 Lite; size ≥ 1920×1920 |
Price:token · $in→$out /1M = 使用量に基づく課金(OpenAI / Google)。$/image = 生成画像 1 枚あたりの定額。Response:b64 · url ✓ のモデルは、署名付きのベンダーホスト URL を返すこともできます(response_format: "url"、有効期間 ~24 h)。ダウンロード速度はベンダーに依存します:Alibaba の URL はグローバル高速化 CDN を経由し(中国本土を含めどこでも高速)、ByteDance seedream の URL はシンガポールのオブジェクトストレージから配信されます(海外クライアントには高速、中国本土からは低速)。b64 only のモデルは response_format: "url" を 400 url_not_supported で拒否します。Edit (i2i) = すべてのモデルが image-to-image に対応します(image フィールドを送信)。値は参照画像の最大数です。
画像から画像へ(編集)
同じリクエストに image フィールドを追加すると、入力画像を編集または参照できます。gpt-image、gemini-*-image、qwen-image / wan2.7、seedream で対応しています(各モデルには受け付けられる入力画像の枚数に上限があります)。画像は base64 または data URI として送信します。複数の参照画像を渡す場合は配列で指定します。
curl https://synthorai.io/v1/images/generations \
-H "Authorization: Bearer $SYNTHORAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2",
"prompt": "add a small red party hat on the main subject",
"image": "'"$(base64 -i input.png)"'"
}' レスポンス形式
次を設定します: response_format: b64_json は base64 の画像バイトを返します(デフォルト); url は上流が対応している場合に取得可能な URL を返します。レスポンスは OpenAI の images API と同じ形式です:{ created, data: [{ b64_json | url }] }。
url is supported only where the upstream itself hands back a CDN URL — currently the Alibaba and ByteDance families (qwen-image*, wan*, seedream*); the image downloads from the vendor's CDN via a pre-signed URL valid ~24 hours. OpenAI and Google models (gpt-image*, gemini*) are b64-only: requesting url there returns 400 url_not_supported — rejected before generation, nothing is billed. Check per model via the supports_url field of GET /v1/images/models, or the model table above.
Complete example — url mode
Generate with response_format: "url", read data[0].url from the response, then download the image from the vendor's CDN — a full round-trip you can paste into a terminal:
# 1) Generate — ask for a URL instead of inline base64
curl https://synthorai.io/v1/images/generations \
-H "Authorization: Bearer $SYNTHORAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "wan2.7-image",
"prompt": "a serene mountain lake at sunrise",
"response_format": "url"
}'
# → 200 in ~15–30 s. Tiny JSON body — no image bytes inline:
{
"created": 1783064343,
"data": [
{
"url": "https://dashscope-463f.oss-accelerate.aliyuncs.com/1d/8a/20260703/xxxx.png?Expires=1783151704&OSSAccessKeyId=LTAI...&Signature=bvTa..."
}
]
}
# 2) Download from the vendor CDN — the URL is pre-signed, no auth header needed
curl -o out.png "https://dashscope-463f.oss-accelerate.aliyuncs.com/1d/8a/20260703/xxxx.png?Expires=1783151704&OSSAccessKeyId=LTAI...&Signature=bvTa..." The URL is pre-signed — anyone with it can download, no auth header needed — and expires in ~24 hours: fetch promptly and re-host the file if you need it long-term. Typical end-to-end: ~15–30 s generation + sub-second CDN download.
Latency, large responses & timeouts
Generation time varies by model: qwen-image-2.0 typically returns in ~5–10 s, while wan2.7-image and seedream-class models take ~15–30 s (longer at 2K+ sizes). The gateway allows up to 180 s per request and returns 504 generation_timeout beyond that — this API itself never returns 408.
The default response_format=b64_json embeds the full image in the response body (2–3 MB of base64 for large models). On slow or long-haul client links, downloading that body can add minutes and trip your HTTP client's or relay gateway's own timeout — typically surfaced on your side as 408 or a timeout error.
大きな画像モデルや配信リージョンから遠いクライアントでは、response_format: "url" を推奨します。レスポンスボディが非常に小さく、画像はベンダーから直接ダウンロードされます。ベンダーの違い:Alibaba(qwen-image*/wan*)の URL はグローバル高速化 CDN を経由し、中国本土からでも高速です。ByteDance seedream の URL はシンガポールのオブジェクトストレージから配信され、海外では高速、中国本土からは低速です。URL は署名付きで約 24 時間有効です。速やかに取得し、永続化が必要な場合は再ホストしてください。低速回線で b64_json を使わざるを得ない場合は、クライアントのタイムアウトを ≥180 s に引き上げてください。
課金
成功時(HTTP 200)のみ課金されます。ほとんどのモデルは画像単位(枚数 × 単価)で課金されます。トークン使用量を返す OpenAI gpt-image-* モデルはトークン単位で課金されます。各課金は request_id、モデル、費用とともに記録され、追跡可能です。
一部のモデルは明示的な size を拒否します(例:seedream-4-5-251128 / seedream-5-0-260128 は size=1024x1024 で 400 を返します)。InvalidParameter:size エラーが発生した場合は、size を省略してモデルのデフォルト値を使用してください。
例 — curl
curl https://synthorai.io/v1/images/generations \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-1",
"prompt": "a serene mountain lake at sunrise, photorealistic",
"n": 1,
"size": "1024x1024"
}' 例 — Python(OpenAI SDK)
from openai import OpenAI
import base64
client = OpenAI(base_url="https://synthorai.io/v1", api_key="YOUR_API_KEY")
resp = client.images.generate(
model="qwen-image-2.0",
prompt="a serene mountain lake at sunrise, photorealistic",
n=1,
size="1024x1024",
)
# Default response_format is b64_json
img = base64.b64decode(resp.data[0].b64_json)
with open("out.png", "wb") as f:
f.write(img) 例 — Node(OpenAI SDK)
import OpenAI from "openai";
import fs from "node:fs";
const client = new OpenAI({
baseURL: "https://synthorai.io/v1",
apiKey: process.env.SYNTHORAI_API_KEY,
});
const resp = await client.images.generate({
model: "seedream-4-0-250828",
prompt: "a serene mountain lake at sunrise, photorealistic",
n: 1,
});
fs.writeFileSync("out.png", Buffer.from(resp.data[0].b64_json, "base64")); 冪等性
次を渡します: X-Idempotency-Key ヘッダーを指定すると、リトライが安全になります。同じ key での再リクエストは、2回目の生成(および課金)を行わず 409 を返します。画像生成は遅くリトライが発生しやすいため、これにより二重課金を防ぎます。