Getting Started
Learn how to install and use the Akioudai Safety SDK to add robust safety measures to your AI systems.
Prerequisites
Before you begin, ensure you have the following requirements in place:
System Requirements
- Node.js 14 or higher
- npm 6+ or yarn 1.22+
- An active Akioudai account
- API credentials (obtain from your dashboard)
The SDK is compatible with most modern JavaScript frameworks and runtime environments, including:
Server-side Node.js applications and services
React, Vue, Angular, and other frontend frameworks
AWS Lambda, Azure Functions, Vercel Functions
Installation
The Akioudai Safety SDK is available as a private npm package. To install it, you need to first authenticate with our private registry.
Important
To request access to our private registry, please contact our sales team or use the Request Access button on our SDK documentation page.
Installing with npm
# Authenticate with our private registry
npm config set @akioudai:registry https://registry.akioudai.ai/
npm config set //registry.akioudai.ai/:_authToken="YOUR_AUTH_TOKEN"
# Install the SDK
npm install @akioudai/safety-sdk
Installing with yarn
# Authenticate with our private registry
yarn config set @akioudai:registry https://registry.akioudai.ai/
yarn config set //registry.akioudai.ai/:_authToken "YOUR_AUTH_TOKEN"
# Install the SDK
yarn add @akioudai/safety-sdk
Authentication
Once installed, you need to authenticate the SDK with your API credentials. We recommend using environment variables to securely store these credentials.
Setting up environment variables
Create a .env
file in your project root with the following content:
# .env file
AKIOUDAI_API_KEY=your_api_key_here
AKIOUDAI_API_SECRET=your_api_secret_here
Security Best Practices
- Never hardcode API credentials in your source code
- Add
.env
to your.gitignore
file - Provide different access levels for development, staging, and production
- Regularly rotate your API keys
Loading environment variables
In Node.js, you can use the dotenv
package to load these environment variables:
// Install dotenv first:
// npm install dotenv
// At the top of your entry file (e.g., index.js)
require('dotenv').config();
// Then access environment variables
const apiKey = process.env.AKIOUDAI_API_KEY;
const apiSecret = process.env.AKIOUDAI_API_SECRET;
Basic Usage
Here's a simple example of how to use the Safety SDK to implement safety guardrails for your AI model:
1// Import the SDK2import { SafetyGuard } from '@akioudai/safety-sdk';34// Initialize the safety guard with your API credentials5const guard = new SafetyGuard({6 apiKey: process.env.AKIOUDAI_API_KEY,7 apiSecret: process.env.AKIOUDAI_API_SECRET,8 boundaries: ['ethics', 'bias', 'toxicity'],9 threshold: 0.9510});1112// Function to check AI model outputs13async function checkModelOutput(output) {14 try {15 // Monitor the model output for safety violations16 const result = await guard.monitor(output, {17 realtime: true,18 callbacks: {19 onViolation: (violation) => {20 console.log('Safety violation detected:', violation);21 // Take appropriate action (e.g., filter, log, alert)22 }23 }24 });25 26 // If the output is safe, return it27 if (result.safe) {28 return output;29 } else {30 // Otherwise, return a modified or filtered output31 return result.filteredOutput || 'I cannot provide that response';32 }33 } catch (error) {34 console.error('Error monitoring model output:', error);35 // Fallback response in case of error36 return 'Sorry, I encountered an error processing your request';37 }38}
Understanding the response
The monitor
method returns a response object with the following properties:
{
safe: boolean, // Whether the output is safe
violations: [ // Array of detected violations (if any)
{
type: string, // Type of violation (e.g., 'ethics', 'bias')
severity: number, // Severity score (0-1)
details: string, // Description of the violation
span: { // Location of the violation in the output
start: number,
end: number
}
}
],
filteredOutput: string, // Modified output with violations removed/replaced
metrics: { // Performance metrics
latency: number, // Processing time in ms
score: number // Overall safety score (0-1)
}
}
Next Steps
Now that you have the SDK installed and configured, you can explore more advanced features:
Agent Alignment
Learn how to align AI agents with specific objectives and safety guidelines.
Learn moreSafety Guardrails
Explore advanced safety guardrails for different types of content and contexts.
Learn more