Skip to main content

开放平台应用

开放平台模块提供标准化的开放API接口,包括Chat Completion对话接口和开放平台应用管理接口。

Chat Completion V1

接口地址

POST /openapi/api/v1/chat/completions

请求方法

POST

权限要求

chat_v1 READ

接口描述

标准的Chat Completion接口,支持SSE流式输出和JSON响应。

请求Header

Header名类型必填说明
AuthorizationStringBearer Token认证,格式:Bearer sk_xxxxxxxxxxxxx

请求参数

参数名类型必填默认值说明
userIdString-用户ID
conversationIdString-会话ID
promptString-提示词文本
promptTemplateString-提示词模板
modelString-模型名称
ragSearchbooleantrue是否启用RAG检索
reasonStatusbooleanfalse是否返回推理状态
messagesLinkedList<BotMessage>-消息列表
containerIdList<String>-知识库容器ID列表
multipleDialogbooleantrue是否多轮对话
temperaturefloat0.95温度参数,0-1
top_pfloat0.7Top P采样
fileIdsList<String>-文件ID列表
apiKeyString-API Key(隐藏字段)

BotMessage结构

参数名类型必填说明
roleString角色类型
contentObject消息内容
reasoningContentString推理内容

RequestBody示例

{
"userId": "user_001",
"conversationId": "conv_001",
"prompt": "你好",
"model": "glm-4",
"ragSearch": true,
"reasonStatus": false,
"messages": [
{
"role": "user",
"content": "你好,请介绍一下自己"
}
],
"containerId": ["container_001"],
"multipleDialog": true,
"temperature": 0.95,
"top_p": 0.7,
"fileIds": []
}

响应示例

SSE流式或JSON响应:

{
"id": "chatcmpl-123",
"object": "chat.completion",
"created": 1677652288,
"model": "glm-4",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "你好!我是智能助手,很高兴为您服务。"
},
"finish_reason": "stop"
}
]
}

请求示例

curl -X POST "${domain}/openapi/api/v1/chat/completions" \
-H "Authorization: Bearer sk_xxxxxxxxxxxxx" \
-H "Content-Type: application/json" \
-d '{
"model": "glm-4",
"prompt": "你好",
"messages": [
{"role": "user", "content": "你好,请介绍一下自己"}
],
"containerId": ["container_001"],
"temperature": 0.95,
"top_p": 0.7
}'

查询可用模型列表

接口地址

GET /openapi/community/v1/models

请求方法

GET

权限要求

chat_v2 READ

接口描述

查询当前可用的模型列表,返回OpenAI兼容格式。

请求参数

响应示例

{
"object": "list",
"data": [
{
"id": "glm-4",
"object": "model",
"created": 1677652288,
"owned_by": "zhipu"
},
{
"id": "glm-3-turbo",
"object": "model",
"created": 1677652288,
"owned_by": "zhipu"
}
]
}

请求示例

curl -X GET "${domain}/openapi/community/v1/models" \
-H "Authorization: Bearer sk_xxxxxxxxxxxxx" \
-H "Content-Type: application/json"

Chat OpenAI兼容接口

接口地址

POST /openapi/community/v1/chat/completions

请求方法

POST

权限要求

chat_v2 READ

接口描述

OpenAI兼容的Chat Completion接口V2,支持SSE流式输出和JSON响应。

请求Header

Header名类型必填说明
AuthorizationStringBearer Token认证,格式:Bearer sk_xxxxxxxxxxxxx

请求参数

参数名类型必填默认值说明
messagesLinkedList<BotMessage>-消息列表
modelString-模型名称
temperaturefloat0.95温度参数,0-1
top_pfloat0.7Top P采样
conversationIdString-会话ID
containerIdList<String>-知识库容器ID列表
userString-用户标识

BotMessage结构

参数名类型必填说明
roleString角色类型
contentObject消息内容
reasoningContentString推理内容

RequestBody示例

{
"messages": [
{
"role": "user",
"content": "你好,请介绍一下自己"
}
],
"model": "glm-4",
"temperature": 0.95,
"top_p": 0.7,
"conversationId": "conv_001",
"containerId": ["container_001"],
"user": "user_001"
}

响应示例

SSE流式或JSON响应:

{
"id": "chatcmpl-123",
"object": "chat.completion",
"created": 1677652288,
"model": "glm-4",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "你好!我是智能助手,很高兴为您服务。"
},
"finish_reason": "stop"
}
]
}

请求示例

curl -X POST "${domain}/openapi/community/v1/chat/completions" \
-H "Authorization: Bearer sk_xxxxxxxxxxxxx" \
-H "Content-Type: application/json" \
-d '{
"model": "glm-4",
"messages": [
{"role": "user", "content": "你好,请介绍一下自己"}
],
"containerId": ["container_001"],
"temperature": 0.95,
"top_p": 0.7
}'

应用面板信息

接口地址

GET /openapi/store/api/v1/dashboard

请求方法

GET

权限要求

app_dashboard READ

接口描述

获取应用面板配置信息。

请求Header

Header名类型必填说明
AuthorizationString认证Token

请求参数

响应示例

{
"code": 8200,
"message": "操作成功",
"data": {
"id": 1,
"sort": 1,
"tenantId": "0",
"code": "app_001",
"title": "智能客服",
"description": "智能客服应用",
"logoImage": "https://cdn.example.com/logo.png",
"appUrl": "https://app.example.com/app_001"
}
}

请求示例

curl -X GET "${domain}/openapi/store/api/v1/dashboard" \
-H "Authorization: Bearer sk_xxxxxxxxxxxxx" \
-H "Content-Type: application/json"

按AppID查询应用

接口地址

GET /openapi/store/api/v1/queryByAppId

请求方法

GET

权限要求

app_info READ

接口描述

根据AppID查询应用信息。

请求参数

参数名类型必填说明
appidString应用ID(注意:参数名为小写appid)

响应示例

{
"code": 8200,
"message": "操作成功",
"data": {
"appId": "app_001",
"name": "智能客服",
"description": "智能客服应用",
"icon": "https://cdn.example.com/icon.png",
"status": "published",
"config": {
"llmModel": "glm-4",
"llmTemperature": 0.7
}
}
}

请求示例

curl -X GET "${domain}/openapi/store/api/v1/queryByAppId?appid=app_001" \
-H "Authorization: Bearer sk_xxxxxxxxxxxxx" \
-H "Content-Type: application/json"

应用商店列表

接口地址

GET /openapi/store/api/v1/store/list

请求方法

GET

权限要求

app_dashboard READ

接口描述

分页查询应用市场列表。

请求参数

参数名类型必填说明
pageNoInteger当前页码,默认1
pageSizeInteger页码大小,默认10
nameString应用名称(模糊查询)

响应示例

{
"code": 8200,
"message": "操作成功",
"data": [
{
"id": 1,
"appid": "app_001",
"role": "assistant",
"category": "客服",
"icon": "https://cdn.example.com/icon.png",
"name": "智能客服",
"description": "智能客服应用",
"accessToken": "token_xxx",
"appUrl": "https://app.example.com/app_001",
"tag": "AI,客服",
"creator": "admin",
"createTime": "2024-01-01 10:00:00",
"modifier": "admin",
"modifierTime": "2024-01-01 10:00:00",
"sort": 1
}
],
"total": 1,
"totalPage": 1,
"pageNo": 1,
"pageSize": 10
}

请求示例

curl -X GET "${domain}/openapi/store/api/v1/store/list?pageNo=1&pageSize=10&name=客服" \
-H "Authorization: Bearer sk_xxxxxxxxxxxxx" \
-H "Content-Type: application/json"

提交面板反馈

接口地址

POST /openapi/store/feedback/api/v1/add

请求方法

POST

权限要求

app_chat_feedback WRITE

接口描述

提交应用面板反馈。

请求参数

参数名类型必填说明
conversationIdString会话ID
modelString模型名称,默认glm-3-turbo
questionString问题内容
answerString回答内容
remarkString备注信息
typeString反馈类型(like/tap/other)
tagString标签
messageIdString消息ID
appidString应用ID

RequestBody示例

{
"conversationId": "conv_001",
"model": "glm-3-turbo",
"question": "什么是知识库?",
"answer": "知识库是用于存储和管理知识的系统...",
"remark": "",
"type": "like",
"tag": "",
"messageId": "msg_001",
"appid": "app_001"
}

响应示例

{
"code": 8200,
"message": "提交成功",
"data": "feedback_001"
}

请求示例

curl -X POST "${domain}/openapi/store/feedback/api/v1/add" \
-H "Authorization: Bearer sk_xxxxxxxxxxxxx" \
-H "Content-Type: application/json" \
-d '{
"conversationId": "conv_001",
"question": "什么是知识库?",
"answer": "知识库是用于存储和管理知识的系统...",
"type": "like",
"appid": "app_001"
}'