Skip to content

图片生成 / dall-e-3

POST  v1/images/generations

根据提示词以及其他参数创建图片

官方文档:https://platform.openai.com/docs/api-reference/images/create

请求参数

Authorization

在 Header 添加参数 Authorization,其值为在 Bearer 之后拼接 Token。

Authorization: Bearer ******************

Body 参数

Content-Type: application/json

参数名类型必填说明
modelstring必需模型名称。用于指定图像生成的模型(例如 dall-e-2dall-e-3)。
qualitystring必需生成图片的质量。hd 选项会生成更细致和一致的图片。仅 dall-e-3 支持此参数。
promptstring必需提示词。期望生成图片的文本描述。 • dall-e-2:最大长度 1000 字符 • dall-e-3:最大长度 4000 字符 提示:描述需具体详细,包含关键视觉元素、艺术风格及构图视角。
ninteger必需生成数量。要生成的图片数量(范围 1-10)。 • 注意:dall-e-3 仅支持 n=1
sizestring必需图片尺寸。 • dall-e-2:支持 256x256, 512x512, 1024x1024 • dall-e-3:支持 1024x1024 (正方形), 1792x1024 (横向), 1024x1792 (纵向)
stylestring可选图片风格。仅 dall-e-3 支持。 • vivid:超现实、戏剧性风格。 • natural:更自然、写实风格。
userstring可选用户标识。代表最终用户的唯一 ID,用于帮助 OpenAI 监控和检测滥用行为。

请求示例 (JSON)

{
    "model": "dall-e-3",
    "quality": "hd",
    "prompt": "a white siamese cat",
    "n": 1,
    "size": "1024x1024"
}

返回响应

200 成功

Content-Type: application/json

响应参数

字段名类型必填说明
createdinteger必需创建时间戳。通常是 Unix 时间戳,表示任务创建或完成的时间。
dataarray [object]必需数据列表。包含生成的图像信息数组,数组中的每个对象代表一张生成的图片。
└─ revised_promptstring可选经过系统优化或人工修改后的最终提示词。
└─ urlstring可选图片地址。生成图片的直接访问链接(如果请求中指定了返回 URL)。

响应示例

{
    "created": 1760483997,
    "data": [
        {
            "revised_prompt": "A white Siamese cat with sleek fur and bright blue eyes, sitting elegantly on a soft cushion by a sunny window. The sunlight is streaming through the window, creating a warm and cozy ambiance. The background features a blurred view of a garden outside the window, hinting at flowers and greenery, while the cat exudes an air of grace and poise.",
            "url": "https://dalleprodsec.blob.core.windows.net/private/images/971071d6-3b7f-4a71-ab81-a5799a148628/generated_00.png?se=2025-10-15T23%3A20%3A12Z&sig=ko7zSeMfSXPv2X5o0RJal5KbURn5qUUgCHtwMEmJHtk%3D&ske=2025-10-15T19%3A00%3A58Z&skoid=e52d5ed7-0657-4f62-bc12-7e5dbb260a96&sks=b&skt=2025-10-08T19%3A00%3A58Z&sktid=33e01921-4d64-4f8c-a055-5bdaffd5e33d&skv=2020-10-02&sp=r&spr=https&sr=b&sv=2020-10-02"
        }
    ]
}

示例代码

python
import http.client
import json

conn = http.client.HTTPSConnection("nxaiapp.com")
payload = json.dumps({
   "model": "dall-e-3",
   "quality": "hd",
   "prompt": "a white siamese cat",
   "n": 1,
   "size": "1024x1024"
})
headers = {
   'Authorization': 'Bearer <token>',
   'Content-Type': 'application/json'
}
conn.request("POST", "/v1/images/generations", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))