Streaming session interface
This document details the request and response parameters for the session interface, along with examples and error codes. To learn about supported concurrency and how to purchase more capacity, see the product billing page. Session concurrency is calculated with the following formula: session concurrency = QPS * tail-packet response latency (s).
Notes
See the Large model session interface integration overview.
Integration example
Web client: integration example
DingTalk bot: integration example
WeChat Customer Service: integration example
WeCom: integration example
Lark bot: integration example
Session API requests
Request URL
https://alime-ws.aliyuncs.com/sse/paas4Json/{AccessToken}/{ChannelId}/{Sign}/{Timestamp}
Request parameters
Parameter | Description |
AccessToken | The access token for authentication. Obtain it from the Get connection information for streaming calls API. |
ChannelId | The streaming channel. Obtain it from the Get connection information for streaming calls API. |
Sign | The signature generated using the signing protocol. For more information, see Session API signature. |
Timestamp | The timestamp used to generate the signature. You can use the current system time in milliseconds. |
Request body parameters (JSON)
Parameter | Type | Required | Description |
messageId | String | Yes | A unique request identifier to ensure idempotence. A UUID is recommended. |
action | String | Yes | A fixed value: |
version | String | Yes | A fixed value: |
data | List | Yes | For details, see the session request parameters below. |
InstanceId | String | Yes | The bot ID. For example: |
Utterance | String | Yes | The user's utterance. The maximum length is 512 characters. |
SessionId | String | No | The session ID, used to identify the session and maintain context. |
SenderId | String | No | The sender ID, used to identify the user in the current session. |
SenderNick | String | No | The nickname of the sender in the current session. |
VendorParam | JSON String | No | A JSON string of user-defined passthrough parameters that you can pass to dialog engines. Examples:
|
Perspective | Array of String | No | Codes used to retrieve answers from different perspectives under a single knowledge title. Pass this parameter in the format |
SandBox | Boolean | No | Specifies the operating environment. The default is the production environment.
|
Command | String | No | The command to execute for the request.
|
Response parameters
An HTML response indicates that the URL parameters are incorrect.
Parameter | Type | Description |
success | Boolean | Indicates whether the request was successful. |
code | String | The error code. This field is returned only when |
message | String | The error message. This field is returned only when |
messageId | String | The ID of the request message. |
requestId | String | The unique ID of the request. |
data | Array | The response data. The format of A JSON string containing the detailed session response. See the fields below for its structure. |
SessionId | String | The ID of the current session. |
MessageId | String | The ID of the response message. |
SequenceId | String | The ID of a message segment in the streaming response. |
Source | String | The source of the answer. This field can be empty.
|
StreamEnd | Boolean | Indicates whether the streaming response is complete. |
MessageBody | MessageBody | The message body from the large language model. |
Type | String | The answer type.
|
DirectMessageBody | DirectMessageBody | The direct answer object from the bot. Returned only when |
SentenceList | Array of Sentence | The answer from the large language model, split into multiple segments. You can render segments as they arrive. |
Content | String | A segment of the answer from the large language model. |
ReferNumber | Integer | The sequence number of the segment. |
ContentType | String | The data type of the answer. Valid values:
|
HitSystemAskConfig | String | The matched Q&A policy. This field can be empty.
|
AnswerReference | AnswerReference | The source references for the answer. |
ItemList | Array of Item | A list of referenced items. For details, see ItemList Field Details. |
Ext | Map<String, Object> | Additional information from various answer sources. |
EXTERNAL_FLAGS(when | Map | Returns the |
RelatedQuestionList | Array of RelatedQuestion | A list of related questions. |
Content | String | The content of the related question. |
ClarifyMessageBody | ClarifyMessageBody | The clarification question object from the bot. Returned only when |
ClarifyContent | String | The full clarification response from the large language model. For example: "Which school are you asking about: Tsinghua University or Peking University?" |
Title | String | The title of the clarification prompt. For example: "Which school are you asking about?" |
ClarifyList | Array of Clarify | A list of clarification options for creating clickable follow-up prompts. For example: "Tsinghua University", "Peking University". |
Commands | Map<String, Object> | Contains the parameters of the triggered command. For details, see Commands Field Details. |
Example
Request example
Example Session API URL:
This link is for reference only; do not use it directly. https://alime-ws.aliyuncs.com/sse/paas4Json/121ccf51-94bf-4035-b7b4-4596ec1c03b4/e8c472e8-ddd8-42c8-b042-a89c7caa346d/d18120b6d9f83953b56340443f75188f/1718179407815
Request Body:
{
"messageId": "9e268624-1853-4f8b-8bd6-41a7ad818d62",
"action":"TongyiBeebotChat",
"version":"2022-04-08",
"data": [
{
"type": "JSON_TEXT",
"value": "{\"InstanceId\":\"chatbot-cn-dDmF3jcdVf\",\"Utterance\":\"What can you do?\",\"VendorParam\":\"{\\\"docLabels\\\":\\\"30022351214\\\"}\",\"Perspective\":[\"cnfKrDEfFa\",\"deasdSKoipa\"]}"
}
]
}Response example
{
"data": [
{
"type": "JSON_TEXT",
"value": "{\"IsAIGC\":true,\"MessageBody\":{\"DirectMessageBody\":{\"AnswerReference\":{\"ItemList\":[]},\"ContentType\":\"RICH_TEXT\",\"RelatedQuestionList\":[],\"SentenceList\":[{\"Content\":\"I can answer your questions as an expert in various fields. No matter what area of expertise you need, I will do my best to help. What specific question can I help you with?\"}]},\"Type\":\"Direct\",\"VoiceConfig\":{\"AsrMaxEndSilence\":\"700\",\"CollectNumber\":false,\"CollectVoice\":false,\"HangUp\":false,\"Interruptible\":false,\"ReplyTimeout\":5}},\"MessageId\":\"7a2c9996-64d4-4f08-8b90-5d78d43f84c7\",\"SequenceId\":\"d8d33d7fe5e244a4a37656a0d80bb003\",\"SessionId\":\"10fc717a-b2ee-4914-86a4-8f1d1f2a827c\",\"Source\":\"HYBRID_KNOWLEDGE\",\"StreamEnd\":false}"
}
],
"messageId": "9e268624-1853-4f8b-8bd6-41a7ad818d62",
"requestId": "7a2c9996-64d4-4f08-8b90-5d78d43f84c7",
"success": true
}Session response
The unescaped JSON object from the value field in the response example.
{
"MessageBody": {
"DirectMessageBody": {
"AnswerReference": {
"ItemList": [
]
},
"ContentType": "RICH_TEXT",
"RelatedQuestionList": [
],
"SentenceList": [
{
"Content": "I can answer your questions as an expert in a variety of fields. How can I help you?"
}
]
},
"Type": "Direct",
"VoiceConfig": {
"AsrMaxEndSilence": "700",
"CollectNumber": false,
"CollectVoice": false,
"HangUp": false,
"Interruptible": false,
"ReplyTimeout": 5
}
},
"MessageId": "7a2c9996-64d4-4f08-8b90-5d78d43f84c7",
"SequenceId": "d8d33d7fe5e244a4a37656a0d80bb003",
"SessionId": "10fc717a-b2ee-4914-86a4-8f1d1f2a827c",
"Source": "HYBRID_KNOWLEDGE",
"StreamEnd": false,
"IsAIGC": true
}Response examples
Source: TASK_DRIVEN_DIALOGUE
{
"MessageBody":{
"Commands":{},
"DirectMessageBody":{
"ContentType":"PLAIN_TEXT",
"Ext":{
"EXTERNAL_FLAGS":{}
},
"SentenceList":[
{
"Content":"It is sunny in Beijing, with a temperature of 8 degrees Celsius and easterly winds up to level 3."
}
]
},
"Type":"Direct"
},
"MessageId":"7a2cdb51-af56-4ac9-9c6d-108905695ac9",
"SequenceId":"4861074fe523498ba3f397e876b60105",
"SessionId":"f3d7e960933411ee96144bea43fe4df3",
"Source":"TASK_DRIVEN_DIALOGUE",
"StreamEnd":true
}Source=NON_STRUCTURAL_KNOWLEDGE
{
"MessageBody":{
"DirectMessageBody":{
"AnswerReference":{
"ItemList":[
{
"Content":"Hello",
"ContentType":"RICH_TEXT",
"DataSource":"FAQ_DIRECT",
"Number":1,
"ReferenceExt":{
"DocName":"FAQ knowledge base"
},
"Title":"Hello"
}
]
},
"ContentType":"RICH_TEXT",
"SentenceList":[
{
"Content":"Hello",
"ReferNumber":1
}
]
},
"Type":"Direct"
},
"MessageId":"808a9cfb-2cec-4230-aad1-66c28df6040e",
"SequenceId":"32a052f098c14769b8b81ac202f38d01",
"SessionId":"595fa8a0940611eeb59a155f6621f5d6",
"Source":"NON_STRUCTURAL_KNOWLEDGE",
"StreamEnd":true
}Source=SYSTEM_ASK_CONFIG
Triggered exception prompt: HitSystemAskConfig=NO_ANSWER
{
"MessageBody": {
"DirectMessageBody": {
"Ext": {},
"AnswerReference": {
"ItemList": []
},
"ContentType": "RICH_TEXT",
"SentenceList": [
{
"Content": "The bot is busy. Please try again later."
}
],
"HitSystemAskConfig": "NO_ANSWER",
"RelatedQuestionList": []
},
"VoiceConfig": {
"ReplyTimeout": 5,
"Interruptible": false,
"HangUp": false,
"AsrMaxEndSilence": "700",
"CollectVoice": false,
"CollectNumber": false
},
"Type": "Direct"
},
"MessageId": "6B15B50A-46D0-50DD-8EB4-5E82E931B331",
"SequenceId": "e140735e71014ff78ee84a2692a231a4",
"SessionId": "797acf6e-96b7-435b-9156-8a92ccefba1c",
"Source": "SYSTEM_ASK_CONFIG",
"StreamEnd": true,
"IsAIGC": true
}Triggered the built-in safety prompt: HitSystemAskConfig=SENSITIVE_WORD
{
"success": true,
"MessageBody": {
"DirectMessageBody": {
"AnswerReference": {
"ItemList": []
},
"ContentType": "PLAIN_TEXT",
"HitSystemAskConfig": "SENSITIVE_WORD",
"RelatedQuestionList": [],
"SentenceList": [
{
"Content": "I cannot answer that question. Please try asking something else."
}
]
},
"Type": "Direct"
},
"MessageId": "d163a0b1-cce4-41c3-8502-d314f464485e",
"SequenceId": "b7d96983212340f8ad672aee03e9c28f",
"SessionId": "c44f27edf48246b5b95c79035cbfac33",
"Source": "SYSTEM_ASK_CONFIG",
"StreamEnd": true,
"IsAIGC": true
}Command trigger: HitSystemAskConfig=COMMANDS
{
"success": true,
"MessageBody": {
"Commands": {
"sysToAgent": "{\"skillGroup\":\"\",\"ext\":\"\",\"toAgentReason\":\"HitEmotion\"}"
},
"DirectMessageBody": {
"AnswerReference": {
"ItemList": []
},
"ContentType": "PLAIN_TEXT",
"HitSystemAskConfig": "COMMANDS",
"RelatedQuestionList": [],
"SentenceList": [
{
"Content": "Transferring you to an agent."
}
]
},
"VoiceConfig": {
"AsrMaxEndSilence": "700",
"CollectNumber": false,
"CollectVoice": false,
"HangUp": false,
"Interruptible": false,
"ReplyTimeout": 5
},
"Type": "Direct"
},
"MessageId": "5d7db238-7c7e-4adb-b00f-fc22183dbdda",
"SequenceId": "2be71925e6fe4556bcfcbaaa0456e6d3",
"SessionId": "a78f6a070a574bb69cea4ee0108b2370",
"Source": "SYSTEM_ASK_CONFIG",
"StreamEnd": true,
"IsAIGC": true
}Error codes
An HTML response means the URL parameters are invalid.
Error code | HTTP status code | Description |
InvalidInstanceId.NotFound | 404 | The specified robot ID was not found. |
InvalidParameter | 400 | The specified parameter is invalid. |
InternalError | 500 | An internal error occurred. |
Rate limiting error
If concurrency exceeds version concurrency, throttling is triggered. For example:
{
"code": "csQueueBusy",
"data": [],
"message": "Queued: The service is busy, please wait.",
"messageId": "203bee17-c404-4b9c-ba96-cf3873237fa0",
"requestId": "18f80b3c-ff87-468c-b90f-0d31e4ce34b8",
"success": false
}