- OpenAI
- 平台接口
- 音乐模型
- 图像模型
- MidJourney
- ideogram
- FalAI
- 即梦
- Kling
- 视频模型
图像生成
POST
/v1/images/generations
Images
请求参数
Authorization
在 Header 添加参数
Authorization
,其值为在 Bearer 之后拼接 Token示例:
Authorization: Bearer ********************
Body 参数application/json
prompt
string
必需
gpt-image-1
的最大长度为32000字符,dall-e-2
为1000字符,dall-e-3
为4000字符。示例值:
A cute baby sea otter
model
可选
dall-e-2
、dall-e-3
或 gpt-image-1
之一。除非使用了针对 gpt-image-1
的特定参数,否则默认为 dall-e-2
。Any of
One of
dall-e-2
、dall-e-3
或 gpt-image-1
之一。除非使用了针对 gpt-image-1
的特定参数,否则默认为 dall-e-2
。默认值:
dall-e-2
示例值:
gpt-image-1
n
integer | null
可选
dall-e-3
,仅支持n=1
。>= 1<= 10
默认值:
1
示例值:
1
quality
enum<string> | enum<null>
可选
auto
(默认值)将自动为给定模型选择最佳质量。high
、medium
和 low
支持 gpt-image-1
。hd
和 standard
支持 dall-e-3
。standard
是 dall-e-2
的唯一选项。枚举值:
standardhdlowmediumhighauto
默认值:
auto
示例值:
medium
response_format
enum<string> | enum<null>
可选
dall-e-2
和 dall-e-3
生成的图像返回的格式。必须是 url
或 b64_json
之一。URL 在图像生成后仅在 60 分钟内有效。此参数不支持 gpt-image-1
,该模型将始终返回 base64 编码的图像。枚举值:
urlb64_json
默认值:
url
示例值:
url
output_format
enum<string> | enum<null>
可选
gpt-image-1
。必须是 png
、jpeg
或 webp
之一。枚举值:
pngjpegwebp
默认值:
png
示例值:
png
output_compression
integer | null
可选
gpt-image-1
的 webp
或 jpeg
输出格式,默认值为100。默认值:
100
示例值:
100
size
enum<string> | enum<null>
可选
gpt-image-1
,必须是 1024x1024
、1536x1024
(横向)、1024x1536
(纵向)或 auto
(默认值)之一;对于 dall-e-2
,必须是 256x256
、512x512
或 1024x1024
之一;对于 dall-e-3
,必须是 1024x1024
、1792x1024
或 1024x1792
之一。枚举值:
auto1024x10241536x10241024x1536256x256512x5121792x10241024x1792
默认值:
auto
示例值:
1024x1024
moderation
enum<string> | enum<null>
可选
gpt-image-1
生成的图像内容审核级别。必须是 low
(较宽松的过滤)或 auto
(默认值)。枚举值:
lowauto
默认值:
auto
示例值:
low
background
enum<string> | enum<null>
可选
gpt-image-1
。必须是以下之一:transparent
、opaque
或 auto
(默认值)。当使用 auto
时,transparent
,输出格式需要支持透明度,因此png
(默认值)或 webp
。枚举值:
transparentopaqueauto
默认值:
auto
示例值:
transparent
style
enum<string> | enum<null>
可选
dall-e-3
。必须是 vivid
或 natural
之一。Vivid 会使模型倾向于生成超现实且戏剧性的图像。Natural 会使模型生成更自然、较少超现实感的图像。枚举值:
vividnatural
默认值:
vivid
示例值:
vivid
示例
{
"prompt": "A cute baby sea otter",
"model": "string",
"n": 1,
"quality": "auto",
"response_format": "url",
"output_format": "png",
"output_compression": 100,
"size": "auto",
"moderation": "auto",
"background": "auto",
"style": "vivid"
}
示例代码
Shell
JavaScript
Java
Swift
Go
PHP
Python
HTTP
C
C#
Objective-C
Ruby
OCaml
Dart
R
请求示例请求示例
Shell
JavaScript
Java
Swift
curl --location --request POST 'https://api.uniapi.io/v1/images/generations' \
--header 'Content-Type: application/json' \
--data-raw '{
"prompt": "A cute baby sea otter",
"model": "string",
"n": 1,
"quality": "auto",
"response_format": "url",
"output_format": "png",
"output_compression": 100,
"size": "auto",
"moderation": "auto",
"background": "auto",
"style": "vivid"
}'
返回响应
🟢200成功
application/json
Body
来自图像生成端点的响应。
created
integer
必需
data
array[object (Image) {3}]
生成的图像列表。
b64_json
string
可选
gpt-image-1
的默认值,仅当 dall-e-2
和 dall-e-3
的 response_format
设置为 b64_json
时存在。url
string
可选
dall-e-2
或 dall-e-3
时, 如果将 response_format
设置为 url
(默认值),生成图像的 URL 将被返回。gpt-image-1
不支持此功能。revised_prompt
string
可选
dall-e-3
,用于生成图像的修订提示。usage
object
可选
gpt-image-1
,图像生成的令牌使用信息。total_tokens
integer
必需
input_tokens
integer
必需
output_tokens
integer
必需
input_tokens_details
object
必需
示例
{
"created": 0,
"data": [
{
"b64_json": "string",
"url": "string",
"revised_prompt": "string"
}
],
"usage": {
"total_tokens": 0,
"input_tokens": 0,
"output_tokens": 0,
"input_tokens_details": {
"text_tokens": 0,
"image_tokens": 0
}
}
}
修改于 2025-05-18 07:36:21