Skip to content

InfuseAI SDKs

InfuseAI provides official SDKs for Node.js/TypeScript and Python, making it easy to integrate AI capabilities into your applications.

Available SDKs

Node.js / TypeScript SDK

Perfect for:

  • Frontend applications (React, Vue, Angular)
  • Backend services (Express, NestJS)
  • Serverless functions
  • Desktop applications (Electron)

Installation:

bash
npm install infuseai-sdk

View Node.js SDK Documentation →

Python SDK

Perfect for:

  • Django applications
  • Flask APIs
  • FastAPI services
  • Data science projects
  • ML pipelines

Installation:

bash
pip install infuseai

View Python SDK Documentation →

Quick Comparison

FeatureNode.js SDKPython SDK
Query API
Streaming Responses
Chat Widget
Type Safety✅ (TypeScript)✅ (Type hints)
Context Manager
Async Support

Common Features

Both SDKs provide:

  • Simple Authentication: API key-based authentication
  • Query Interface: Send prompts and receive AI responses
  • Source Citations: Access to retrieved knowledge base sources
  • Error Handling: Comprehensive error types
  • Credit Tracking: Monitor credit usage per query
  • Type Safety: Full TypeScript/Python type hints

Authentication

All SDKs require three credentials:

  • Client ID: Your unique user identifier
  • App ID: The specific AI application ID
  • API Key: Secret authentication key

Get these from your app's dashboard.

Basic Usage

typescript
import { InfuseClient } from 'infuseai-sdk';

const client = new InfuseClient({
  clientId: 'YOUR_CLIENT_ID',
  appId: 'YOUR_APP_ID',
  apiKey: 'YOUR_API_KEY',
});

const response = await client.query('What is InfuseAI?');
console.log(response.response);
python
from infuseai import InfuseClient

client = InfuseClient(
    client_id="YOUR_CLIENT_ID",
    app_id="YOUR_APP_ID",
    api_key="YOUR_API_KEY",
)

response = client.query("What is InfuseAI?")
print(response.response)

Response Format

All SDKs return responses in a consistent format:

typescript
{
  response: string;        // The AI-generated answer
  sources: Array<{         // Knowledge base sources used
    name: string;          // Document name
    content: string;       // Relevant excerpt
    score: number;         // Relevance score
  }>;
  creditsUsed: number;     // Credits consumed
  creditsLeft: number;     // Remaining credits
  responseTime: number;    // Query processing time (ms)
}

Error Handling

Both SDKs provide specific error types:

  • AuthError: Invalid credentials
  • CreditsError: Insufficient credits
  • APIError: Server or network errors
  • ConfigError: Invalid configuration
typescript
try {
  const response = await client.query('Hello');
} catch (error) {
  if (error instanceof AuthError) {
    console.error('Authentication failed');
  } else if (error instanceof CreditsError) {
    console.error('Insufficient credits');
  }
}
python
from infuseai import InfuseClient, InfuseAuthError, InfuseCreditsError

try:
    response = client.query("Hello")
except InfuseAuthError:
    print("Authentication failed")
except InfuseCreditsError:
    print("Insufficient credits")

Advanced Features

Streaming Responses

Both SDKs support streaming for real-time responses:

typescript
const stream = await client.queryStream('Tell me a story');
for await (const chunk of stream) {
  process.stdout.write(chunk);
}
python
stream = client.query_stream("Tell me a story")
for chunk in stream:
    print(chunk, end="", flush=True)

Custom Configuration

Override default settings:

typescript
const client = new InfuseClient({
  clientId: 'xxx',
  appId: 'xxx',
  apiKey: 'xxx',
  baseUrl: 'https://custom-api.example.com',
  timeout: 30000,
  retries: 3,
});
python
client = InfuseClient(
    client_id="xxx",
    app_id="xxx",
    api_key="xxx",
    base_url="https://custom-api.example.com",
    timeout=30,
    max_retries=3,
)

Best Practices

  1. Secure Credentials: Never hardcode API keys in source code
  2. Environment Variables: Use .env files for credentials
  3. Error Handling: Always implement proper error handling
  4. Rate Limiting: Implement client-side rate limiting
  5. Caching: Cache responses when appropriate
  6. Monitoring: Track credit usage and errors

Next Steps

Choose your SDK and dive deeper:

Support

Need help with the SDKs?

Released under the ISC License.