Documentation Index Fetch the complete documentation index at: https://haiprotocol.com/llms.txt
Use this file to discover all available pages before exploring further.
Get started in three steps
Implement HAIP in your application with this quick guide.
📦 Install Packages
# Install SDK
npm install @haip/sdk
# Install Server
npm install @haip/server
# Install Types
npm install @types/haip
# Install CLI (optional)
npm install -g @haip/cli
Step 1: Create Server
Save this in server.js
import { createPermissionMap , HAIPServer , HAIPTool } from "@haip/server" ;
import {
HAIPEventType ,
HAIPMessage ,
HAIPSessionTransaction ,
HAIPToolSchema ,
} from "haip" ;
import OpenAI from "openai" ;
const server = new HAIPServer ({
port: 8080 ,
host: "0.0.0.0" ,
jwtSecret: "CHANGE_THIS_TO_A_SECRET_STRING" ,
enableCORS: true ,
enableLogging: true ,
flowControl: {
enabled: true ,
minCredits: 100 ,
maxCredits: 10000 ,
creditThreshold: 200 ,
backPressureThreshold: 0.8 ,
adaptiveAdjustment: true ,
},
});
server . authenticate (( req ) => {
// Here you should validate your with your auth system
// Hardcoded check here
if ( req . token === "Bearer TOKEN" ) {
return {
id: "user123" ,
permissions: createPermissionMap ({ MESSAGE: [ "*" ] }),
credits: 1000 ,
};
}
return null ;
});
server . start ();
Step 2: Create client
Save this in client.js
import { createHAIPClient } from "@haip/sdk" ;
async function main () {
const client = createHAIPClient ({
url: "ws://localhost:8080" ,
});
client . authenticate (() => {
// You should send a token here.
return {
token: "Bearer TOKEN" ,
};
});
try {
await client . connect ();
const transaction = await client . startTransaction ( "echo" , {});
transaction . on ( "message" , ( message : any ) => {
console . log ( "🤖 Agent:" , message . payload );
});
console . log ( "✅ Sending to transaction:" , "Hello! Can you echo this?" );
transaction . sendTextMessage ( "Hello! Can you echo this?" );
} catch ( error ) {
console . error ( "Error:" , error );
await client . disconnect ();
}
}
main ();
Step 3: Run Locally
In the client
node server.js
node client.js
You should see something like this:
> @haip/sdk@1.0.1 example
> ts-node ./example/test-client.ts
[HAIP] Transport connecting...
[HAIP] Handshake sent
✅ Sending to transaction: Hello! Can you echo this?
🤖 Agent: Hello! Can you echo this?
Now run (assumig you are running this locally on localhost:8080)
You can also use the echo tool:
✔ Transaction started...
You: Hello This is me
🤖 Agent: Hello This is me
Authentication Secure your connections with JWT tokens and proper validation.
Tool Integration Enable agents to call external tools and APIs.
Flow Control Manage back-pressure and prevent system overload.
Error Handling Implement robust error handling and recovery.