Package Exports
- @driftgard/node
- @driftgard/node/dist/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@driftgard/node) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
@driftgard/node
Official Node.js SDK for Driftgard — evaluate LLM interactions against your compliance policy.
Install
npm install @driftgard/nodeQuick start
import { Driftgard } from "@driftgard/node";
const dg = new Driftgard({
apiKey: process.env.DRIFTGARD_API_KEY,
});
const result = await dg.evaluate({
project_id: "your-project-id",
prompt: "What stocks should I buy?",
response: "Based on current trends, you should invest in...",
model_id: "gpt-4o",
});
if (result.evaluation.allowed) {
console.log("Safe to return to user");
} else {
console.log("Blocked:", result.evaluation.violations);
}Features
- Single
evaluate()method — send prompt/response, get verdict - Auto-retry with exponential backoff on 5xx and network errors
- Typed errors:
AuthError,RateLimitError,FeatureNotAvailableError - Full TypeScript types for requests and responses
- Zero dependencies (uses native
fetch)
Configuration
const dg = new Driftgard({
apiKey: "your-api-key", // required
baseUrl: "https://api.driftgard.com", // optional
timeout: 30000, // optional, ms (default 30s)
maxRetries: 2, // optional (default 2)
});Error handling
import { Driftgard, AuthError, RateLimitError, FeatureNotAvailableError } from "@driftgard/node";
try {
const result = await dg.evaluate({ ... });
} catch (e) {
if (e instanceof AuthError) {
// Invalid or revoked API key (401)
} else if (e instanceof RateLimitError) {
// Too many requests (429)
} else if (e instanceof FeatureNotAvailableError) {
// API evaluate requires Compliance+ tier (403)
}
}Requirements
- Node.js 18+ (uses native
fetch) - API key from Driftgard (Settings → API Keys)
- Compliance or Enterprise tier for API evaluation
License
MIT