Chat(修改图片)
方法: POST路径: /v1/chat/completions
官方指南官方API文档 所有对话模型,都可使用此接口, 修改 model 属性为模型名 需要模型支持生图能力
请求参数
Header 参数
text
Content-Type
string
必需
示例:
application/json
Accept
string
必需
示例:
application/json
Authorization
string
可选
默认值:
Bearer {{YOUR_API_KEY}}Body 参数 application/json
text
model
enum<string>
必需
要使用的模型的 ID。有关哪些模型适用于聊天 API 的详细信息,请参阅
模型端点兼容性表。
枚举值:
gpt-image-1
gpt-4o-image
sora_image
flux-kontext-pro
支持所有 flux kontext 系列
nano-banana
doubao-seedream-4-0-250828
doubao-seededit-3-0-i2i-250628
nano-banana-hd
qwen-image-edit
messages
array
[object]
必需
以
聊天格式
生成聊天完成的消息。
role
string
可选
content
string
可选
stream
boolean
可选
如果设置,将发送部分消息增量,就像在 ChatGPT 中一样。当令牌可用时,令牌将作为纯数据
服务器发送事件
data: [DONE]
发送,流由消息终止。
有关示例代码
,请参阅 OpenAI Cookbook 。
示例
{
"model"
:
"gpt-4o-image"
,
"stream"
:
false
,
"messages"
:
[
{
"role"
:
"user"
,
"content"
:
[
{
"type"
:
"text"
,
"text"
:
"修改这个图片"
}
,
{
"type"
:
"image_url"
,
"image_url"
:
{
"url"
:
"https://github.com/dianping/cat/raw/master/cat-home/src/main/webapp/images/logo/cat_logo03.png"
}
}
,
{
"type"
:
"image_url"
,
"image_url"
:
{
"url"
:
"支持多图"
}
}
]
}
]
}请求示例代码
Shell
bash
curl --location --request POST '/v1/chat/completions' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer {{YOUR_API_KEY}}' \
--header 'Content-Type: application/json' \
--data-raw '{
"model": "gpt-4o-image",
"stream": false,
"messages": [
{
"role": "user",
"content": [
{
"type": "text",
"text": "修改这个图片"
},
{
"type": "image_url",
"image_url": {
"url": "https://github.com/dianping/cat/raw/master/cat-home/src/main/webapp/images/logo/cat_logo03.png"
}
},
{
"type": "image_url",
"image_url": {
"url": "支持多图"
}
}
]
}
]
}'返回响应
🟢 200 OK
内容类型: application/json
响应结构
text
id
string
必需
object
string
必需
created
integer
必需
choices
array
[object]
必需
index
integer
可选
message
object
可选
finish_reason
string
可选
usage
object
必需
prompt_tokens
integer
必需
completion_tokens
integer
必需
total_tokens
integer
必需示例
json
{
"id": "chatcmpl-123",
"object": "chat.completion",
"created": 1677652288,
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "\n\nHello there, how may I assist you today?"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 9,
"completion_tokens": 12,
"total_tokens": 21
}
}