跳到主要內容

影像生成

OpenAI Images 格式的文生圖與圖片編輯 API。各渠道支援的模型(DALL·E 3、GPT-Image、Seedream 等)略有差異,以下為通用欄位。

生成圖片​

POST /v1/images/generations
请求REQUEST
POSThttps://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"
}'

請求主體參數​

參數類型必填說明
modelstring否預設 dall-e-2;可用 dall-e-3、gpt-image-1 等
promptstring是畫面描述,DALL·E 3 最長 4000 字元
ninteger否生成張數 1–10(DALL·E 3 僅支援 1)
sizestring否解析度:1024x1024 / 1792x1024 / 1024x1792(DALL·E 3);256/512/1024x1024(DALL·E 2);auto/1024x1536/1536x1024(GPT-Image)
qualitystring否standard / hd(DALL·E 3);low/medium/high/auto(GPT-Image)
response_formatstring否url(預設)或 b64_json(GPT-Image 固定回傳 b64)
stylestring否DALL·E 3 專屬:vivid / natural
seedinteger否隨機種子

回應​

{
"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"
欄位類型必填說明
imagefile是原始圖片(png/jpeg/webp,GPT-Image 可傳多張 image[])
promptstring是編輯指令
maskfile否遮罩,透明區域為可編輯區域(DALL·E 2)
modelstring否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 設為對應名稱即可,無法識別的參數會原樣轉傳給上游。