Skip to main content

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 request
  • Content-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 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 partial progress. Default is false
  • chatAskType - string, optional - Optional values are: Text, Audio, Image, Video. Default is Text
  • fileIds - 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

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);

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 message
  • content - The content of the AI-generated response
  • totalToken - Number of tokens used to generate the response
  • noAnswer - 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:

  1. Check the HTTP status code for network-level errors
  2. Examine the fields Code and Message in the response for business-level errors
  3. The field Message will contain detailed information about the error

Possible Errors

CodeDescription
400Missing or invalid parameters
401Invalid API key
404Session not found
429Rate limit exceeded
500Internal server error

Example Error Response

{
"Data": null,
"Version": "1.0.0",
"Success": false,
"Code": 404,
"Message": "Session not found"
}