infuseai-sdk
v1.1.0
Published
NPM Client for Infuse
Downloads
307
Readme
infuseai-sdk
The official Node.js client for InfuseAI. This SDK empowers you to seamlessly integrate your custom RAG apps and Knowledge Bases into any Node.js or frontend application.
📦 Installation
npm install infuseai-sdk🚀 Usage
1. Import and Initialize
Initialize the InfuseClient with your application credentials. You can retrieve these from your App's dashboard in InfuseAI.
import { InfuseClient } from 'infuseai-sdk';
const client = new InfuseClient({
clientId: 'YOUR_CLIENT_ID', // Your User ID
appId: 'YOUR_APP_ID', // The specific AI App ID
apiKey: 'YOUR_API_KEY', // The API Key for this App
theme: 'minimal' // Optional: 'minimal', 'gradient', 'bubble', etc.
});2. Query Your App
Send prompts to your AI using the query method. The SDK manages context retrieval (RAG) and LLM inference behind the scenes.
async function askMyAssistant() {
try {
const response = await client.query('What does the documentation say about deployment?');
console.log('Answer:', response.response);
// If your app uses a Knowledge Base, you can inspect the sources used:
if (response.sources) {
console.log('Sources Used:', response.sources.map(s => s.name));
}
} catch (error) {
console.error('Failed to query InfuseAI:', error.message);
}
}
askMyAssistant();3. Embed Chat Widget
You can easily embed the full chat interface into any DOM element using the mount method.
<!-- In your HTML -->
<div id="my-chat-container" style="height: 600px; width: 400px;"></div>
<script>
client.mount("my-chat-container");
</script>📘 API Reference
InfuseClient
Constructor
new InfuseClient(config: InfuseConfig)InfuseConfig Properties:
| Property | Type | Required | Description |
| :--------- | :------- | :------- | :---------- |
| clientId | string | Yes | Your unique user identifier from the dashboard. |
| appId | string | Yes | The ID of the specific app you want to interact with. |
| apiKey | string | Yes | The secret API key for authentication. |
| theme | string | No | Optional chat theme (default: 'minimal'). |
| baseUrl | string | No | Optional override for the API endpoint (default: Production). |
client.query(text)
Sends a prompt to the InfuseAI backend.
Signature
query(text: string): Promise<QueryResponse>Returns
A Promise resolving to a QueryResponse object:
interface QueryResponse {
response: string; // The AI's generated answer
sources?: Array<{ // Optional list of sources used for RAG
name: string; // Name of the source file/document
content: string; // Snippet of the content used
}>;
[key: string]: any;
}
### `client.mount(elementId)`
Embeds the chat widget into the specified DOM element.
#### Signature
```typescript
mount(elementId: string): voidParameters
| Parameter | Type | Description |
| :---------- | :------- | :---------- |
| elementId | string | The ID of the DOM element where the chat widget should be rendered. |
⚠️ Error Handling
The client will throw an error if:
- Missing configuration (
clientId,appId,apiKey). - Network issues prevent reaching the API.
- The API returns 4xx or 5xx status codes (e.g., Invalid API Key).
Always wrap your calls in a try/catch block to handle these gracefully.
📄 License
ISC
