Overview
The Hazel Chat API is built on Effect RPC, providing a type-safe, functional approach to API communication. The RPC system offers automatic serialization, error handling, and seamless integration between frontend and backend.Key Features
- Type-Safe: Full TypeScript type safety from client to server
- Effect-Based: Built on Effect for composable, functional error handling
- Real-Time Ready: HTTP and WebSocket support for live updates
- Automatic Serialization: NDJSON protocol for efficient data transfer
- Authentication: WorkOS-based authentication with session management
- Rate Limited: Built-in rate limiting (60 requests/minute per user)
Architecture
The API uses the Effect RPC framework with the following architecture:Base URL
RPC Endpoint
All RPC calls are made to the/rpc endpoint:
Available RPC Groups
The API is organized into the following RPC groups:| Group | Description |
|---|---|
MessageRpcs | Create, update, and delete messages |
ChannelRpcs | Manage channels, DMs, and threads |
OrganizationRpcs | Organization management |
UserRpcs | User profile and settings |
NotificationRpcs | Notification preferences |
InvitationRpcs | Workspace invitations |
MessageReactionRpcs | Message reactions (emoji) |
TypingIndicatorRpcs | Real-time typing indicators |
ChannelMemberRpcs | Channel membership |
PinnedMessageRpcs | Pin important messages |
AttachmentRpcs | File uploads and attachments |
BotRpcs | Bot management and commands |
ChatSyncRpcs | External chat integration sync |
Type-Safe Client Usage
Web/Desktop Client
The frontend uses an Effect-based RPC client with automatic type inference:Bot SDK Client
Bots use a simplified HTTP-based RPC client:All RPC methods return an
Effect that must be executed using Effect’s runtime. Errors are typed and handled functionally.Rate Limiting
The API enforces rate limits to ensure fair usage:- Message Operations: 60 requests per minute per user
- Per-user tracking: Rate limits are applied per authenticated user
- Response headers: Rate limit information included in error responses
RateLimitExceededError with retry information:
Response Format
All successful RPC responses include:- Data: The requested resource(s)
- Transaction ID: For optimistic updates
Transaction IDs enable optimistic UI updates. The client can immediately show changes and reconcile them when the server response arrives.
Common RPC Methods
Message Operations
Channel Operations
Next Steps
Authentication
Learn how to authenticate API requests with WorkOS
Error Handling
Understand error types and how to handle them