创建图片
POST /v1/images/generations根据文本提示生成图像。
请求体参数
prompt: string所需图像的文本描述。GPT 图像模型最大长度为 32000 字符,
dall-e-2为 1000 字符,dall-e-3为 4000 字符。background: optional "transparent" 或 "opaque" 或 "auto"设置生成图像的背景透明度。仅 GPT 图像模型支持此参数。可选值:
transparent(透明)、opaque(不透明)或auto(自动,默认值)。当使用auto时,模型将自动确定最佳背景。如果设为
transparent,输出格式需支持透明度,因此应为png(默认值)或webp。"transparent""opaque""auto"
model: optional string 或 ImageModel用于图像生成的模型。可选值:
dall-e-2、dall-e-3,或 GPT 图像模型(gpt-image-1、gpt-image-1-mini、gpt-image-1.5)。默认值为dall-e-2,除非使用了 GPT 图像模型特有的参数。stringImageModel = "gp-im-2""gp-im-2"
moderation: optional "low" 或 "auto"控制 GPT 图像模型生成图像的内容审核级别。可选
low(较低限制)或auto(自动,默认值)。"low""auto"
n: optional number生成的图像数量。取值范围 1–10。
dall-e-3仅支持n=1。output_compression: optional number生成图像的压缩级别(0–100%)。仅 GPT 图像模型在
webp或jpeg输出格式下支持,默认值为 100。output_format: optional "png" 或 "jpeg" 或 "webp"生成图像的返回格式。仅 GPT 图像模型支持。可选值:
png、jpeg或webp。"png""jpeg""webp"
partial_images: optional number生成的中间过程图像数量。用于流式返回中间图像的场景。取值 0–3。设为 0 时,响应将在一次流事件中返回单张完整图像。注意:如果完整图像生成速度较快,最终图像可能会在达到指定中间图像数量之前发送。
quality: optional "standard" 或 "hd" 或 "low" 等生成图像的质量。
auto(默认值)将自动为给定模型选择最佳质量。high、medium和low适用于 GPT 图像模型。hd和standard适用于dall-e-3。standard是dall-e-2的唯一选项。"standard""hd""low""medium""high""auto"
response_format: optional "url" 或 "b64_json"使用
dall-e-2和dall-e-3时生成图像的返回格式。可选url或b64_json。URL 在图像生成后 60 分钟内有效。GPT 图像模型不支持此参数,其始终返回 base64 编码的图像。"url""b64_json"
size: optional string 或 "auto" 或 "1024x1024" 或 "1536x1024" 等生成图像的尺寸。对于
gp-im-2,支持WIDTHxHEIGHT格式的任意分辨率,例如1536x864。宽和高都必须能被 16 整除,且宽高比需在 1:3 到 3:1 之间。分辨率超过2560x1440为实验性支持,最大分辨率为3840x2160。GPT 图像模型支持标准尺寸1024x1024、1536x1024和1024x1536;auto适用于允许自动尺寸的模型。对于dall-e-2,可使用256x256、512x512或1024x1024。对于dall-e-3,可使用1024x1024、1792x1024或1024x1792。string"auto" 或 "1024x1024" 或 "1536x1024" 等生成图像的尺寸。对于
gp-im-2,支持WIDTHxHEIGHT格式的任意分辨率,例如1536x864。宽和高都必须能被 16 整除,且宽高比需在 1:3 到 3:1 之间。分辨率超过2560x1440为实验性支持,最大分辨率为3840x2160。GPT 图像模型支持标准尺寸1024x1024、1536x1024和1024x1536;auto适用于允许自动尺寸的模型。对于dall-e-2,可使用256x256、512x512或1024x1024。对于dall-e-3,可使用1024x1024、1792x1024或1024x1792。"auto""1024x1024""1536x1024""1024x1536""256x256""512x512""1792x1024""1024x1792"
stream: optional boolean以流式模式生成图像。默认为
false。仅 GPT 图像模型支持此参数。style: optional "vivid" 或 "natural"生成图像的风格。仅
dall-e-3支持。可选vivid(生动)或natural(自然)。vivid使模型倾向于生成超现实和戏剧性的图像,natural则生成更自然、不那么超现实的图像。"vivid""natural"
user: optional string代表最终用户的唯一标识符,可帮助 OpenAI 监控和检测滥用行为。
请求示例
curl https://neolink.com/api/v1/images/generations \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-d '{
"model": "gp-im-2",
"prompt": "一只可爱的海獭宝宝",
"n": 1,
"size": "1024x1024"
}'curl https://neolink.com/api/v1/images/generations \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-d '{
"model": "gp-im-2",
"prompt": "一只可爱的海獭宝宝",
"n": 1,
"size": "1024x1024",
"stream": true
}' \
--no-buffer返回结果
ImagesResponse 对象 { created, background, data 等 }图像生成端点的响应。
created: number图像创建时的 Unix 时间戳(秒)。
background: optional "transparent" 或 "opaque"图像生成所使用的背景参数。
transparent或opaque。"transparent""opaque"
data: optional array of Image生成的图像列表。
b64_json: optional string生成图像的 base64 编码 JSON。GPT 图像模型默认返回此字段;对于
dall-e-2和dall-e-3,仅在response_format设为b64_json时存在。revised_prompt: optional string仅
dall-e-3支持,用于生成图像的修订后提示词。url: optional string使用
dall-e-2或dall-e-3时,如果response_format设为url(默认值),返回生成图像的 URL。GPT 图像模型不支持此字段。
output_format: optional "png" 或 "webp" 或 "jpeg"图像生成的输出格式。可选
png、webp或jpeg。"png""webp""jpeg"
quality: optional "low" 或 "medium" 或 "high"生成图像的质量。可选
low、medium或high。"low""medium""high"
size: optional "1024x1024" 或 "1024x1536" 或 "1536x1024"生成图像的尺寸。可选
1024x1024、1024x1536或1536x1024。"1024x1024""1024x1536""1536x1024"
usage: optional object { input_tokens, input_tokens_details, output_tokens 等 }仅
gpt-image-1支持,图像生成的令牌用量信息。input_tokens: number输入提示中的令牌数(图像和文本)。
input_tokens_details: object { image_tokens, text_tokens }图像生成的输入令牌详情。
image_tokens: number输入提示中的图像令牌数。
text_tokens: number输入提示中的文本令牌数。
output_tokens: number模型生成的输出令牌数。
total_tokens: number图像生成所使用的总令牌数(图像和文本)。
output_tokens_details: optional object { image_tokens, text_tokens }图像生成的输出令牌详情。
image_tokens: number模型生成的图像输出令牌数。
text_tokens: number模型生成的文本输出令牌数。
响应
{
"created": 1713833628,
"data": [
{
"b64_json": "..."
}
],
"usage": {
"total_tokens": 100,
"input_tokens": 50,
"output_tokens": 50,
"input_tokens_details": {
"text_tokens": 10,
"image_tokens": 40
}
}
}event: image_generation.partial_image
data: {"type":"image_generation.partial_image","b64_json":"...","partial_image_index":0}
event: image_generation.completed
data: {"type":"image_generation.completed","b64_json":"...","usage":{"total_tokens":100,"input_tokens":50,"output_tokens":50,"input_tokens_details":{"text_tokens":10,"image_tokens":40}}}