messages[].content 数组的内容块里。图片用 image_url 块,PDF/文件用 file 块。来源三选一:图片可传 http(s) 链接或 data: 形式的 base64;文件可传 file_data(base64 data URI)或 Files API 上传后的 file_id。兼容性:base64(data URI)最通用最稳;外链由网关向源站拉取,部分逆向上游可能不支持; file_id需先调用/v1/files上传接口拿到 ID。
{
"model": "gpt-4o",
"messages": [
{
"role": "user",
"content": [
{ "type": "text", "text": "这张图里有什么?" },
{ "type": "image_url", "image_url": { "url": "https://example.com/a.png" } }
]
}
]
}{
"model": "gpt-4o",
"messages": [
{
"role": "user",
"content": [
{ "type": "text", "text": "这张图里有什么?" },
{ "type": "image_url", "image_url": { "url": "data:image/png;base64,<BASE64>" } }
]
}
]
}{
"model": "gpt-4o",
"messages": [
{
"role": "user",
"content": [
{ "type": "text", "text": "总结这份文件" },
{ "type": "file", "file": { "filename": "a.pdf", "file_data": "data:application/pdf;base64,<BASE64>" } }
]
}
]
}{
"model": "gpt-4o",
"messages": [
{
"role": "user",
"content": [
{ "type": "text", "text": "总结这份文件" },
{ "type": "file", "file": { "file_id": "file-xxx" } }
]
}
]
}image_url.url 字段既可放 http(s) 链接,也可放 data:<mime>;base64,<...> 形式的 base64,二者用同一个字段。curl --location 'https://api.openai-hub.net/v1/chat/completions' \
--header 'Authorization: Bearer sk-0ABIEXVjh9****Qckjy' \
--header 'Content-Type: application/json' \
--data '{
"model": "gpt-5.4",
"messages": [
{
"role": "system",
"content": "你是一个代码编程专家,根据我的提示完成我的任务!"
},
{
"role": "user",
"content": "用python代码写一个计算器"
}
],
"max_tokens": 4000
}'{
"id": "string",
"object": "chat.completion",
"created": 0,
"model": "string",
"choices": [
{
"index": 0,
"message": {
"role": "system",
"content": "string",
"name": "string",
"tool_calls": [
{
"id": "string",
"type": "function",
"function": {
"name": "string",
"arguments": "string"
}
}
],
"tool_call_id": "string",
"reasoning_content": "string"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 0,
"completion_tokens": 0,
"total_tokens": 0,
"prompt_tokens_details": {
"cached_tokens": 0,
"text_tokens": 0,
"audio_tokens": 0,
"image_tokens": 0
},
"completion_tokens_details": {
"text_tokens": 0,
"audio_tokens": 0,
"reasoning_tokens": 0
}
},
"system_fingerprint": "string"
}