API
Overview
The Chat API provides endpoints for message handling, chat history management, and bot interactions. Built on Next.js 15 and deployed on Vercel, it follows a serverless-first architecture with multi-agent support.
Endpoints
Send Message
Webhook Handler
Data Types
Message Types
Keyboard Types
Database Operations
Store Message
Get Chat History
Update Chat History
Error Handling
Error Types
Common Errors
400 Bad Request
: Invalid message format or parameters401 Unauthorized
: Invalid bot token or missing authentication403 Forbidden
: Insufficient permissions or unauthorized agent429 Too Many Requests
: Rate limit exceeded (function or message)500 Internal Server Error
: Server-side error or external service failure
Rate Limiting
Function Calls
Message Sending
Security
Authentication
Bot token validation per agent
User permission checks
Group membership verification
Agent authorization
Input Validation
Message content sanitization
Parameter validation
Type checking
SQL injection prevention
Error Messages
Best Practices
API Usage
Implement proper error handling
Follow rate limiting guidelines
Use appropriate content types
Validate all inputs
Handle timeouts gracefully
Security
Validate all inputs
Sanitize responses
Handle errors securely
Use HTTPS only
Implement proper authentication
Follow least privilege principle
Performance
Cache when possible
Use appropriate indexes
Monitor response times
Implement retry logic
Handle concurrent requests
Use connection pooling
Multi-Agent Support
Validate agent configurations
Handle agent-specific settings
Maintain separate chat histories
Implement proper error boundaries
Monitor agent performance
Related Documentation
Last updated