Messages with Chatbot
The Neoagent API allows you to generate an AI response based on the user's question by sending a POST request to the /chat/Chat/ClientAsk endpoint.
Reading Time
~5-6 minutes
Endpoint
Request URL: https://app.neoagent.co/chat/Chat/ClientAsk
Method: POST
Required Headers
The API request must include the following headers:
Authorization: <Your-Secret-Key>- string, required - The secret key to authenticate the API requestContent-Type: application/json- string, required - The content type of the request payload
Request Body
The request body must 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 - Optional values are: Text, Audio, Image, Video. This field can be left null, defaulting to Text.
"chatAskType": null,
// boolean, optional - Whether to stream partial progress. Default is false.
"stream": false,
// List(integer), optional - An array of integers, only valid 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.
"fileIds": null
}
Parameters
sessionID- integer, required - The session ID obtained from the Create Chat Session APIcontent- string, required - The question or message from the user. If chatAskType is [Image, Audio, Video], content can be emptystream- boolean, optional - Whether to stream partial progress. Default is falsechatAskType- string, optional - Optional values are: Text, Audio, Image, Video. Default is TextfileIds- List(integer), optional - An array of integers, only valid 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 supported only in [MP4, MKV, AVI, FLV, MPEG] formats. Images are supported only in [PNG (.png), JPEG (.jpeg and .jpg), WEBP (.webp), non-animated GIF (.gif)] formats. Size limits: up to 20 MB per image; up to 100 MB per video;
Multimedia File Support
When chatAskType is set to multimedia content:
Supported Formats:
- Images: PNG, JPEG, WEBP, non-animated GIF
- Videos: MP4, MKV, AVI, FLV, MPEG
- Audio: WAV
Size Limits:
- Images: Up to 20MB per image
- Videos: Up to 100MB per video
- Audio: Standard limit
Rules:
- Images: Supports multiple files
- Video/Audio: Only a single file per request
Request Examples
- JavaScript (Fetch API)
- Python (Requests)
- cURL
- HTTP Raw
const res = await fetch('https://app.neoagent.co/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);
import requests
import json
url = 'https://app.neoagent.co/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 'https://app.neoagent.co/chat/Chat/ClientAsk' \
-X POST \
-H 'Authorization: <Your-Secret-Key>' \
-H 'Content-Type: application/json' \
-d '{"sessionID":123,"content":"hello","stream":false}'
POST /chat/Chat/ClientAsk HTTP/1.1
Host: app.neoagent.co
Authorization: <Your-Secret-Key>
Content-Type: application/json
{
"sessionID": 123,
"content": "hello",
"stream": false
}
Example with Image
// First, upload the image using the file upload API
const uploadResponse = await uploadFile(imageFile);
const fileId = uploadResponse.Data.fileId;
// Then send the request with the image
const res = await fetch('https://app.neoagent.co/chat/Chat/ClientAsk', {
method: 'POST',
headers: {
"Authorization": "<Your-Secret-Key>",
"Content-Type": "application/json"
},
body: JSON.stringify({
"sessionID": 123,
"content": "Analyze this image",
"chatAskType": "Image",
"fileIds": [fileId]
})
});
Response
Standard Format (without streaming)
The API response will be a JSON object structured as follows:
{
"Data": {
"messageid": 375561,
"content": "Hello! How can I assist you today?",
"totalToken": 4337,
"noAnswer": false
},
// string - API version
"Version": "1.0.0",
// boolean - Operation success status
"Success": true,
// integer - HTTP status code
"Code": 200,
// string - Error message if present
"Message": ""
}
Response Fields:
messageid- Unique ID of the response messagecontent- The content of the AI-generated responsetotalToken- Number of tokens used to generate the responsenoAnswer- Indicates whether the AI was unable to provide an answer
Streaming Format
When stream: true, the response will be in the Server-Sent Events format:
Response Header:
Content-Type: text/event-stream
Response Body:
// Incremental parts of the response
{"content":"\n"}
{"content":"Hello"}
{"content":"!"}
{"content":" How"}
{"content":" can"}
{"content":" I"}
{"content":" assist"}
{"content":" you"}
{"content":"?"}
// Final message with metadata
{"QuestionID":10495005,"AnswerID":10495006,"Answer":"\nHello! How can I assist you?","TotalToken":4994}
Advantages of Streaming:
- ✅ Real-time response
- ✅ Better user experience for long answers
- ✅ Ability to show progress
Error Handling
If the request fails, you should:
- Check the HTTP status code for network-level errors
- Examine the fields
CodeandMessagein the response for business-level errors - The field
Messagewill contain detailed information about the error
Possible Errors
| Code | Description |
|---|---|
| 400 | Missing or invalid parameters |
| 401 | Invalid API key |
| 404 | Session not found |
| 429 | Rate limit exceeded |
| 500 | Internal server error |
Example Error Response
{
"Data": null,
"Version": "1.0.0",
"Success": false,
"Code": 404,
"Message": "Session not found"
}