Overview
The HAI Protocol is fully specified using OpenAPI 3.1.0. This specification defines all endpoints, message schemas, and protocol components for implementing HAIP-compliant clients and servers.Interactive Documentation
You can explore the complete HAI Protocol specification using the interactive OpenAPI documentation below:Key Components
Transport Endpoints
- WebSocket: 
/haip/websocket- Primary real-time communication - Server-Sent Events: 
/haip/sse- HTTP-based streaming - HTTP Streaming: 
/haip/stream- Chunked transfer encoding 
Message Structure
All HAIP messages follow a consistent envelope structure:Event Types
Core Events
HAI- Initial Message To Open ConnectionPING/PONG- Keep alive messagesINFO- Info messagesERROR- Error messageFLOW_UPDATE- Flow controlTRANSACTION_START- Start a new transactionTRANSACTION_END- End transactionTRANSACTION_JOIN- Join an existing transactionREPLAY_REQUEST- replay messagesMESSAGE- Send a message that will be validated against the tool schemaMESSAGE_UPDATE- Edit/delete messagesAUDIO- Send audio to a toolTOOL_LIST- List out all the toolsTOOL_SCHEMA- Get the schema for a tool
Authentication
HAIP allows the user to bring their own authentication. Which is converted into aHAIPUser:
{"MESSAGE": ["46ec7297-399c-40c5-bf5a-28503a3899b1"]}
Often you will want to give admins permissions to join all transactions and edit all messages.
Binary Frames
For audio, video, and file transmission, HAIP supports binary frames:- Envelope: JSON message with 
bin_lenandbin_mime - Binary Data: Raw binary data following the envelope
 - Fragmentation: Large files split into multiple frames
 
Flow Control
Credit-based back-pressure management:- Initial Credits: Configurable per user
 - Credit Thresholds: Automatic credit requests
 - Back-Pressure Detection: Automatic channel pausing
 - Adaptive Adjustment: Performance-based credit tuning
 
Implementation Examples
These are examples that don’t use the existing SDK. We reccomend using the SDK, for most applications.WebSocket Client
Server-Sent Events Client
HTTP Streaming Client
Error Handling
HAIP defines standard error codes and recovery strategies:- 1000: Normal closure
 - 1001: Going away
 - 1002: Protocol error
 - 1003: Unsupported data
 - 1006: Abnormal closure
 - 1007: Invalid frame payload
 - 1008: Policy violation
 - 1009: Message too big
 - 1011: Internal error
 
Best Practices
Client Implementation
- 
Connection Management
- Implement automatic reconnection
 - Handle connection timeouts gracefully
 - Use exponential backoff for retries
 
 - 
Message Handling
- Validate message structure
 - Handle binary frames correctly
 - Implement proper error recovery
 
 - 
Flow Control
- Respect credit limits
 - Implement back-pressure handling
 - Monitor performance metrics
 
 
Server Implementation
- 
Authentication
- Validate credentials
 - Check permissions
 - Implement proper error responses
 
 - 
Message Processing
- Validate message schemas
 - Handle binary data efficiently
 - Implement proper flow control
 
 - 
Error Handling
- Provide meaningful error messages
 - Implement proper cleanup
 - Log errors for debugging
 
 
Testing
Use the provided OpenAPI specification to generate test cases and validate your implementation:Compliance
To ensure HAI Protocol compliance:- Schema Validation: Validate all messages against the OpenAPI schemas
 - Event Handling: Implement all required event types
 - Flow Control: Respect credit-based flow control
 - Error Handling: Use standard error codes and messages
 - Authentication: Implement JWT token validation