Skip to main content
This API endpoint allows you to send messages to AI agents and create new conversations or continue existing ones. It supports real-time streaming responses, file attachments, and background agent processing.

API Endpoint

Authentication: Requires authenticated user Content-Type: application/json or multipart/form-data (when files are included) Response Format: Server-Sent Events (SSE) stream

Overview

The send message API allows you to:
  • Start new conversations with AI agents
  • Continue existing conversation threads
  • Upload file attachments (PDF, images, documents)
  • Receive real-time streaming responses
  • Use background agents for long-running tasks
  • Specify agent or use permission-based agent selection

Request Parameters

Query Parameters

If neither agent_id nor permission_id is provided, the system will use the user’s default agent. Even if an agent_id is provided, the system will verify that the user has permission to use that agent.

Request Body (JSON)

The simplest request body is:
When you want to reply to an existing conversation thread, include the thread object:

Body Fields

IsStaff sets the message role to “Staff”. We use it when a human staff member is sending the message, otherwise the role is “user”. Languages are used to return document titles and other metadata in the user’s preferred language.

Request Body (FormData with Files)

When uploading files, use multipart/form-data format:
  • message: JSON string containing the message data (same structure as JSON body above)
  • files: One or more file uploads (max 5 files, 10MB each)

File Upload Constraints

Response Format

The API returns a Server-Sent Events (SSE) stream with multiple event types:

1. Agent and Thread Information

First event sent when starting a conversation:

2. Knowledge Sources

Sources used by the agent to answer the question:

3. Streaming Content

Incremental content chunks as the agent generates the response:

4. Completion Status

Final event when the response is complete:

5. Thread Title Generation

Automatic title generation for new threads:

Response Status Values

Background Agents

When using a background agent (for long-running tasks):
  1. The initial response confirms the background task has started
  2. Use the progress stream endpoint to monitor status
  3. The agent will process the request asynchronously
  4. Progress updates are stored in the message’s background_agent_progress field
Progress Stream Endpoint:
See the Background Agent Progress section for details.

Usage Examples

Basic Request - Start New Conversation

Continue Existing Conversation

Send Message to Specific Agent

Send Message with File Attachments

Use Permission-Based Agent Selection

JavaScript/TypeScript Example with SSE

Monitoring Background Agents

For background agents, use the progress stream endpoint to monitor execution:

Progress Stream Events

Fallback Polling System

If streaming fails or is not supported (some mobile environments, proxies), use the message status endpoint for polling.

When to Use Polling

  • SSE connection fails or times out
  • Behind proxy that doesn’t support streaming
  • Mobile SDK with limited SSE support
  • Testing/debugging scenarios

Message Status Endpoint

Response:
Completed Response:

Polling Implementation

Poll every 1-2 seconds until status is DONE or ERROR:

Polling Best Practices

Error Responses

400 Bad Request - Invalid Request Body

400 Bad Request - Invalid UUID Format

403 Forbidden - File Attachments Disabled

400 Bad Request - File Too Large

400 Bad Request - Too Many Files

400 Bad Request - Invalid File Type

404 Not Found - Agent Not Found

Integration Notes

Agent Selection Priority

The system selects an agent in this order:
  1. agent_id parameter (if provided) - highest priority
  2. permission_id parameter (selects default agent for that permission)
  3. User’s default agent (fallback)

Message Processing Flow

  1. User message is saved to the database
  2. Agent is selected based on parameters
  3. File attachments are validated and stored (if present)
  4. For background agents: task is queued for async processing
  5. For standard agents:
    • Relevant documents are retrieved from knowledge base
    • Documents are reranked if enabled
    • Additional context is added to the prompt
    • Response is streamed back via SSE
  6. Assistant message is saved with sources and status
  7. Thread title is generated for new conversations

Tool Integration

Agents can use tools during message processing. Tool calls and responses are stored in the conversation history and included in subsequent context.

Best Practices when implementing the Send Message API in your client

Client Implementation

  • Always handle streaming: Implement proper SSE parsing for real-time responses
  • Implement fallback polling: Use the message status endpoint if streaming fails
  • Show progress indicators: Update UI in real-time as content streams
  • Handle reconnection: Retry stream connections on network errors
  • Display sources: Show knowledge sources to build user trust

File Uploads

  • Validate client-side: Check file size and type before upload to save bandwidth
  • Show upload progress: Provide feedback during file upload
  • Handle errors gracefully: Display clear error messages for file issues
  • Preview files: Let users review files before sending

Performance

  • Limit file sizes: Keep files under 10MB for optimal processing
  • Use appropriate agents: Select specialized agents for specific tasks
  • Monitor background tasks: Check progress regularly for long-running operations

Security

  • Sanitize content: Clean user input before processing
  • Check file types: Only allow safe file types for upload
  • Rate limiting: Implement rate limits to prevent abuse