Chat API
The Chat API provides interactive Q&A capabilities with your analyzed documents. All answers include source citations with page numbers.
Send Message
Ask a question about an analyzed document.
HTTP
POST /v1/chat
Request
Headers:
Authorization: Bearer hi_live_YOUR_API_KEY
Content-Type: application/json
Body Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
analysis_id | String | Yes | Analysis ID (from /v1/analyses) |
query | String | Yes | User's question (max 500 characters) |
include_cost_estimate | Boolean | No | Include cost estimates in response (default: false) |
session_id | String | No | Session ID for conversation continuity |
Example Request
Shell
curl -X POST https://api.homeinsightai.com/v1/chat \
-H "Authorization: Bearer hi_live_YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"analysis_id": "ana_abc123xyz",
"query": "What are the issues with the roof?",
"include_cost_estimate": true
}'
Response
JSON
{
"message_id": "msg_xyz789",
"query": "What are the issues with the roof?",
"answer": "The inspection report identified several roof issues:\n\n1. **Missing shingles on north slope**: Approximately 15-20 asphalt shingles are missing, exposing the underlayment to weather damage.\n\n2. **Damaged flashing around chimney**: The metal flashing shows signs of rust and improper sealing.\n\n3. **Granule loss on asphalt shingles**: Significant granule loss observed across multiple sections, indicating the roof is nearing the end of its lifespan (typically 20-25 years for asphalt shingles).",
"citations": [
{
"file": "inspection_report.pdf",
"page": 9,
"snippet": "North-facing slope shows missing shingles (est. 15-20)"
},
{
"file": "inspection_report.pdf",
"page": 10,
"snippet": "Chimney flashing exhibits rust and improper sealing"
},
{
"file": "inspection_report.pdf",
"page": 9,
"snippet": "Granule loss observed on approximately 40% of visible shingles"
}
],
"estimated_cost": {
"total": {
"low": 2500,
"high": 4500,
"currency": "USD"
},
"breakdown": [
{
"item": "Shingle replacement (north slope)",
"quantity": "20 shingles",
"cost": { "low": 800, "high": 1200 }
},
{
"item": "Chimney flashing repair",
"quantity": "1 chimney",
"cost": { "low": 600, "high": 900 }
},
{
"item": "Full roof replacement (recommended within 2-3 years)",
"quantity": "1 roof",
"cost": { "low": 8500, "high": 15000 },
"notes": "Optional - for long-term planning"
}
]
},
"related_questions": [
"What is the estimated lifespan of the current roof?",
"Are there any structural issues related to the roof?",
"Should I negotiate the roof repairs with the seller?"
],
"created_at": "2025-11-27T12:05:30Z"
}
Get Chat History
Retrieve all chat messages for an analysis.
HTTP
GET /v1/chat/:analysis_id/history
Query Parameters
| Parameter | Type | Description |
|---|---|---|
limit | Number | Results per page (default: 20, max: 100) |
cursor | String | Pagination cursor |
session_id | String | Filter by session ID |
Example Request
Shell
curl "https://api.homeinsightai.com/v1/chat/ana_abc123xyz/history?limit=10" \
-H "Authorization: Bearer hi_live_YOUR_API_KEY"
Response
JSON
{
"analysis_id": "ana_abc123xyz",
"messages": [
{
"message_id": "msg_001",
"query": "What are the major issues?",
"answer": "The inspection identified 12 issues total...",
"created_at": "2025-11-27T12:00:00Z"
},
{
"message_id": "msg_002",
"query": "What are the issues with the roof?",
"answer": "The inspection report identified several roof issues...",
"created_at": "2025-11-27T12:05:30Z"
}
],
"meta": {
"total_count": 2,
"has_more": false
}
}
Clear Chat History
Delete all chat messages for an analysis.
HTTP
DELETE /v1/chat/:analysis_id
Example Request
Shell
curl -X DELETE https://api.homeinsightai.com/v1/chat/ana_abc123xyz \
-H "Authorization: Bearer hi_live_YOUR_API_KEY"
Response
JSON
{
"analysis_id": "ana_abc123xyz",
"messages_deleted": 12,
"deleted_at": "2025-11-27T12:30:00Z"
}
Streaming Responses
For real-time chat experiences, use Server-Sent Events (SSE):
HTTP
POST /v1/chat/stream
Example Request
Shell
curl -X POST https://api.homeinsightai.com/v1/chat/stream \
-H "Authorization: Bearer hi_live_YOUR_API_KEY" \
-H "Content-Type: application/json" \
-H "Accept: text/event-stream" \
-d '{
"analysis_id": "ana_abc123xyz",
"query": "What are the issues with the roof?"
}'
Response (SSE Stream)
event: message
data: {"type": "start", "message_id": "msg_xyz789"}
event: message
data: {"type": "content", "delta": "The inspection "}
event: message
data: {"type": "content", "delta": "report identified "}
event: message
data: {"type": "content", "delta": "several roof issues:\n\n"}
event: message
data: {"type": "citation", "file": "inspection_report.pdf", "page": 9}
event: message
data: {"type": "content", "delta": "1. Missing shingles..."}
event: message
data: {"type": "done", "message_id": "msg_xyz789"}
Best Practices
1. Cost Estimation
Only request cost estimates when needed:
JSON
{
"include_cost_estimate": true // Adds ~2s to response time
}
2. Session Management
Use session IDs for multi-turn conversations:
JSON
{
"session_id": "sess_abc123",
"query": "What about the plumbing?" // Maintains context
}
3. Related Questions
Use the related_questions field to guide users:
JavaScript
// Display suggested questions
response.related_questions.forEach(question => {
console.log(`- ${question}`)
})
4. Citation Display
Always show citations for transparency:
JavaScript
// Example citation UI
citations.forEach(cit => {
console.log(`Source: ${cit.file}, Page ${cit.page}`)
console.log(`"${cit.snippet}"`)
})
Rate Limits
Chat endpoints have separate rate limits:
| Tier | Messages/Minute | Messages/Month |
|---|---|---|
| Free Trial | 5 | 50 |
| Pay-Per-Report | 30 | Unlimited (30 days) |
| Pro | 100 | Unlimited |
| Enterprise | Custom | Unlimited |
Error Handling
Common Errors
Analysis not ready:
JSON
{
"error": {
"code": "analysis_not_ready",
"message": "Analysis is still processing. Please try again in 30 seconds.",
"retry_after": 30
}
}
Empty query:
JSON
{
"error": {
"code": "invalid_query",
"message": "Query cannot be empty"
}
}
No relevant information:
JSON
{
"answer": "I couldn't find specific information about that in the uploaded documents. Could you rephrase your question or ask about something else?",
"citations": [],
"confidence": "low"
}
Next Steps
- Analyses API - Upload and analyze documents
- React SDK - Embed chat widget
- Webhooks - Get notified of new messages