Get started with HAIP in minutes
# 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
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();
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();
node server.js node client.js
> @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?
haip chat --tool echo
✔ Transaction started... You: Hello This is me 🤖 Agent: Hello This is me
Was this page helpful?