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-sdkView Node.js SDK Documentation →
Python SDK
Perfect for:
- Django applications
- Flask APIs
- FastAPI services
- Data science projects
- ML pipelines
Installation:
bash
pip install infuseaiView Python SDK Documentation →
Quick Comparison
| Feature | Node.js SDK | Python 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
- Secure Credentials: Never hardcode API keys in source code
- Environment Variables: Use
.envfiles for credentials - Error Handling: Always implement proper error handling
- Rate Limiting: Implement client-side rate limiting
- Caching: Cache responses when appropriate
- Monitoring: Track credit usage and errors
Next Steps
Choose your SDK and dive deeper:
- Node.js SDK Documentation - Complete Node.js guide
- Python SDK Documentation - Complete Python guide
- API Reference - REST API documentation
- Examples - Code examples and tutorials
Support
Need help with the SDKs?
- GitHub Issues
- API Reference
- Troubleshooting Guide