Skip to main content
POST
/
v1
/
chat
/
completions
文本与多模态对话
curl --request POST \
  --url https://api.chenyu.cn/v1/chat/completions \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "model": "<string>",
  "messages": [
    {}
  ],
  "messages[].role": "<string>",
  "messages[].content": {},
  "stream": true,
  "temperature": 123,
  "max_tokens": 123
}
'
{
  "id": "<string>",
  "object": "<string>",
  "model": "<string>",
  "choices": [
    {
      "message.role": "<string>",
      "message.content": "<string>",
      "finish_reason": "<string>"
    }
  ],
  "usage": {}
}

文本与多模态对话

使用 OpenAI Chat Completions 兼容格式调用文本模型或视觉模型。支持普通文本、图片输入、多图输入和流式响应。

请求参数

model
string
required
模型 ID。可通过 模型列表 查询
messages
array
required
对话消息列表
messages[].role
string
required
消息角色,支持 systemuserassistant
messages[].content
string | array
required
消息内容。文本模型可传字符串;视觉模型可传 OpenAI 多模态 content 数组
stream
boolean
是否使用 Server-Sent Events 流式响应
temperature
number
采样温度
max_tokens
integer
最大输出 token 数

响应参数

id
string
响应 ID
object
string
响应类型,通常为 chat.completion
model
string
实际调用的模型 ID
choices
array
输出候选列表
usage
object
token 用量

代码示例

import requests

url = "https://api.chenyu.cn/v1/chat/completions"
headers = {
    "Authorization": "Bearer your_api_key",
    "Content-Type": "application/json"
}
payload = {
    "model": "doubao-seed-2-0-lite-260428",
    "messages": [
        {"role": "user", "content": "你好,简单介绍一下你自己"}
    ]
}

response = requests.post(url, headers=headers, json=payload)
print(response.json()["choices"][0]["message"]["content"])

多模态示例

{
  "model": "doubao-seed-1-6-vision-250815",
  "messages": [
    {
      "role": "user",
      "content": [
        {"type": "text", "text": "这张图片里有什么?"},
        {
          "type": "image_url",
          "image_url": {
            "url": "https://example.com/image.png"
          }
        }
      ]
    }
  ]
}

响应示例

{
  "id": "chatcmpl_xxx",
  "object": "chat.completion",
  "created": 1780000000,
  "model": "doubao-seed-2-0-lite-260428",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "你好,我是晨羽智云大模型服务。"
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 20,
    "completion_tokens": 12,
    "total_tokens": 32
  }
}