Skip to main content

Message a Chatbot

The 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.If chatAskType is [Image,Audio,Video], content can be empty.
"content": "hello",
// string, optional - The optional values are: Text, Audio,Image,Video. This field can be left null, with the default value being Text.
"chatAskType": null,
// boolean, optional - Whether to stream back partial progress. Defaults to false.
"stream": false,
// List(integer), optional - It is an integer array, valid only when chatAskType is set to [Image,Video,Audio].In image mode, multiple images are supported, while in [video,Audio] mode, only a single [video,audio] is allowed.Audio is only supported in WAV format.Video is only supported in [MP4,MKV,AVI,FLV,MPEG] format.Image is only supported in [PNG (.png),JPEG (.jpeg and .jpg),WEBP (.webp),Non-animated GIF (.gif)] format.Size limits:Up to 20MB per image;Up to 100MB per video;Up to 40MB per video;
"fileIds": null
}
  • sessionID - integer, required - The session ID obtained from the Create Chat Session API
  • content - string, required - The question or message from the user.If chatAskType is [Image,Audio,Video], content can be empty.
  • stream - boolean, optional - Whether to stream back partial progress. Defaults to false.
  • chatAskType - string, optional - The optional values are: Text, Audio,Image,Video. This field can be left null, with the default value being Text.
  • fileIds - List(integer), optional - It is an integer array, valid only when chatAskType is set to [Image,Video,Audio].In image mode, multiple images are supported, while in [video,Audio] mode, only a single [video,audio] is allowed.Audio is only supported in WAV format.Video is only supported in [MP4,MKV,AVI,FLV,MPEG] format.Image is only supported in [PNG (.png),JPEG (.jpeg and .jpg),WEBP (.webp),Non-animated GIF (.gif)] format.Size limits:Up to 20MB per image;Up to 100MB per video;Up to 40MB per video;

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