Loading...
Loading...
The chat API powers the core conversational experience. It retrieves relevant document chunks, injects them as context, and streams the LLM response back to the client.
/api/chat{
"message": "What is the refund policy?",
"conversationId": "conv_abc123", // optional, creates new if omitted
"stream": true // optional, default true
}When stream: true (default), the response is sent as Server-Sent Events (SSE). Each event is a JSON chunk of the generated text.
data: {"content": "Based on "}
data: {"content": "the document, "}
data: {"content": "refunds are processed within 30 days."}
data: [DONE]{
"content": "Based on the document, refunds are processed within 30 days.",
"sources": [
{
"documentId": "doc_xyz",
"documentName": "terms-of-service.pdf",
"page": 4,
"relevanceScore": 0.92
}
],
"conversationId": "conv_abc123"
}/api/chat?conversationId=conv_abc123{
"messages": [
{
"id": "msg_001",
"role": "user",
"content": "What is the refund policy?",
"createdAt": "2025-01-15T10:30:00Z"
},
{
"id": "msg_002",
"role": "assistant",
"content": "Based on the document, refunds are processed within 30 days.",
"sources": [...],
"createdAt": "2025-01-15T10:30:05Z"
}
]
}