多模态大模型对话
更新时间:2026-02-08
本接口用于多模态大模型对话,采用 OpenAI 兼容格式,同步返回对话结果。
注意事项:
- 支持 G3FP、G3PP 模型
- 当前仅支持非流式返回(stream 为 false)
- G3FP 思考模式支持 MINIMAL/LOW/MEDIUM/HIGH 级别
- G3PP 思考模式支持 LOW/HIGH 级别
- 不建议修改 top_p、top_k、temperature 等采样参数,使用默认值即可获得最佳效果
请求结构
Http
1POST /v2/chat/completions HTTP/1.1
2connection: keep-alive
3host: vod.bj.baidubce.com
4content-type: application/json
5x-bce-request-id: <bce-request-id>
6x-bce-date: <utc-date-string>
7authorization: <bce-authorization-string>
请求头域
除公共头域外,无其它特殊头域。
请求参数
| 参数 | 类型 | 是否必需 | 描述 |
|---|---|---|---|
| model | String | 是 | 模型名称,支持:
|
| messages | Array | 是 | 对话消息列表 |
| + role | String | 是 | 消息角色,支持:model(系统提示词)、user(用户)、assistant(大模型) |
| + content | String | 是 | 消息内容,最大输入 token 数:1,048,576,最大输出 token 数:65,536 |
| temperature | Double | 否 | 控制输出随机性,值越高越随机,范围 0.0 ~ 2.0 |
| top_p | Double | 否 | 核采样参数,控制候选 token 的累积概率阈值,范围 0.0 ~ 1.0 |
| top_k | Integer | 否 | 从概率最高的 k 个 token 中采样,范围 1 ~ 64 |
| max_completion_tokens | Integer | 否 | 最大输出 token 数量限制,>=1 |
| seed | Double | 否 | 随机种子,相同 seed 可复现结果 |
| stop | Array<String> | 否 | 停止词列表,遇到这些词时停止生成 |
| frequency_penalty | Double | 否 | 频率惩罚,正值降低重复词出现概率,范围 -2.0 ~ 2.0 |
| presence_penalty | Double | 否 | 存在惩罚,正值鼓励模型讨论新话题,范围 -2.0 ~ 2.0 |
| stream | Boolean | 否 | 是否流式返回,当前仅支持 false |
| extra_body | Object | 否 | 扩展参数,用于传递厂商特定配置 |
| + g_model | Object | 否 | Google/Gemini 特定配置 |
| ++ thinking_config | Object | 否 | 思考模式配置 |
| +++ thinking_level | String | 否 | 思考深度级别,级别越高推理越深入。G3FP 支持:MINIMAL、LOW、MEDIUM、HIGH;G3PP 支持:LOW、HIGH |
返回头域
除公共头域,无其它特殊头域。
返回参数
| 参数 | 类型 | 描述 |
|---|---|---|
| id | String | 响应唯一标识符 |
| object | String | 对象类型,固定为 chat.completion |
| created | Long | 响应创建时间戳(Unix 时间戳,秒) |
| model | String | 使用的模型名称(G3FP 或 G3PP) |
| choices | Array | 生成的回复列表 |
| + index | Integer | 回复索引,从 0 开始 |
| + message | Object | 回复消息内容 |
| ++ role | String | 角色,固定为 assistant |
| ++ content | String | 生成的回复文本内容 |
| + finish_reason | String | 结束原因 |
| usage | Object | Token 使用统计 |
| + prompt_tokens | Integer | 输入 token 数量 |
| + completion_tokens | Integer | 输出 token 数量 |
| + total_tokens | Integer | 总 token 数量 |
| + prompt_tokens_details | Object | 输入 token 详细统计 |
| ++ cached_tokens | Integer | 缓存命中的 token 数量 |
| ++ text_tokens | Integer | 文本 token 数量 |
| ++ audio_tokens | Integer | 音频 token 数量 |
| ++ image_tokens | Integer | 图片 token 数量 |
| + completion_tokens_details | Object | 输出 token 详细统计 |
| ++ text_tokens | Integer | 文本 token 数量 |
| ++ audio_tokens | Integer | 音频 token 数量 |
| ++ reasoning_tokens | Integer | 推理 token 数量(思考模式产生) |
| + price | String | 本次请求费用(人民币) |
| error | Object | 错误信息(仅在出错时返回) |
| + message | String | 错误描述信息 |
| + type | String | 错误类型 |
| + code | String/Integer | 错误代码 |
请求示例
基础对话示例
请求内容
Http
1POST /v2/chat/completions HTTP/1.1
2host: vod.bj.baidubce.com
3accept: */*
4connection: keep-alive
5content-type: application/json
6x-bce-request-id: 6bae5cb3-97d1-4b1a-b8b6-0ad577c1d481
7x-bce-date: 2024-03-24T13:08:44Z
8authorization: bce-auth-v1/46bd9968a6194b4bbdf0341f2286ccce/2024-03-24T13:08:44Z/1800/host;x-bce-date/7e21c9cf1e4e2cc6921a407a388fe98df122c53b9f509043d841be76eb09a1f9
9
10{
11 "model": "G3FP",
12 "messages": [
13 {
14 "role": "user",
15 "content": "你好,请介绍一下你自己"
16 }
17 ],
18 "stream": false
19}
返回内容
JSON
1{
2 "id": "chatcmpl-xxxxxxxx",
3 "object": "chat.completion",
4 "created": 1711281524,
5 "model": "G3FP",
6 "choices": [
7 {
8 "index": 0,
9 "message": {
10 "role": "assistant",
11 "content": "你好!我是一个大语言模型,可以帮助你回答问题、提供信息和进行对话。"
12 },
13 "finish_reason": "stop"
14 }
15 ],
16 "usage": {
17 "prompt_tokens": 10,
18 "completion_tokens": 30,
19 "total_tokens": 40,
20 "prompt_tokens_details": {
21 "cached_tokens": 0,
22 "text_tokens": 10,
23 "audio_tokens": 0,
24 "image_tokens": 0
25 },
26 "completion_tokens_details": {
27 "text_tokens": 30,
28 "audio_tokens": 0,
29 "reasoning_tokens": 0
30 },
31 "price": "0.000100"
32 }
33}
带思考模式示例
请求内容
Http
1POST /v2/chat/completions HTTP/1.1
2host: vod.bj.baidubce.com
3accept: */*
4connection: keep-alive
5content-type: application/json
6x-bce-request-id: 6bae5cb3-97d1-4b1a-b8b6-0ad577c1d482
7x-bce-date: 2024-03-24T13:08:44Z
8authorization: bce-auth-v1/46bd9968a6194b4bbdf0341f2286ccce/2024-03-24T13:08:44Z/1800/host;x-bce-date/7e21c9cf1e4e2cc6921a407a388fe98df122c53b9f509043d841be76eb09a1f9
9
10{
11 "model": "G3PP",
12 "messages": [
13 {
14 "role": "user",
15 "content": "请分析量子计算对密码学的潜在影响"
16 }
17 ],
18 "stream": false,
19 "extra_body": {
20 "g_model": {
21 "thinking_config": {
22 "thinking_level": "HIGH"
23 }
24 }
25 }
26}
返回内容
JSON
1{
2 "id": "chatcmpl-yyyyyyyy",
3 "object": "chat.completion",
4 "created": 1711281530,
5 "model": "G3PP",
6 "choices": [
7 {
8 "index": 0,
9 "message": {
10 "role": "assistant",
11 "content": "量子计算对密码学的影响是深远的。当前广泛使用的 RSA 和 ECC 等公钥加密算法依赖于大数分解和离散对数问题的计算困难性,而量子计算机利用 Shor 算法可以在多项式时间内解决这些问题,从而对现有加密体系构成威胁。为应对这一挑战,后量子密码学(PQC)正在积极发展,包括基于格的密码学、基于哈希的签名方案等抗量子算法。"
12 },
13 "finish_reason": "stop"
14 }
15 ],
16 "usage": {
17 "prompt_tokens": 15,
18 "completion_tokens": 200,
19 "total_tokens": 215,
20 "prompt_tokens_details": {
21 "cached_tokens": 0,
22 "text_tokens": 15,
23 "audio_tokens": 0,
24 "image_tokens": 0
25 },
26 "completion_tokens_details": {
27 "text_tokens": 120,
28 "audio_tokens": 0,
29 "reasoning_tokens": 80
30 },
31 "price": "0.002500"
32 }
33}
