图像生成
了解如何使用我们的 DALL·E 型号
介绍
图像 API 提供了三种与图像交互的方法:
- 根据文本提示从头开始创建图像
- 根据新的文本提示创建现有图像的编辑
- 创建现有图像的变体
本指南介绍了使用这三个 API 终结点的基础知识以及有用的代码示例。要了解它们的实际效果,请查看我们的 DALL·E 预览应用程序。
图像 API 处于测试阶段。在此期间,API 和模型将根据你的反馈进行改进。为了确保所有用户都能舒适地制作原型,默认速率限制为每分钟 50 张图像。您可以在我们的速率限制指南中了解有关[速率限制](https://platform.openai.com/docs/guides/rate-limits)的更多信息。
创建图像
编辑图像
图像变化
API
Create image
给定提示符和/或输入图像,模型将生成新图像。
Example request
curl https://api.openai.com/v1/images/generations \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-d '{
"prompt": "A cute baby sea otter",
"n": 2,
"size": "1024x1024"
}'
Parameters
{
"prompt": "A cute baby sea otter",
"n": 2,
"size": "1024x1024"
}
{
"created": 1589478378,
"data": [
{
"url": "https://..."
},
{
"url": "https://..."
}
]
}
Request body
prompt string Required
A text description of the desired image(s). The maximum length is 1000 characters.
n integer Optional Defaults to 1
The number of images to generate. Must be between 1 and 10.
size string Optional Defaults to 1024x1024
The size of the generated images. Must be one of 256x256, 512x512, or 1024x1024.
response_format string Optional Defaults to url
The format in which the generated images are returned. Must be one of url or b64_json.
user string Optional
A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse.
Create image edit
根据原始图像和提示创建编辑或扩展的图像。
Example request
curl https://api.openai.com/v1/images/edits \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-F image="@otter.png" \
-F mask="@mask.png" \
-F prompt="A cute baby sea otter wearing a beret" \
-F n=2 \
-F size="1024x1024"
Response
{
"created": 1589478378,
"data": [
{
"url": "https://..."
},
{
"url": "https://..."
}
]
}
Request body
image string Required
The image to edit. Must be a valid PNG file, less than 4MB, and square. If mask is not provided, image must have transparency, which will be used as the mask.
mask string Optional
An additional image whose fully transparent areas (e.g. where alpha is zero) indicate where image should be edited. Must be a valid PNG file, less than 4MB, and have the same dimensions as image.
prompt string Required
A text description of the desired image(s). The maximum length is 1000 characters.
n integer Optional Defaults to 1
The number of images to generate. Must be between 1 and 10.
size string Optional Defaults to 1024x1024
The size of the generated images. Must be one of 256x256, 512x512, or 1024x1024.
response_format string Optional Defaults to url
The format in which the generated images are returned. Must be one of url or b64_json.
user string Optional
A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. Learn more.
Create image variation
创建给定图像的变体。
Example request
curl https://api.openai.com/v1/images/variations \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-F image="@otter.png" \
-F n=2 \
-F size="1024x1024"
Response
{
"created": 1589478378,
"data": [
{
"url": "https://..."
},
{
"url": "https://..."
}
]
}
Request body
image string Required
The image to use as the basis for the variation(s). Must be a valid PNG file, less than 4MB, and square.
n integer Optional Defaults to 1
The number of images to generate. Must be between 1 and 10.
size string Optional Defaults to 1024x1024
The size of the generated images. Must be one of 256x256, 512x512, or 1024x1024.
response_format string Optional Defaults to url
The format in which the generated images are returned. Must be one of url or b64_json.
user string Optional
A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. Learn more.