
Research
/Security News
OpenAPI React Query Codegen Compromised in Mini Shai-Hulud npm Supply Chain Attack
Ten malicious OpenAPI React Query Codegen versions were published to npm in the Mini Shai-Hulud attack, all with valid provenance.
@dirigible-ai/sdk
Advanced tools
JavaScript / TypeScript library for the Dirigible AI API.
A lightweight SDK for monitoring AI and Large Language Model (LLM) workflows.
Simply wrap your AI clients and add a decorator for complete observability.
observeAIClient wrapper for all AI providersnpm install @dirigible-ai/sdk
Follow those four simple steps to fully track your AI workflows and interactions with specific metadata.
Sign up for a free account at https://dirigible.ai to get your API key.
Initialize the SDK using your Dirigible API key and project ID:
import { initialize } from '@dirigible-ai/sdk';
initialize({
apiKey: 'your-api-key',
projectId: 'your-project-id',
// Optional parameters
environment: 'production' // or 'development', 'staging', etc.
});
See the full list of supported parameters in the Configuration options section.
To add observability, simply wrap your AI clients using observeAIClient:
import { observeAIClient } from '@dirigible-ai/sdk';
import OpenAI from 'openai';
// Initialize and wrap your AI clients
let openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });
openai = observeAIClient(openai);
// Then use your AI clients normally - everything is automatically logged!
const response = await openai.chat.completions.create({
model: 'gpt-4o',
messages: [{ role: 'user', content: 'Hello world' }]
});
Alternatively, create and wrap in one step:
const openai = observeAIClient(new OpenAI({
apiKey: process.env.OPENAI_API_KEY
}));
The SDK supports OpenAI, Anthropic and Google clients:
import { observeAIClient } from '@dirigible-ai/sdk';
import OpenAI from 'openai';
import Anthropic from '@anthropic-ai/sdk';
import { GoogleGenAI } from '@google/genai';
let openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });
openai = observeAIClient(openai);
let anthropic = new Anthropic({ apiKey: process.env.ANTHROPIC_API_KEY });
anthropic = observeAIClient(anthropic);
let gemini = new GoogleGenAI({ apiKey: process.env.GEMINI_API_KEY });
gemini = observeAIClient(gemini);
With those two steps (initializing + wrapping), the application workflow and corresponding interactions are captured and logged to Dirigible.
You can add workflow-specific metadata when initializing:
import { initialize } from '@dirigible-ai/sdk';
// Initialize with optional workflow metadata
initialize({
apiKey: 'your-api-key',
projectId: 'my-project',
workflowMetadata: {
version: '1.2.0',
userType: 'premium'
}
});
Use the @observeLLM decorator to add metadata to specific interactions:
import { observeLLM } from '@dirigible-ai/sdk';
import OpenAI from 'openai';
class AIService {
private openai = observeAIClient(new OpenAI({ apiKey: 'your-openai-key' }));
// Add the decorator just above the method calling the LLM
@observeLLM({
task: 'classify_input',
userId: userId,
inputId: inputId
})
async classifyText(text: string) {
return this.openai.chat.completions.create({
model: 'gpt-4o',
messages: [{ role: 'user', content: text }]
});
}
}
You can also use a function to generate dynamic metadata:
import { observeLLM } from '@dirigible-ai/sdk';
class AIService {
@observeLLM((params) => ({
promptLength: params.messages[0].content.length,
timestamp: new Date().toISOString(),
userId: getCurrentUser().id
}))
async classifyText(text: string) {
return this.openai.chat.completions.create({
model: 'gpt-4o',
messages: [{ role: 'user', content: text }]
});
}
}
That's it! With those four steps, your AI workflows and interactions are entirely tracked and visualized in your Dirigible dashboard with the right metadata.
You can add global metadata that will be included with all requests:
import { setGlobalMetadata, addGlobalMetadata } from '@dirigible-ai/sdk';
// Set initial global metadata
setGlobalMetadata({
deploymentRegion: 'us-west',
version: '1.2.3'
});
// Add more metadata later in your workflow
addGlobalMetadata({
generatedId: generatedId
});
Global metadata is attached to the workflow, and to all interactions happening after its declaration.
It can for example be used to add metadata that is generated during the workflow.
For better traceability and easier correlation with your own systems, both workflows and individual interactions have unique IDs that you can access:
import { getWorkflowId, getInteractionId } from '@dirigible-ai/sdk';
import OpenAI from 'openai';
// Initialize your client
let openai = observeAIClient(new OpenAI({ apiKey: process.env.OPENAI_API_KEY }));
// Get the current workflow ID
const workflowId = getWorkflowId();
console.log(`Current workflow ID: ${workflowId}`);
// Make an LLM API call
const response = await openai.chat.completions.create({
model: 'gpt-4o',
messages: [{ role: 'user', content: 'Hello world' }]
});
// Get the ID of the interaction that just occurred (do it just after)
const interactionId = getInteractionId();
console.log(`Interaction ID: ${interactionId}`);
This is particularly useful for cross-system tracing and debugging complex AI workflows that span multiple services.
You can also create direct links to Dirigible to easily access those logs:
`https://dirigible.ai/workflows/${workflowId}`
`https://dirigible.ai/interactions/${interactionId}`
In addition to tracking LLM interactions, you can log data artifacts in your workflows:
import { saveArtifact } from '@dirigible-ai/sdk';
// Store vector search results used for RAG, with name and value
const searchResults = await vectorDb.search(query, { topK: 5 });
saveArtifact('search_results', searchResults);
// Optionally, log with artifact metadata and type
saveArtifact('search_results_with_meta', searchResults, {
metadata: { query, similarity_threshold: 0.8 }
type: 'vector_search',
});
You can store any serializable data structure:
saveArtifact('processed_results', {
relevant: searchResults.slice(0, 2),
irrelevant: searchResults.slice(2),
stats: {
totalResults: searchResults.length,
avgScore: searchResults.reduce((sum, r) => sum + r.score, 0) / searchResults.length,
executionTimeMs: 42
}
});
Artifacts can be used to track intermediate steps in your pipelines or see what data was used for generation.
For OpenAI streaming responses, add the stream_options parameter to capture all usage information:
const stream = await openai.chat.completions.create({
model: "gpt-4o",
messages: [{ role: "user", content: "Your prompt" }],
stream: true,
stream_options: { "include_usage": true } // This ensures capture of OpenAI stream info
});
It works out of the box for other providers.
This should be automatic but when running scripts or processes that exit quickly, you can flush logs before exiting:
import { forceFlush } from '@dirigible-ai/sdk';
// At the end of your script
async function main() {
// ...your code...
// Force flush at the end to ensure logs are sent
console.log('Forcing final flush of logs...');
await forceFlush();
// Optional: Wait a bit to ensure network requests complete
await new Promise(resolve => setTimeout(resolve, 1000));
}
main().catch(console.error);
For more control or when automatic instrumentation isn't suitable, you can manually create and manage workflows:
import { createWorkflow, logLLMInteraction, endWorkflow } from '@dirigible-ai/sdk';
class ChatService {
private llmClient: any;
constructor() {
// Initialize your LLM client here
}
// Create a chat session with explicit workflow
createChat(userId: string) {
// Create a workflow for this conversation
const chatWorkflow = createWorkflow(`chat-${Date.now()}`, {
userId,
startTime: new Date().toISOString()
});
return {
async sendMessage(message: string) {
// Get current workflow metadata
const workflowData = chatWorkflow.getMetadata();
// Make the LLM call
const response = await this.llmClient.generateResponse(message);
// Log the interaction, with workflow metadata
await logLLMInteraction({
model: 'llm-model',
request: { message },
response,
metadata: workflowData
});
// Update workflow after each message
chatWorkflow.addMetadata({
lastMessageTime: new Date().toISOString()
});
return response;
},
endChat() {
// Optionally, end the workflow when chat ends
endWorkflow({
outcome: 'completed',
finalState: 'conversation_ended'
});
}
};
}
}
The SDK can be configured with these options:
initialize({
// Required
apiKey: 'your-api-key', // Dirigible API key
projectId: 'your-project-id', // Dirigible project identifier
// Optional
apiUrl: 'https://custom-api-url.com', // Default is Dirigible API
environment: 'production', // Environment name
enabled: true, // Enable/disable logging globally
flushInterval: 1000, // Flush queue every 1 second(s) (ms)
samplingRate: 0.5, // Log a limited % of requests
trackWorkflows: true, // Enable/disable automatic workflow tracking
autoInstrument: true, // Enable/disable automatic client patching
workflowMetadata: { // Initial metadata for workflow
version: '1.2.3',
userType: 'premium'
},
logLevel: LogLevel.INFO, // Logging verbosity level
logPrefix: '[Dirigible]' // Prefix for log messages
});
The SDK includes a configurable logging system with different verbosity levels:
import { initialize, LogLevel } from '@dirigible-ai/sdk';
// Configure with custom log level
initialize({
apiKey: 'your-api-key',
projectId: 'your-project-id',
logLevel: LogLevel.INFO,
logPrefix: '[MyApp]' // Custom prefix for log messages
});
Available log levels:
LogLevel.NONE: Disable all logsLogLevel.ERROR: Only show errorsLogLevel.WARN: Show warnings and errorsLogLevel.INFO: Show info, warnings, and errors (default)LogLevel.DEBUG: Show debug and all aboveLogLevel.TRACE: Most verbose level for detailed tracingYou can adjust log levels for different environments:
initialize({
apiKey: 'your-api-key',
projectId: 'your-project-id',
environment: process.env.NODE_ENV,
// Set log level based on environment
logLevel: process.env.NODE_ENV === 'production'
? LogLevel.WARN
: LogLevel.DEBUG
});
MIT
FAQs
Lightweight SDK for monitoring and improving AI workflows.
The npm package @dirigible-ai/sdk receives a total of 0 weekly downloads. As such, @dirigible-ai/sdk popularity was classified as not popular.
We found that @dirigible-ai/sdk demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.

Research
/Security News
Ten malicious OpenAPI React Query Codegen versions were published to npm in the Mini Shai-Hulud attack, all with valid provenance.

Security News
Socket joins more than 100 technology, cybersecurity, and financial organizations calling for a global surge in cyber defense.

Product
Enterprise security teams can now detect malware, credential theft, suspicious network activity, and risky updates across Microsoft Edge extensions.