Docs

模型 API

视觉输入与图像生成

区分图像理解与生成,使用 image_url 内容块和 images/generations 接口。

更新于

POST/v1/images/generations

图像理解

图像理解通过支持视觉的聊天模型进行。Chat Completions 的 content 可包含 text 与 image_url 内容块。URL 必须能够被服务链路访问;本机文件路径不是远程图像 URL。私密资源应按应用的数据策略提供短期授权访问。

Chat Completions body
{
  "model": "YOUR_MODEL_ID",
  "messages": [
    {
      "role": "user",
      "content": [
        {
          "type": "text",
          "text": "Describe this image."
        },
        {
          "type": "image_url",
          "image_url": {
            "url": "https://your-domain.example/image.png"
          }
        }
      ]
    }
  ]
}

生成图像

POST /v1/images/generations 使用图像生成模型。model 和 prompt 是核心字段;尺寸、数量、质量和响应格式的支持取决于目标模型。先发送最小请求,再添加经过确认的参数。当前接入能力不能由“支持 OpenAI 兼容协议”一句话推断全部可用。

cURL
curl --fail-with-body https://api.token4ai.cloud/v1/images/generations \
  -H "Authorization: Bearer $TOKEN4AI_API_KEY" \
  -H "Content-Type: application/json" \
  --data '{
  "model": "YOUR_MODEL_ID",
  "prompt": "A clean technical illustration of a cloud API gateway."
}'

处理结果与限制

根据实际响应读取 data 中的图像 URL 或 Base64 数据。下载前检查 MIME 类型和体积,不要假设供应商返回的 URL 永久有效。上传输入大小、图像数量与输出尺寸由模型、路由和部署限制共同决定;遇到 413 时减少体积后再试。

继续阅读