Quick reference
| Endpoint | Method | Purpose | Response Time | Use When |
|---|---|---|---|---|
| Chat (Sync) | POST /m2m/sites/{id}/chat | Send message and get answer immediately | 5-60s | Caller needs immediate answer |
| Chat (Async) | POST /m2m/sites/{id}/chat/async | Submit message for background processing | 100ms | Caller should not block |
| Chat Status | GET /m2m/sites/{id}/chat/requests/{requestId} | Check status of async request | 10ms | Polling async completion |
| Chat Feedback | POST /m2m/sites/{id}/chat/feedback | Rate the response quality | 100ms | Improving answer quality |
| Session List | GET /m2m/sites/{id}/sessions | List user conversations | 100ms | Tracking sessions |
| Session Close | POST /m2m/sites/{id}/chat/session/close | Mark session as closed | 100ms | Ending conversation |
Pattern 1: Synchronous chat (blocking)
Use when the user is waiting for the answer.Pattern 2: Asynchronous chat (non-blocking)
Use when you have a job queue or background processing system.Pattern 3: Collect feedback (quality monitoring)
Use after each completed response to track answer quality.Pattern 4: Retrieve conversation history
Use to look up past sessions for a user.Pattern 5: Close sessions explicitly
Use when a conversation ends (user resolution, timeout, etc.).Session strategy
Before using any chat endpoint, define yoursession_id strategy:
Option A: Per-user sessions
Best for chat applications where one user = one long conversation.- One session per user account
- Conversation history grows over time
- Follow-up questions maintain context
- Close explicitly when user logs out
Option B: Per-thread sessions
Best for ticket or thread-based systems.- One session per support ticket
- Clear conversation boundaries
- Easy to archive
- Close when ticket resolved
Option C: Per-channel sessions
Best for multi-channel integrations (email, slack, etc.).- One session per channel + user combo
- Separate context per channel
- Can close after inactivity
- Useful for omnichannel setups
Request/response flow
Sync chat flow
Async chat flow
Feedback flow
Common patterns
Pattern: “Sync with fallback”
Try sync chat first, fall back to a template answer if it times out.Pattern: “Async with webhook”
Submit async chat and notify via webhook when complete.Error handling checklist
✓ Treat400 as a payload error (fix request)✓ Treat
401 as auth failure (check key, rotation)✓ Treat
403 as access denied (check plan/permissions)✓ Treat
404 as resource not found (check IDs)✓ Retry
429 and 5xx with exponential backoff✓ Don’t retry
4xx (except 429) without fixing the request✓ Async polling has an overall timeout
✓ User-facing errors are safe and don’t expose API details See Error Handling Catalog for complete guidance.
Production readiness
Before deploying chat integrations: ✓ All HTTP calls have timeouts✓ Retries are bounded and selective
✓ Session IDs are stable across requests
✓ Feedback collection is wired correctly
✓ Async polling respects timeouts
✓ Monitoring and alerting are configured
✓ Logs do not contain API keys
✓ User-facing errors are safe
✓ Staging smoke test passed
Related resources
- M2M API Overview — High-level architecture
- API Authentication — Key management
- M2M Integration Guidelines — Production rules
- Error Handling Catalog — How to handle failures
- M2M Code Samples — Working examples