Package Installation
Install the Wassist SDK using your preferred package manager:
Requirements
Node.js 18.0 or later (for native fetch support)
TypeScript 4.7+ (optional, but recommended)
The SDK uses the native fetch API. If you’re using an older Node.js version, you’ll need a fetch polyfill like node-fetch.
Basic Setup
import { createWassistClient } from '@wassist/sdk' ;
const client = createWassistClient ({
baseUrl: 'https://api.wassist.app/api/v1/' ,
authToken: 'your-auth-token' ,
});
Configuration Options
The createWassistClient function accepts these options:
Option Type Required Description baseUrlstring | URLYes The Wassist API base URL authTokenstringNo Your API authentication token onAuthError() => voidNo Callback when authentication fails
Setting the Base URL
For production:
const client = createWassistClient ({
baseUrl: 'https://api.wassist.app/api/v1/' ,
});
For local development (if running the Wassist API locally):
const client = createWassistClient ({
baseUrl: 'http://localhost:8000/api/v1/' ,
});
Handling Authentication Errors
Set up an auth error handler to redirect users when tokens expire:
const client = createWassistClient ({
baseUrl: 'https://api.wassist.app/api/v1/' ,
authToken: userToken ,
onAuthError : () => {
// Clear stored token
localStorage . removeItem ( 'wassist_token' );
// Redirect to login
window . location . href = '/login' ;
},
});
Setting Authentication Later
You can create a client without an auth token and set it later:
const client = createWassistClient ({
baseUrl: 'https://api.wassist.app/api/v1/' ,
});
// After user logs in
client . setAuthToken ( userToken );
// To log out
client . clearAuthToken ();
This is useful for applications where authentication state changes.
TypeScript Configuration
For optimal type safety, ensure your tsconfig.json includes:
{
"compilerOptions" : {
"strict" : true ,
"moduleResolution" : "node" ,
"esModuleInterop" : true
}
}
Import Styles
Named Imports (Recommended)
import { createWassistClient , WassistClient } from '@wassist/sdk' ;
import type { Agent , Conversation , Message } from '@wassist/sdk' ;
Default Import
import WassistClient from '@wassist/sdk' ;
const client = new WassistClient ({
baseUrl: 'https://api.wassist.app/api/v1/' ,
});
Verify Installation
Test that everything is working:
import { createWassistClient } from '@wassist/sdk' ;
const client = createWassistClient ({
baseUrl: 'https://api.wassist.app/api/v1/' ,
authToken: process . env . WASSIST_TOKEN ,
});
async function test () {
try {
const { data : agents } = await client . agents . list ();
console . log ( `Connected! Found ${ agents . length } agents.` );
} catch ( error ) {
console . error ( 'Connection failed:' , error . message );
}
}
test ();
Framework-Specific Setup
Create a shared client instance: // lib/wassist.ts
import { createWassistClient } from '@wassist/sdk' ;
export const wassist = createWassistClient ({
baseUrl: process . env . NEXT_PUBLIC_WASSIST_API_URL ! ,
});
// In API routes (server-side)
export function getServerClient ( token : string ) {
return createWassistClient ({
baseUrl: process . env . WASSIST_API_URL ! ,
authToken: token ,
});
}
Create a client factory for request handling: // middleware/wassist.ts
import { createWassistClient } from '@wassist/sdk' ;
import { Request , Response , NextFunction } from 'express' ;
export function wassistClient ( req : Request , res : Response , next : NextFunction ) {
const token = req . headers . authorization ?. replace ( 'Bearer ' , '' );
req . wassist = createWassistClient ({
baseUrl: process . env . WASSIST_API_URL ! ,
authToken: token ,
onAuthError : () => {
res . status ( 401 ). json ({ error: 'Unauthorized' });
},
});
next ();
}
Use with React Query or SWR: // hooks/useWassist.ts
import { createWassistClient } from '@wassist/sdk' ;
import { useMemo } from 'react' ;
import { useAuth } from './useAuth' ;
export function useWassist () {
const { token , logout } = useAuth ();
return useMemo (() => createWassistClient ({
baseUrl: import . meta . env . VITE_WASSIST_API_URL ,
authToken: token ,
onAuthError: logout ,
}), [ token , logout ]);
}
Environment Variables
Keep your configuration secure using environment variables:
# .env
WASSIST_API_URL = https://api.wassist.app/api/v1/
WASSIST_TOKEN = your-secret-token
Never commit API tokens to version control. Use environment variables or a secrets manager.
Next Steps