UNPKG

@guardaian/sdk

Version:

Zero-friction AI governance and monitoring SDK for Node.js applications

531 lines (393 loc) โ€ข 16.5 kB
# GuardAIan SDK [![npm version](https://badge.fury.io/js/@guardaian/sdk.svg)](https://www.npmjs.com/package/@guardaian/sdk) [![Downloads](https://img.shields.io/npm/dm/@guardaian/sdk.svg)](https://www.npmjs.com/package/@guardaian/sdk) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![AI Providers](https://img.shields.io/badge/AI_Providers-7_Supported-purple.svg)](#supported-ai-providers) [![TypeScript](https://img.shields.io/badge/TypeScript-Ready-blue.svg)](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** [![GitHub stars](https://img.shields.io/github/stars/guardaian-labs/guardaian-platform?style=social)](https://github.com/guardaian-labs/guardaian-platform) [![npm downloads](https://img.shields.io/npm/dm/@guardaian/sdk.svg)](https://www.npmjs.com/package/@guardaian/sdk) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) **โญ Star this repo if GuardAIan is securing your AI usage!** --- *Made with โค๏ธ by GuardAIan Labs* </div>