Skip to main content
POST
/
v1
/
chat
/
completions
OpenAI 多模态响应 API
curl --request POST \
  --url https://ai.kaiho.cc/v1/chat/completions \
  --header 'Content-Type: application/json' \
  --data '{
  "response_format": {
    "type": "<string>"
  }
}'

概述

OpenAI 多模态响应 API 允许模型生成包含文本和图像的组合响应,适用于需要视觉解释的场景。

支持的模型

GPT-4o

最强大的多模态模型

GPT-4o-mini

高效的多模态模型

启用多模态输出

通过设置 response_format 参数启用多模态响应:
response_format
object
响应格式配置。

请求示例

curl https://ai.kaiho.cc/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{
    "model": "gpt-4o",
    "messages": [
      {
        "role": "user",
        "content": "画一个流程图,展示用户注册的过程"
      }
    ],
    "response_format": {
      "type": "multimodal"
    }
  }'

响应格式

多模态响应包含文本和图像的数组:
{
  "id": "chatcmpl-123",
  "object": "chat.completion",
  "created": 1677652288,
  "model": "gpt-4o",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": [
          {
            "type": "text",
            "text": "这是一个用户注册流程图:"
          },
          {
            "type": "image_url",
            "image_url": {
              "url": "https://storage.kaiho.cc/generated/image-123.png",
              "detail": "high"
            }
          },
          {
            "type": "text",
            "text": "流程包括以下步骤..."
          }
        ]
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 20,
    "completion_tokens": 150,
    "total_tokens": 170
  }
}

输入多模态内容

您也可以在输入中混合文本和图像:
response = client.chat.completions.create(
    model="gpt-4o",
    messages=[
        {
            "role": "user",
            "content": [
                {
                    "type": "text",
                    "text": "分析这张图片并创建一个相似的版本"
                },
                {
                    "type": "image_url",
                    "image_url": {
                        "url": "https://example.com/image.jpg"
                    }
                }
            ]
        }
    ],
    response_format={"type": "multimodal"}
)

使用场景

图表生成

让 AI 生成数据可视化图表

流程图

创建业务流程或技术架构图

UI 设计

生成界面设计原型

教育内容

创建带有插图的教学材料

图像规格

生成的图像具有以下特点:
  • 格式:PNG
  • 分辨率:1024x1024(默认)
  • 存储:临时存储 24 小时
  • 访问:通过 HTTPS URL

最佳实践

在提示词中清楚说明您需要的图像类型和风格。
准备好处理文本和图像的混合响应数组。
图像 URL 仅临时有效,需要及时下载保存。
计费说明: 多模态响应按生成的文本 tokens 和图像数量分别计费。
I