影像生成
OpenAI Images 格式的文生圖與圖片編輯 API。各渠道支援的模型(DALL·E 3、GPT-Image、Seedream 等)略有差異,以下為通用欄位。
生成圖片
POST /v1/images/generations请求REQUEST
POST
https://test.kailin.com.cn/v1/images/generations返回 url 为临时地址,请及时转存;b64_json 模式返回体积较大,渲染会稍慢。
响应RESPONSE
填写参数并发送请求,响应会显示在这里
請求
curl https://test.kailin.com.cn/v1/images/generations \
-H "Content-Type: application/json" \
-H "Authorization: Bearer sk-your-token" \
-d '{
"model": "dall-e-3",
"prompt": "A cyberpunk city at night, neon lights, reflections after rain",
"n": 1,
"size": "1024x1792"
}'
請求主體參數
| 參數 | 類型 | 必填 | 說明 |
|---|---|---|---|
model | string | 否 | 預設 dall-e-2;可用 dall-e-3、gpt-image-1 等 |
prompt | string | 是 | 畫面描述,DALL·E 3 最長 4000 字元 |
n | integer | 否 | 生成張數 1–10(DALL·E 3 僅支援 1) |
size | string | 否 | 解析度:1024x1024 / 1792x1024 / 1024x1792(DALL·E 3);256/512/1024x1024(DALL·E 2);auto/1024x1536/1536x1024(GPT-Image) |
quality | string | 否 | standard / hd(DALL·E 3);low/medium/high/auto(GPT-Image) |
response_format | string | 否 | url(預設)或 b64_json(GPT-Image 固定回傳 b64) |
style | string | 否 | DALL·E 3 專屬:vivid / natural |
seed | integer | 否 | 隨機種子 |
回應
{
"created": 1730000000,
"data": [
{
"url": "https://oss.example.com/img/abc.png",
"revised_prompt": "A cyberpunk city at night…"
}
]
}
response_format: "b64_json" 時 data[].b64_json 為 Base64 圖片資料。url 結果是上游的暫時位址,有效期限有限,請盡快轉存。
編輯圖片
POST /v1/images/edits以 multipart/form-data 上傳 原始圖片,再透過提示詞進行修改(GPT-Image / DALL·E 2 支援):
curl https://test.kailin.com.cn/v1/images/edits \
-H "Authorization: Bearer sk-your-token" \
-F "model=gpt-image-1" \
-F "prompt=Replace the background with a seaside at dusk" \
-F "image=@/path/to/input.png"
| 欄位 | 類型 | 必填 | 說明 |
|---|---|---|---|
image | file | 是 | 原始圖片(png/jpeg/webp,GPT-Image 可傳多張 image[]) |
prompt | string | 是 | 編輯指令 |
mask | file | 否 | 遮罩,透明區域為可編輯區域(DALL·E 2) |
model | string | 否 | gpt-image-1 / dall-e-2 |
n / size / quality | - | 否 | 與生成 API 相同 |
舊版 API
POST /v1/images/variations(以原圖生成變體,DALL·E 2)與 POST /v1/edits(舊路徑)同樣提供代理,參數同上,僅建議在相容舊程式碼時使用。
提示
Nano Banana(Gemini 影像)等模型同樣可用 OpenAI 格式呼叫——只要把 model 設為對應名稱即可,無法識別的參數會原樣轉傳給上游。