Implementing Q&A Through SSE
Function
This Server-Sent Events (SSE) API for Q&A is used to push data in real time or near real time. Server-Sent Events (SSE) is a technology that enables pushing updates from a server to a browser via HTTP connection. Unlike the traditional request-response mode, SSE allows the server to proactively send data to a client without requiring the client to frequently make requests. In a Q&A system, the SSE API enables real-time update of answers to questions. For example, after a user submits a question, the server can push new answers or updates in real time through the SSE API, without requiring the user to continuously refresh the page to check whether there are new answers.
URI
POST /v1/{project_id}/koochat/assistants/{assistant_id}/chat
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| project_id | Yes | String | Definition Project ID. For details, see Obtaining a Project ID and Name. Constraints N/A Range Project ID of the account. Default Value N/A |
| assistant_id | Yes | String | Definition ID of the assistant created on the Pangu Bot page. For details, see Obtaining an Assistant ID. Constraints N/A Range N/A Default Value N/A |
Request Parameters
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| X-Auth-Token | No | String | Definition User authentication details. For how to obtain a token, see [Authentication] (pangubot_04_0005.xml). Constraints N/A Range N/A Default Value N/A |
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| question | Yes | String | Definition User question. Constraints N/A Range 1 to 4,096 characters Default Value N/A |
| conversation_id | No | String | Definition Session ID. If no session ID is carried or an incorrect session ID is carried, a new session ID is automatically generated. Constraints N/A Range The value can contain 1 to 36 characters, including only letters, digits, hyphens (-), and underscores (_). UUID is recommended. Default Value N/A |
| conversation_conf | No | ConversationConf object | Definition Dialog configuration, which is required when a new session is created. Constraints N/A |
| source | No | String | Definition Q&A source. Constraints N/A Range Default Value N/A |
| debug | No | Boolean | Definition Whether debugging is required. Constraints N/A Range Default Value false |
| extra_info | No | String | Definition Extra dialog information, which is transparently transmitted to FunctionGraph through the skill. Constraints N/A Range N/A Default Value N/A |
| user_id | No | String | Definition User ID on the user side. The value can be customized. Constraints N/A Range 0 to 36 characters Default Value N/A |
| stream | No | Boolean | Definition Whether the results returned by the foundation model are output in streaming mode which implements the typewriter effect. Constraints N/A Range Default Value false |
Response Parameters
Status code: 200
| Parameter | Type | Description |
|---|---|---|
| event-message | AnswerMessage object | Definition Streaming dialog reply, which needs to be concatenated to obtain the final answer. |
| event-resp | RespMessage object | Definition Auxiliary information about a dialog, such as the intents and slots. |
| event-references | ReferencesMessage object | Definition Reference source tracing. |
| event-faq_log | FaqLogMessage object | Definition FAQ logs. |
| event-intention_retrieve_log | IntentionRetrieveLog object | Definition Intent retrieval logs. |
| event-intention_distribute_log | IntentionDistributeLog object | Definition Intent distribution logs. |
| event-rag_log | RagLog object | Definition RAG logs. |
| event-llm_request_log | LlmRequestLog object | Definition LLM logs. |
| event-moderation | String | Definition Content moderation. Range N/A |
| Parameter | Type | Description |
|---|---|---|
| answer | String | Definition Answer chunks returned in streaming mode. Range N/A |
| created | Long | Definition Created event. Range N/A |
| Parameter | Type | Description |
|---|---|---|
| conversation_id | String | Definition Session ID. Range N/A |
| created | Long | Definition Response time. Range N/A |
| answer | String | Definition Complete reply. Range N/A |
| request_id | String | Definition Request ID. Range N/A |
| reply_type | Integer | Definition Reply type. Range |
| detail | ChatResp object | Definition Return details. |
| rewritten_question | String | Definition Query rewriting result. Range N/A |
| Parameter | Type | Description |
|---|---|---|
| log_id | String | Definition Dialog ID. Range N/A |
| answer | String | Definition Engine reply. Range N/A |
| cost | Long | Definition Time required. Range N/A |
| resp_type | Integer | Definition Response type. Range |
| score | Float | Definition Score. Range 0 to 1 |
| fusion_result | Integer | Definition Q&A type. This parameter is valid only when resp_type is set to 1. Range |
| skill_id | String | Definition ID of the skill in use. This parameter is valid only when resp_type is set to 1. Range N/A |
| frame | FrameDTO object | Definition Skill frame data. This parameter is valid only when resp_type is set to 1. |
| Parameter | Type | Description |
|---|---|---|
| history_global_variables | Map<String,String> | Definition All variables collected in the current session (which may contain multiple dialog turns), including historical dialog turns. Key indicates the variable name, and Value indicates the variable value. |
| current_variables | Map<String,String> | Definition Variables collected in the current dialog turn. Key indicates the variable name, and Value indicates the variable value. |
| Parameter | Type | Description |
|---|---|---|
| references | references object | Definition Reference data. |
| Parameter | Type | Description |
|---|---|---|
| document_name | Map<String,Object> | Definition Document name. |
| type | String | Definition Document type. Range document: document |
| reference | Boolean | Definition Whether the document is referenced. Range |
| referenceIndex | Integer | Definition Index. Range N/A |
| page_content | String | Definition Original reference content. Range N/A |
| metadata | metadata object | Definition Raw data. |
| Parameter | Type | Description |
|---|---|---|
| title | String | Definition Document title. Range N/A |
| content | String | Definition Original reference content. Range N/A |
| doc_name | String | Definition Document chunk name. Range N/A |
| _id | String | Definition Document chunk ID. Range N/A |
| _score | String | Definition Score. Range 0 to 1 |
| Parameter | Type | Description |
|---|---|---|
| directory_ids | Array of strings | Definition Directory ID. |
| faqs | Array of faqs objects | Definition FAQ information. |
| cost | Integer | Definition Time required. Range N/A |
| Parameter | Type | Description |
|---|---|---|
| id | String | Definition FAQ ID. Range N/A |
| questions | Array of questions objects | Definition Question list. |
| top_score | Float | Definition Maximum matching score. Range 0 to 1 |
| answers | Array of answers objects | Definition Answer list. |
| Parameter | Type | Description |
|---|---|---|
| question | String | Definition Hit question. Range N/A |
| score | Float | Definition Score. Range 0 to 1 |
| Parameter | Type | Description |
|---|---|---|
| content | String | Definition Answer content. Range N/A |
| type | Integer | Definition Answer type. Range |
| Parameter | Type | Description |
|---|---|---|
| candidate_intentions | Array of candidate_intentions objects | Definition Candidate intent. |
| cost | Integer | Definition Time required. Range N/A |
| Parameter | Type | Description |
|---|---|---|
| intention_id | String | Definition Intent ID. Range N/A |
| intention_name | String | Definition Intent name. Range N/A |
| questions | Array of questions objects | Definition Question list. |
| assistant_id | String | Definition Assistant ID. Range N/A |
| version | String | Definition Version. Range N/A |
| score | Float | Definition Score. Range 0 to 1 |
| threshold | Float | Definition Acceptance threshold. Range N/A |
| Parameter | Type | Description |
|---|---|---|
| embedding | Array of floats | Definition Embedding list. |
| question | String | Definition Question. Range N/A |
| question_id | String | Definition Question ID. Range N/A |
| score | Float | Definition Score. Range 0 to 1 |
| Parameter | Type | Description |
|---|---|---|
| distributed_skill_id | String | Definition Distributed skill ID. Range N/A |
| distributed_skill_name | String | Definition Distributed skill name. Range N/A |
| intention_recognized_result | intention_recognized_result object | Definition Intent recognition result. |
| score | Float | Definition Score. Range 0 to 1 |
| Parameter | Type | Description |
|---|---|---|
| intention_id | String | Definition Intent ID. Range N/A |
| intention_name | String | Definition Intent name. Range N/A |
| questions | Array of questions objects | Definition Question list. |
| assistant_id | String | Definition Assistant ID. Range N/A |
| version | String | Definition Version. Range N/A |
| score | Float | Definition Score. Range 0 to 1 |
| threshold | Float | Definition Acceptance threshold. Range N/A |
| Parameter | Type | Description |
|---|---|---|
| embedding | Array of floats | Definition Embedding list. |
| question | String | Definition Question content. Range N/A |
| question_id | String | Definition Question ID. Range N/A |
| score | Float | Definition Score. Range 0 to 1 |
| Parameter | Type | Description |
|---|---|---|
| directory_ids | Array of strings | Definition Document directory ID. |
| debug_info | debug_info object | Definition Key information for invoking the RAG engine. |
| cost | Integer | Definition Time required for calling the RAG engine API. Range N/A |
| Parameter | Type | Description |
|---|---|---|
| doc_search_response | doc_search_response object | Definition Knowledge management search result. |
| websearch_response | Array of strings | Definition Public network search result. |
| rag_knowledge | Array of strings | Definition Knowledge finally selected as RAG. |
| Parameter | Type | Description |
|---|---|---|
| docs | Array of docs objects | Definition Document description. |
| Parameter | Type | Description |
|---|---|---|
| file_id | String | Definition File ID. Range N/A |
| title | String | Definition File title. Range N/A |
| subtitle | String | Definition File subtitle. Range N/A |
| content | String | Definition Content. Range N/A |
| doc_type | String | Definition File type. Range N/A |
| file_path | String | Definition File path. Range N/A |
| update_date_time | String | Definition File update time. Range N/A |
| score | Float | Definition Score. Range 0 to 1 |
| extra_info | String | Definition Extended document information. Range N/A |
| Parameter | Type | Description |
|---|---|---|
| llm_chat_req | llm_chat_req object | Definition LLM calling request. |
| Parameter | Type | Description |
|---|---|---|
| messages | Array of messages objects | Definition List of messages in the request for calling a large model. |
| conversationId | String | Definition Dialog ID. Range N/A |
Example Requests
Calling the Q&A API in streaming mode
POST https://{endpoint}/v1/{project_id}/koochat/assistants/{assistant_id}/chat
{
"stream" : true,
"source" : "API",
"question" : "Querying weather forecasts"
} Example Responses
Status code: 200
Request succeeded.
SSE response message for the dialog API.
Attribute name "event:{type}". "{type}" indicates the message event type. Attribute value "data" indicates the SSE message data.
event:faq_log
retry:0
data:{"cost":125,"directory_ids":[]}
event:intention_retrieve_log
retry:0
data:{"cost":138,"candidate_intentions":[]}
event:intention_distribute_log
retry:0
data:{"score":null,"distributed_skill_id":null,"distributed_skill_name":null,"intention_recognized_result":null}
event:qaflow_log
retry:0
data:{"cost":561,"directories":[]}
event:rag_log
retry:0
data:{"cost":444,"directory_ids":["123"],"debug_info":{"intention":"No intention","doc_search_response":{"docs":[]},"rag_knowledge":[],"websearch_response":[],"error_info":[],"planning_queries": ["Hello"]}
event:llm_request_log
retry:0
data:{"llm_chat_req":{"conversationId":"1769568381849004","customizedLlmConfig":{"region":"cn-southwest-2","url":"http://127.0.0.1:80/modelarts-maas/deepseek-v3/v1/chat/completions","service_type":2,"maas_model_name":"DeepSeek-V3","cloud_system_enable":true},"messages":[{"role":"system","content":"You are an intelligent dialog assistant. The user message is as follows:\nHello"}],"stream":true}}
event:llm_response_log
retry:0
data:{"first_token_cost":1555}
event:e2e_log
retry:0
data:{"first_token_cost":3571}
event:message
retry:0
data:{"created":1769590001702,"answer":"Hello","conversation_id":"1769568381849004","request_id":"1769568381849004"}
event:message
retry:0
data:{"created":1769590001707,"answer":"! ","conversation_id":"1769568381849004","request_id":"1769568381849004"}
event:message
retry:0
data:{"created":1769590001714,"answer":"Today is","conversation_id":"1769568381849004","request_id":"1769568381849004"}
event:message
retry:0
data:{"created":1769590001715,"answer":"2026","conversation_id":"1769568381849004","request_id":"1769568381849004"}
event:message
retry:0
data:{"created":1769590001715,"answer":"January","conversation_id":"1769568381849004","request_id":"1769568381849004"}
event:message
retry:0
data:{"created":1769590001715,"answer":"28","conversation_id":"1769568381849004","request_id":"1769568381849004"}
event:message
retry:0
data:{"created":1769590001716,"answer":"","conversation_id":"1769568381849004","request_id":"1769568381849004"}
event:message
retry:0
data:{"created":1769590001716,"answer":"Wednesday afternoon","conversation_id":"1769568381849004","request_id":"1769568381849004"}
event:message
retry:0
data:{"created":1769590001717,"answer":"How are you","conversation_id":"1769568381849004","request_id":"1769568381849004"}
event:message
retry:0
data:{"created":1769590001717,"answer":". ","conversation_id":"1769568381849004","request_id":"1769568381849004"}
event:message
retry:0
data:{"created":1769590001718,"answer":"What","conversation_id":"1769568381849004","request_id":"1769568381849004"}
event:message
retry:0
data:{"created":1769590001718,"answer":"can","conversation_id":"1769568381849004","request_id":"1769568381849004"}
event:message
retry:0
data:{"created":1769590001719,"answer":"I do for you","conversation_id":"1769568381849004","request_id":"1769568381849004"}
event:message
retry:0
data:{"created":1769590001719,"answer":"? ","conversation_id":"1769568381849004","request_id":"1769568381849004"}
event:message
retry:0
data:{"created":1769590001719,"answer":"Whether you want question","conversation_id":"1769568381849004","request_id":"1769568381849004"}
event:message
retry:0
data:{"created":1769590001720,"answer":"answering,","conversation_id":"1769568381849004","request_id":"1769568381849004"}
event:message
retry:0
data:{"created":1769590001720,"answer":"content","conversation_id":"1769568381849004","request_id":"1769568381849004"}
event:message
retry:0
data:{"created":1769590001720,"answer":"creation, or","conversation_id":"1769568381849004","request_id":"1769568381849004"}
event:message
retry:0
data:{"created":1769590001721,"answer":"technical support","conversation_id":"1769568381849004","request_id":"1769568381849004"}
event:message
retry:0
data:{"created":1769590001721,"answer":".","conversation_id":"1769568381849004","request_id":"1769568381849004"}
event:message
retry:0
data:{"created":1769590001721,"answer":"I am","conversation_id":"1769568381849004","request_id":"1769568381849004"}
event:message
retry:0
data:{"created":1769590001721,"answer":"always","conversation_id":"1769568381849004","request_id":"1769568381849004"}
event:message
retry:0
data:{"created":1769590001721,"answer":"at your service","conversation_id":"1769568381849004","request_id":"1769568381849004"}
event:message
retry:0
data:{"created":1769590001722,"answer":". ","conversation_id":"1769568381849004","request_id":"1769568381849004"}
event:reference
retry:0
data:[]
event:resp
retry:0
data:{"created":1769590001723,"answer":"Hello! Today is Wednesday afternoon, January 28, 2026. How are you? What can I do for you? Whether you want question answering, content creation, or technical support. I am always at your service. ","conversation_id":"1769568381849004","request_id":"1769568381849004","detail":{"answer":"Hello! Today is Wednesday afternoon, January 28, 2026. How are you? What can I do for you? Whether you want question answering, content creation, or technical support. I am always at your service. ","resp_type":1,"llm_generated":false}}
event:message
retry:0
data:[DONE]
Status Codes
| Status Code | Description |
|---|---|
| 200 | Request succeeded. SSE response message for the dialog API. Attribute name "event:{type}". "{type}" indicates the message event type. Attribute value "data" indicates the SSE message data. |
Error Codes
See Error Codes.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot
