@guardaian/sdk
Version:
Zero-friction AI governance and monitoring SDK for Node.js applications
531 lines (393 loc) โข 16.5 kB
Markdown
# GuardAIan SDK
[](https://www.npmjs.com/package/@guardaian/sdk)
[](https://www.npmjs.com/package/@guardaian/sdk)
[](https://opensource.org/licenses/MIT)
[](#supported-ai-providers)
[](https://www.typescriptlang.org/)
<div align="center">
## **Monitor ALL your AI usage with one line of code**
**The only SDK that automatically tracks OpenAI, Anthropic, Google, Azure, AWS, Cohere & Hugging Face**
[**๐ Get Started Free**](https://app.guardaianlabs.com) โข [**๐ Documentation**](https://github.com/guardaian-labs/guardaian-platform/wiki) โข [**๐ฌ Support**](https://github.com/guardaian-labs/guardaian-platform/discussions)
### **โจ One import. Zero code changes. Complete AI governance.**
</div>
## ๐ **Quick Start (30 seconds)**
```bash
npm install @guardaian/sdk
```
```javascript
import '@guardaian/sdk/auto';
import { GuardAIan } from '@guardaian/sdk';
GuardAIan.init({ apiKey: 'gai_your_key' }); // Get free key at app.guardaianlabs.com
// Your existing AI code now tracked automatically! ๐ก๏ธ
const response = await openai.chat.completions.create({
model: 'gpt-4',
messages: [{ role: 'user', content: 'Hello!' }]
});
// โ
Cost, tokens, compliance automatically tracked in dashboard
```
**โ
Zero code changes โข โ
All AI providers โข โ
Free dashboard**
[**๐ Get Free API Key**](https://app.guardaianlabs.com) โข [**๐ Full Documentation**](https://github.com/guardaian-labs/guardaian-platform/wiki)
## ๐ **Production-Ready AI Governance**
<div align="center">
**Enterprise-grade reliability โข Developer-friendly integration โข Comprehensive monitoring**
Built for companies that need complete AI governance without compromising developer velocity.
From startups to enterprise, GuardAIan scales with your AI usage.
**โ
Zero-downtime deployment**
**โ
Enterprise security standards**
**โ
Comprehensive provider coverage**
**โ
Real-time monitoring & alerts**
</div>
## ๐ก **Why GuardAIan SDK?**
### **๐ฏ Universal Coverage**
- **7 AI providers supported** - OpenAI, Anthropic, Google, Azure, AWS, Cohere, Hugging Face
- **85% market coverage** - Works with all major enterprise AI services
- **One SDK for everything** - No more juggling multiple monitoring tools
### **โก Zero Friction**
- **One import line** - `import '@guardaian/sdk/auto'`
- **No code changes** - Works with your existing AI implementations
- **Drop-in replacement** - Transparent interception, identical APIs
### **๐ก๏ธ Enterprise Ready**
- **Real-time compliance** - Instant policy enforcement
- **Complete audit trails** - Full regulatory compliance (SOC2, GDPR)
- **Professional dashboards** - Executive-ready reporting
### **๐ฐ Immediate ROI**
- **Cost optimization** - Track spending across all AI services
- **Usage insights** - Optimize AI usage patterns
- **Policy enforcement** - Prevent budget overruns automatically
## ๐ค **Supported AI Providers**
| Provider | Models | Package | Status |
|----------|--------|---------|--------|
| **๐ค OpenAI** | GPT-4, GPT-3.5, DALL-E | `openai` | โ
**Full Support** |
| **๐ง Anthropic** | Claude 3.5 Sonnet, Opus | `@anthropic-ai/sdk` | โ
**Full Support** |
| **๐ Google** | Gemini Pro, Flash | `@google/generative-ai` | โ
**Full Support** |
| **โ๏ธ Azure OpenAI** | Enterprise GPT models | `openai` + Azure | โ
**Full Support** |
| **๐ถ AWS Bedrock** | Claude, Llama, Titan | `@aws-sdk/client-bedrock-runtime` | โ
**Full Support** |
| **๐ฆ Cohere** | Command-R, Embeddings | `cohere-ai` | โ
**Full Support** |
| **๐ค Hugging Face** | Open Source Models | `@huggingface/inference` | โ
**Full Support** |
**๐ฏ Covers 85% of enterprise AI usage**
## ๐ป **Usage Examples**
### **๐ค OpenAI (Most Popular)**
```javascript
import { GuardAIan } from '@guardaian/sdk';
import '@guardaian/sdk/auto';
import OpenAI from 'openai';
GuardAIan.init({ apiKey: 'gai_abc123' });
const openai = new OpenAI({ apiKey: 'sk-...' });
// Automatically tracked: cost, tokens, duration, compliance
const response = await openai.chat.completions.create({
model: 'gpt-4',
messages: [{ role: 'user', content: 'Hello!' }]
});
// Dashboard shows: $0.006 cost, 150 tokens, 1.2s duration โ
```
### **๐ง Anthropic Claude**
```javascript
import Anthropic from '@anthropic-ai/sdk';
const anthropic = new Anthropic({ apiKey: 'sk-ant-...' });
// Automatically tracked with GuardAIan
const message = await anthropic.messages.create({
model: 'claude-3-5-sonnet-20241022',
max_tokens: 1000,
messages: [{ role: 'user', content: 'Analyze this data...' }]
});
// Tracks: Claude-specific pricing, token usage, compliance
```
### **๐ Google Gemini (Free Testing)**
```javascript
import { GoogleGenerativeAI } from '@google/generative-ai';
const genAI = new GoogleGenerativeAI('your-api-key');
const model = genAI.getGenerativeModel({ model: 'gemini-pro' });
// Automatically tracked with GuardAIan
const result = await model.generateContent('Explain quantum computing');
// Perfect for free testing - no credit card required!
// Get free key: https://makersuite.google.com/app/apikey
```
### **โ๏ธ Azure OpenAI (Enterprise)**
```javascript
import OpenAI from 'openai';
const azure = new OpenAI({
apiKey: 'your-azure-key',
baseURL: 'https://your-resource.openai.azure.com/openai/deployments/gpt-4',
defaultQuery: { 'api-version': '2024-02-01' }
});
// Tracked separately as 'azure-openai' service
const response = await azure.chat.completions.create({...});
```
## โ๏ธ **Configuration**
### **๐ง Basic Setup**
```javascript
GuardAIan.init({
apiKey: 'gai_abc123', // Required: Your GuardAIan API key
environment: 'production', // Optional: Environment name
projectName: 'my-ai-app', // Optional: Project identifier
debug: false // Optional: Enable debug logging
});
```
### **๐ Advanced Configuration**
```javascript
GuardAIan.init({
apiKey: 'gai_abc123',
baseURL: 'https://api.guardaianlabs.com', // Optional: Custom API endpoint
environment: 'production', // Optional: Environment name
projectName: 'my-ai-app', // Optional: Project identifier
debug: false, // Optional: Enable debug logging
batchSize: 10, // Optional: Batch size for API calls
flushInterval: 5000, // Optional: Flush interval in ms
customTags: ['team:ml', 'cost-center:r&d'] // Optional: Custom metadata tags
});
```
### **๐ข Environment-Specific Setup**
```javascript
// Use environment variables for different stages
GuardAIan.init({
apiKey: process.env.GUARDAIAN_API_KEY,
environment: process.env.NODE_ENV,
projectName: 'your-app-name',
debug: process.env.NODE_ENV !== 'production'
});
```
## ๐ **What Gets Tracked Automatically**
### **๐ฐ Complete Cost Analysis**
- **Real-time cost calculation** with provider-specific pricing
- **Token usage breakdown** (input/output tokens)
- **Cost per model** and operation type
- **Budget tracking** with automatic alerts
### **โก Performance Monitoring**
- **Response time tracking** for optimization
- **API call success/failure rates**
- **Performance comparisons** between models
- **Usage patterns** and trends
### **๐ก๏ธ Compliance & Governance**
- **Automatic policy enforcement** in real-time
- **Usage limit monitoring** (calls, tokens, spend)
- **Model restriction enforcement**
- **Security scanning** and violation alerts
### **๐ Business Intelligence**
- **Usage analytics** across teams and projects
- **Cost optimization insights** and recommendations
- **Executive reporting** with trends and forecasts
- **ROI analysis** for AI investments
## ๐ก๏ธ **Compliance & Governance**
GuardAIan automatically enforces your organization's AI policies:
```javascript
// Your dashboard policies are enforced automatically:
// โ Usage Limits: Max 1000 API calls per day
// โ Budget Controls: Max $500/month across all AI services
// โ Model Restrictions: Only allow GPT-3.5 and Claude-3-haiku
// โ Time Restrictions: AI usage only during business hours
// โ Content Filtering: Block sensitive data patterns
const response = await openai.chat.completions.create({
model: 'gpt-4', // Might be blocked by policy
messages: [{ role: 'user', content: 'Hello!' }]
});
// Policy violations are automatically:
// ๐จ Logged to your dashboard
// ๐ง Sent as alerts to admins
// ๐ Included in compliance reports
// โ
Your code continues to work normally
```
**๐ Enterprise Security:**
- **SOC 2 Type II** compliant infrastructure
- **GDPR compliant** data handling
- **No sensitive data stored** - Only metadata tracked
- **API keys encrypted** in transit and at rest
## ๐ป **TypeScript Support**
Full TypeScript definitions included:
```typescript
import { GuardAIan, TrackingData, GuardAIanOptions } from '@guardaian/sdk';
// Fully typed initialization
const config: GuardAIanOptions = {
apiKey: 'gai_abc123',
environment: 'production',
debug: false
};
GuardAIan.init(config);
// Type-safe manual tracking
const event: TrackingData = {
service: 'openai',
model: 'gpt-4',
operation: 'chat.completion',
inputTokens: 100,
outputTokens: 50,
cost: 0.006
};
await guardaian.track(event);
```
## ๐ง **Manual Tracking & Advanced Usage**
### **Manual Event Tracking**
```javascript
import { GuardAIan } from '@guardaian/sdk';
const guardaian = new GuardAIan({ apiKey: 'gai_abc123' });
// Track custom AI usage
await guardaian.track({
service: 'openai',
model: 'gpt-4',
operation: 'chat.completion',
inputTokens: 100,
outputTokens: 50,
cost: 0.006,
duration: 1200,
metadata: {
userId: 'user123',
feature: 'chat-assistant'
}
});
```
### **Status Checking & Debugging**
```javascript
// Check if SDK is properly initialized
if (GuardAIan.isInitialized()) {
console.log('โ
GuardAIan is ready!');
}
// Enable debug logging
GuardAIan.init({
apiKey: 'gai_abc123',
debug: true
});
// Console output:
// ๐ก๏ธ GuardAIan: Intercepted OpenAI call...
// ๐ฐ Cost: $0.006, Tokens: 150, Duration: 1.2s
// โ
Successfully sent to dashboard
```
## ๐ก๏ธ **Error Handling & Reliability**
GuardAIan is designed to **never break your AI applications**:
### **๐ Fail-Safe Design**
```javascript
// Even if GuardAIan is completely down, your AI calls work normally
const response = await openai.chat.completions.create({...});
// โ
Always works - tracking is an enhancement, not a dependency
```
### **๐ Resilient Architecture**
- **Non-blocking tracking** - Network issues don't affect your app
- **Automatic retries** - Failed tracking calls are retried automatically
- **Graceful degradation** - Invalid config disables monitoring silently
- **Error isolation** - GuardAIan errors never bubble up to your code
### **โก Performance**
- **< 1ms overhead** per API call
- **Async background processing** - non-blocking
- **Intelligent batching** - efficient network usage
- **Memory efficient** - automatic cleanup
## ๐ **Getting Started Guide**
### **Step 1: Get Your API Key**
1. ๐ **Sign up** at [app.guardaianlabs.com](https://app.guardaianlabs.com)
2. ๐ **Create a project** for your application
3. ๐ **Generate API key** from the dashboard
4. ๐ก๏ธ **Set up policies** (optional but recommended)
### **Step 2: Install & Initialize**
```bash
npm install @guardaian/sdk
```
```javascript
// Add to your application entry point
import { GuardAIan } from '@guardaian/sdk';
import '@guardaian/sdk/auto';
GuardAIan.init({
apiKey: process.env.GUARDAIAN_API_KEY,
environment: process.env.NODE_ENV,
projectName: 'your-app-name'
});
```
### **Step 3: Verify Setup**
```javascript
// Run a test AI call and check your dashboard
const response = await openai.chat.completions.create({
model: 'gpt-3.5-turbo',
messages: [{ role: 'user', content: 'Hello GuardAIan!' }]
});
// โ
Check https://app.guardaianlabs.com for the tracked usage
```
## ๐งช **Testing & Development**
### **๐ง Development Setup**
```javascript
// Environment-specific configuration
GuardAIan.init({
apiKey: process.env.NODE_ENV === 'production'
? process.env.GUARDAIAN_PROD_KEY
: process.env.GUARDAIAN_DEV_KEY,
environment: process.env.NODE_ENV,
debug: process.env.NODE_ENV === 'development'
});
```
### **๐งช Free Testing with Google Gemini**
```javascript
// Perfect for development - no credit card required
import { GoogleGenerativeAI } from '@google/generative-ai';
const genAI = new GoogleGenerativeAI('your-free-api-key');
const model = genAI.getGenerativeModel({ model: 'gemini-1.5-flash' });
const result = await model.generateContent('Test GuardAIan tracking');
// Get free API key: https://makersuite.google.com/app/apikey
```
## ๐ **Documentation & Resources**
### **๐ Documentation**
- **[Complete API Reference](https://github.com/guardaian-labs/guardaian-platform/wiki)** - Full SDK documentation
- **[Quick Start Guide](https://github.com/guardaian-labs/guardaian-platform/wiki/Quick-Start)** - Get running in 5 minutes
- **[Provider Setup Guides](https://github.com/guardaian-labs/guardaian-platform/wiki/Providers)** - Setup for each AI service
- **[Enterprise Features](https://github.com/guardaian-labs/guardaian-platform/wiki/Enterprise)** - Advanced configuration
### **๐ฌ Community & Support**
- **[GitHub Discussions](https://github.com/guardaian-labs/guardaian-platform/discussions)** - Community Q&A
- **[GitHub Issues](https://github.com/guardaian-labs/guardaian-platform/issues)** - Bug reports and feature requests
- **[Support Email](mailto:support@guardaianlabs.com)** - Direct technical support
### **๐ฅ Learning Resources**
- **[Blog Posts](https://blog.guardaianlabs.com)** - AI governance insights and tips
- **[Case Studies](https://guardaianlabs.com/case-studies)** - Real customer success stories
## ๐
**Changelog & Roadmap**
### **๐ Current Version: 1.0.0**
- โ
Universal AI provider support (7 providers)
- โ
Real-time cost calculation
- โ
Automatic compliance checking
- โ
TypeScript definitions
- โ
Enterprise security features
### **๐ฎ Coming Soon**
- ๐ง **More AI Providers** - Stability AI, AI21 Labs
- ๐ **Advanced Analytics** - Usage forecasting, anomaly detection
- ๐ **Webhook Support** - Real-time notifications
- ๐ **Multi-region Support** - Global deployment options
## ๐ **License**
MIT License - see [LICENSE](LICENSE) file for details.
**Privacy & Security:**
- [Privacy Policy](https://guardaianlabs.com/privacy)
- [Terms of Service](https://guardaianlabs.com/terms)
- [Security](https://guardaianlabs.com/security)
## ๐ฏ **Ready to Get Started?**
### **๐ Free Trial - No Credit Card Required**
```bash
# Install and start monitoring in under 2 minutes
npm install @guardaian/sdk
# Sign up and get your API key
# https://app.guardaianlabs.com/signup
# Add these two lines to your app
import { GuardAIan } from '@guardaian/sdk';
import '@guardaian/sdk/auto';
GuardAIan.init({ apiKey: 'your_api_key' });
# Your existing AI code now has complete governance! ๐ก๏ธ
```
**[๐ Start Free Trial](https://app.guardaianlabs.com/signup)** โข **[๐ Read Full Docs](https://github.com/guardaian-labs/guardaian-platform/wiki)** โข **[๐ฌ Get Support](https://github.com/guardaian-labs/guardaian-platform/discussions)**
<div align="center">
### **๐ก๏ธ The Complete AI Governance Solution**
**Built for developers who use AI responsibly**
[](https://github.com/guardaian-labs/guardaian-platform)
[](https://www.npmjs.com/package/@guardaian/sdk)
[](https://opensource.org/licenses/MIT)
**โญ Star this repo if GuardAIan is securing your AI usage!**
*Made with โค๏ธ by GuardAIan Labs*
</div>