Skip to main content

Message a Chatbot

The AI Agent API enables you to generate an AI response based on the user's question by sending a POST request to the /chat/Chat/ClientAsk endpoint.

Endpoint

Request URL: https://usapi.hottask.com/chat/Chat/ClientAsk

Method: POST

Request Headers

The API request must include the following headers:

  • Authorization: <Your-Secret-Key> - string, required - The secret key for authenticating the API request
  • Content-Type: application/json - string, required - The content type of the request payload (must be application/json)

Request Body

The request body should contain the following parameters:

{
// integer, required - The session ID obtained from the Create Chat Session API
"sessionID": 123,
// string, required - The question or message from the user
"content": "hello",
// boolean, optional - Whether to stream back partial progress. Defaults to false.
"stream": false
}
  • sessionID - integer, required - The session ID obtained from the Create Chat Session API
  • content - string, required - The question or message from the user
  • stream - boolean, optional - Whether to stream back partial progress. Defaults to false.

Example Request

JavaScript (Fetch API)

const res = await fetch('https://usapi.hottask.com/chat/Chat/ClientAsk', {
method: 'POST',
headers: {
"Authorization": "<Your-Secret-Key>",
"Content-Type": "application/json"
},
body: JSON.stringify({
"sessionID": 123,
"content": "hello",
"stream": false
})
});

const data = await res.json();
console.log(data);

Python (Requests Library)

import requests
import json

url = 'https://usapi.hottask.com/chat/Chat/ClientAsk'
headers = {
"Authorization": "<Your-Secret-Key>",
"Content-Type": "application/json"
}
data = {
"sessionID": 123,
"content": "hello",
"stream": false
}

response = requests.post(url, headers=headers, json=data)
data = response.json()
print(data)

cURL

curl 'https://usapi.hottask.com/chat/Chat/ClientAsk' \
-X POST \
-H 'Authorization: <Your-Secret-Key>' \
-H 'Content-Type: application/json' \
-d '{"sessionID":123,"content":"hello","stream":false}'

HTTP Request

POST /chat/Chat/ClientAsk HTTP/1.1
Host: usapi.hottask.com
Authorization: <Your-Secret-Key>
Content-Type: application/json

{
"sessionID": 123,
"content": "hello",
"stream": false
}

Response

Not using the return format of the stream:

The API response will be a JSON object with the following structure:

{
"Data": {
"messageid": 375561,
"content": "Hello! How can I assist you today?",
"totalToken": 4337
},
// string - API version
"Version": "1.0.0",
// boolean - Operation success status
"Success": true,
// integer - HTTP status code
"Code": 200,
// string - Error message if any
"Message": ""
}

Using the return format of the stream:

Response Header:

{
"Content-Type": "text/event-stream"
}

Response Body:

// The AI ​​response.
{"content":"\n"}
{"content":"Hello"}
{"content":"!"}
{"content":" How"}
{"content":" can"}
{"content":" I"}
{"content":" assist"}
{"content":" you"}
{"content":"?"}
// QuestionID is the message ID of the request, AnswerID is the message ID of the response, Answer is the complete answer of the AI, and TotalToken is the number of tokens consumed.
{"QuestionID":10495005,"AnswerID":10495006,"Answer":"\nHello! How can I assist you?","TotalToken":4994}

Error Handling

If the request fails, you should: 1. Check the HTTP status code for network-level errors 2. Examine the `Code` and `Message` fields in the response for business-level errors 3. The `Message` field will contain detailed error information