MaaS_Baichuan
请求协议
https
Header
| 参数名 | 类型 | 必填 | 描述 |
|---|---|---|---|
Content-Type |
string | 是 | 固定为 application/json |
Authorization |
string | 是 | Bearer ${YOUR_AK} |
请求 URL
POST https://genaiapi.cloudsway.net/v1/ai/{endpointPath}/chat/completions
请求 Body 参数
| 参数名 | 二级参数 | 三级参数 | 四级参数 | 类型 | 必填 | 描述 |
|---|---|---|---|---|---|---|
| model | - | - | - | string | 是 | 使用的模型 ID |
| messages | - | - | - | array[json] | 是 | 对话消息列表 (历史对话按从老到新顺序填入) |
| role | - | - | string | 是 | 消息作者的角色,为以下其中之一 1、user 2、assistant 3、system | |
| content | - | - | object | 是 | 消息内容,string或array[json]类型 | |
| - | - | - | string | 否 | content为string类型时,消息内容为普通文本 | |
| - | - | - | array[json] | 否 | content为array[json]类型时,消息内容为文本结构 | |
| - | type | - | string | 否 | content为array[json]类型时填写此字段,内容类型,必须为text或者file两者中一个 | |
| - | text | - | string | 否 | content为array[json]类型时填写此字段,当 type 为 text 时,填写的消息文本 | |
| - | file | - | object | 否 | content为array[json]类型时填写此字段,当 type 为 file 时,填写的文件内容 | |
| - | - | file_id | string | 否 | content为array[json]类型时填写此字段。 | |
| stream | - | - | - | boolean | 否 | 是否使用流式接口,默认值为 false |
| temperature | - | - | - | float | 否 | 取值范围: [.0f, 1.0f]。 多样性,越高,多样性越好, 缺省 0.3 |
| top_p | - | - | - | float | 否 | 取值范围: [.0f, 1.0f)。值越小,越容易出头部, 缺省 0.85 |
| top_k | - | - | - | int | 否 | 取值范围: [0, 20]。 搜索采样控制参数,越大,采样集大, 0 则不走 top_k 采样筛选策略,最大 20(超过 20 会被修正成 20),缺省 5 |
| max_tokens | - | - | - | int | 否 | 回答产生的最大 token 数。取值范围[1,32000] |
| metadata | - | - | - | map | 否 | 扩展参数 |
| evidence_scope | - | - | string | 否 | 证据材料获取范围(仅对Baichuan-M3-Plus模型生效)。支持 grounded、cited两种,默认为grounded。 grounded已对齐证据, 模型grounding阶段中被选取并校验的全部证据材料,但不要求这些证据一定在最终回答中被明确引用。 cited已引用证据,在最终模型输出中被明确引用(如通过 citation 编号)的证据材料,是grounded证据的子集。 | |
| disable_follow-up_question_extension | - | - | boolean | 否 | 是否禁用回复里的问题扩展。true: 禁用扩展; false: 不禁用扩展,默认为false。(仅对Baichuan-M3-Plus模型生效)。 | |
| output_style | - | - | string | 否 | 回答风格。支持expert 专业模式、patient 通俗模式,不传递参数默认为专业模式。(仅对Baichuan-M3-Plus模型生效)。 | |
| thinking | - | - | - | map | 否 | 思考的扩展参数,仅限Baichuan-M3使用。 |
| budget_tokens | - | - | int | 否 | 思考的token数,取值范围:大于等于 1024并且小于 max_tokens |
请求示例
curl --location --request POST 'https://genaiapi.cloudsway.net/v1/ai/{endpointPath}/chat/completions \
--header 'Authorization: Bearer ${YOUR_AK}' \
--header 'Content-Type: application/json' \
--data-raw '{
"model": "Baichuan-M3",
"messages": [
{
"role": "user",
"content": "小儿感冒咳嗽,痰咳不出来怎么办?"
}
],
"stream": false,
"max_tokens": 3000,
"thinking": {
"budget_tokens": 2000
}
}'
响应示例
{
"id": "chatcmpl-TT8pnXcBIF38VECBUAWLoaAq",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "**暂时不...如有其他问题,随时可以问我。🙏\n(注意:线上咨询不能替代面诊。如有任何不确定,请寻求专业医生的帮助。)",
"reasoning_content": "嗯,用户问的是小儿感冒咳嗽,痰咳不出来怎么办...避免用太专业的术语,让家长容易理解。同时要强调不要自己乱用药,尤其是抗生素和止咳药。\n"
},
"finish_reason": "stop",
"native_finish_reason": "stop"
}
],
"created": 1779243318,
"model": "MaaS_Baichuan_M3_20260113",
"object": "chat.completion",
"usage": {
"prompt_tokens": 43,
"completion_tokens": 2065,
"total_tokens": 2108,
"search_count": 0
}
}
流式请求示例
curl --location --request POST 'https://genaiapi.cloudsway.netv1/ai/{endpointPath}/chat/completions \
--header 'Authorization: Bearer ${YOUR_AK}' \
--header 'Content-Type: application/json' \
-d '{
"model": "Baichuan-M3",
"messages": [
{
"role": "user",
"content": "对于肌酐清除率低于30mL/min的患者,使用万古霉素的负荷剂量和维持剂量应如何调整?"
}
],
"stream": true,
"max_tokens":12000,
"thinking":{
"budget_tokens": 2000
}
}'
OpenAI SDK调用方式
from openai import OpenAI
client = OpenAI(
api_key="${YOUR_AK}",
base_url="genaiapi.cloudsway.net/v1",
)
completion = client.chat.completions.create(
model="MaaS_Baichuan_M3_20260113",
messages=[
{"role": "user", "content": "北京有哪些美食"}
],
stream=True
)
for chunk in completion:
print(chunk.choices[0])
文件管理接口说明
File上传可以与知识库检索retrieval等功能一起使用的文档。支持的文档格式:pdf、doc、docx、txt、xlsx、xls、csv、pptx。
| 限制内容 | 限制数量 |
|---|---|
| 文件总容量 | 5GB |
| 单个文件大小 | 50MB |
| 上传频率 | 60rpm |
1. File文件对象
| 字段名称 | 类型 | 描述 |
|---|---|---|
| id | string | 文件唯一标识,用于文件接口 |
| bytes | integer | 文件字节数大小 |
| created_at | integer | 创建时间,Unix时间戳(秒) |
| filename | string | 文件名称 |
| object | string | 类型,文件对象类型为'file' |
| purpose | string | 文件的使用意图。具体如下: 知识库:knowledge-base 助手对话:assistants 文档解析:file-parsing Baichuan-M2-Plus/Baichuan-M3-Plus对话:medical 当意图为medical时,支持的文档格式:pdf、doc、docx、txt、html、htm、md、markdown、rft、xml、csv、png、jpg、jpeg、gif、bmp、webp、json |
2.文件列表查询
[POST] /v1/ai/{endpointPath}/files
2.1返回值
| 字段名 | 一级子参数 | 类型 | 描述 |
|---|---|---|---|
| data | - | array[object] | 返回文件对象的list |
| id | string | 文件唯一标识,用于文件接口 | |
| bytes | integer | 文件字节数大小 | |
| created_at | integer | 创建时间,Unix时间戳(秒) | |
| filename | string | 文件名称 | |
| object | string | 类型,文件对象类型为'file' | |
| purpose | string | 文件的使用意图。如'knowledge-base' | |
| object | - | string | 对象类型"list" |
2.2接口示例
2.2.1请求
2.2.2返回值
{
"data": [
{
"id": "file-123",
"bytes": 1562,
"created_at": 1701832828,
"filename": "xxx.pdf",
"object": "file",
"purpose": "knowledge-base"
},
{
"id": "file-124123",
"bytes": 183237,
"created_at": 1702201134,
"filename": "xxx.doc",
"object": "file",
"purpose": "knowledge-base"
}
],
"object": "list"
}
3.文件上传接口
[POST] https://genaiapi.cloudsway.net/v1/ai/{endpointPath}/files
限制:单个文档限制50MB。 知识库目前支持pdf、doc、docx、xlsx、xls、csv、pptx类型文件,其中xlsx、xls、csv只能按固定模板上传QA对数据,具体模板见体验中心文档上传页面。 如果您收到速率限制的报错,则表示您在短时间内发出了太多请求,API 会拒绝新请求,直到经过指定的时间。
3.1请求参数
| 参数名称 | 类型 | 是否必填 | 说明 |
|---|---|---|---|
| file | file | Y | 上传的文件内容 |
| purpose | string | Y | 文件意图 |
3.2返回值
文件对象
3.3接口示例
3.3.1请求
curl https://genaiapi.cloudsway.net/v1/ai/{endpointPath}/files \
-H "Authorization: Bearer $API_KEY" \
--form 'purpose="medical"' \
--form 'file=@"C:\\Users\\user\\Desktop\\测试上传文件接口.txt"'
3.3.2返回值
{
"id": "file-abc123",
"object": "file",
"bytes": 120000,
"created_at": 1677610602,
"filename": "mydata.pdf",
"purpose": "knowledge-base"
}
4.文件删除接口
[POST] https://genaiapi.cloudsway.net/v1/ai/{endpointPath}/files/{fileId} 用于删除一个文件,被知识库使用的文件需要先解除关联后才能删除。
4.1请求参数
| 参数名称 | 类型 | 是否必填 | 说明 |
|---|---|---|---|
| file_id | string | Y | 文件id |
4.2接口示例
4.2.1请求
curl https://genaiapi.cloudsway.net/v1/ai/{endpointPath}/files/{fileId} \
-X DELETE \
-H "Authorization: Bearer $API_KEY"
4.2.2返回值
5.文件检索接口
[POST] https://genaiapi.cloudsway.net/v1/ai/{endpointPath}/files/{fileId} 返回一个文件的相关信息。
5.1请求参数
| 参数名称 | 类型 | 是否必填 | 说明 |
|---|---|---|---|
| file_id | string | Y | 文件id |
5.2返回值
返回指定文件id的文件对象信息
5.3接口示例
5.3.1请求
curl https://genaiapi.cloudsway.net/v1/ai/{endpointPath}/files/{fileId} \
-H "Authorization: Bearer $API_KEY"
5.3.2返回值
{
"id": "file-abc123",
"object": "file",
"bytes": 120000,
"created_at": 1677610602,
"filename": "mydata.pdf",
"purpose": "knowledge-base",
}
6.文件解析内容获取接口
只处理意图为file-parsing或medical的文件,调用文件上传接口时请将purpose设置为file-parsing或medical。
[POST]https://genaiapi.cloudsway.net/v1/ai/{endpointPath}/files/{fileId}/parsed-content 返回文档解析结果。
6.1请求参数
| 参数名称 | 类型 | 是否必填 | 说明 |
|---|---|---|---|
| file_id | string | Y | 文件id |
6.2返回值
| 参数名称 | 类型 | 说明 |
|---|---|---|
| status | string | init:待解析;parsing:解析中;online:解析成功;fail:解析失败;unsafe:未通过安全检查。 |
| content | string | 文档解析内容 |
6.3接口示例
6.3.1请求
curl https://genaiapi.cloudsway.net/v1/ai/{endpointPath}/files/{fileId}/parsed-content \
-H "Authorization: Bearer $API_KEY"