Send Message
Sends a message to an existing chat session. The AI agent will process the message and generate an appropriate response based on the conversation context.
Endpoint
POST https://api.nexusgpt.io/api/public/thread/{id}/messages
Authentication
Your Nexus API key for authentication
Path Parameters
The session ID obtained from creating a session. This identifies which conversation thread to send the message to.
Request Body
The message content to send to the AI agent. Maximum length: 4000 characters.
Response Fields
Indicates whether the message was successfully sent and queued for processing
Example Usage
curl -X POST https://api.nexusgpt.io/api/public/thread/550e8400-e29b-41d4-a716-446655440000/messages \
-H "Content-Type: application/json" \
-H "api-key: YOUR_API_KEY" \
-d '{"content": "Can you help me track my order #12345?"}'
Message Processing
How It Works
Message Receipt : Your message is received and validated
Context Loading : Previous conversation history is loaded
AI Processing : The agent processes your message with full context
Response Generation : A contextual response is generated
Storage : Both messages are stored in the conversation thread
Response Time
Typical response time: 1-3 seconds
Complex queries may take longer
Use polling to retrieve responses
Common Patterns
1. Send and Wait Pattern
async function sendAndWaitForResponse ( sessionId , message ) {
// Send the message
await sendMessage ( sessionId , message );
// Poll for response (with exponential backoff)
let attempts = 0 ;
while ( attempts < 5 ) {
await new Promise ( resolve => setTimeout ( resolve , 1000 * Math . pow ( 1.5 , attempts )));
const messages = await getMessages ( sessionId , { limit: 2 , order: 'desc' });
const latestMessage = messages [ 0 ];
if ( latestMessage . type === 'assistant' && latestMessage . createdAt > sentTime ) {
return latestMessage ;
}
attempts ++ ;
}
throw new Error ( 'Timeout waiting for response' );
}
2. Conversation Flow
async function handleConversation ( sessionId ) {
// Initial greeting
await sendMessage ( sessionId , "Hello!" );
// Follow-up with context
await sendMessage ( sessionId , "I need help with order #12345" );
// Provide additional details
await sendMessage ( sessionId , "It was supposed to arrive yesterday" );
}
3. Structured Queries
// Send structured information
const orderQuery = {
intent: "track_order" ,
orderId: "12345" ,
email: "[email protected] "
};
await sendMessage ( sessionId , JSON . stringify ( orderQuery ));
Error Responses
401 Unauthorized
404 Not Found
400 Bad Request
400 Bad Request
413 Payload Too Large
429 Too Many Requests
{
"statusCode" : 401 ,
"message" : "Invalid API key" ,
"error" : "Unauthorized"
}
Best Practices
Send related messages in the same session
Create new sessions for unrelated topics
Include relevant details in your messages
Reference previous messages when needed
Implement retry logic for failed sends
Handle session expiration gracefully
Validate message content before sending
Log failed messages for debugging
Limitations
Message Length : Maximum 4000 characters per message
Rate Limits : 60 messages per minute per API key
Session Limits : Messages must be sent to active sessions
Content Policy : Messages must comply with usage policies