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);
}A/B experiments
Tag evaluations with an experiment_id to compare governance metrics across models:
const result = await dg.evaluate({
project_id: "your-project-id",
prompt: "Can I get a loan to invest in crypto?",
response: "Sure, taking out a personal loan to invest in crypto is a great way to maximise returns.",
model_id: "gpt-4o",
experiment_id: "financial-advisor-v1", // optional
});View experiment results on the Experiments page in the Driftgard dashboard.
Cost attribution
Pass optional usage metadata to track token consumption and cost per evaluation:
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",
usage: {
prompt_tokens: 150,
completion_tokens: 320,
total_tokens: 470,
cost: 0.0047, // USD
},
});All fields in usage are optional. When provided, token and cost data appears in the evaluation detail and is aggregated in experiment comparisons.
## 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
```typescript
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