@complyedge/sdk
TypeScript/JavaScript SDK for ComplyEdge: runtime EU AI Act enforcement for AI agents.
Every check() call is evaluated against a deterministic Rego rule bundle, returns article-cited violations, and is written to an Article 12 audit trail.
Install
npm install @complyedge/sdk
Requires Node.js 18 or later. Get an API key at dashboard.complyedge.io.
Quick start
import { ComplyEdgeClient } from "@complyedge/sdk";
const ce = new ComplyEdgeClient({ apiKey: process.env.COMPLYEDGE_API_KEY! });
const result = await ce.check("Score users based on their social behavior");
if (!result.allowed) {
console.log("Blocked:", result.violations[0].ruleId);
console.log("Why:", result.violations[0].ruleDescription);
console.log("Audit event:", result.eventId);
}
Blocked output:
Blocked: rego-art5-1c-001
Why: Social scoring prohibited under Article 5(1)(c)
Audit event: evt_01J...
Configuration
const ce = new ComplyEdgeClient({
apiKey: process.env.COMPLYEDGE_API_KEY!,
jurisdiction: "EU",
agentId: "support-bot",
timeout: 30_000,
baseUrl: "https://api.complyedge.io",
});
check(text, context?)
Calls POST /v1/check, the deterministic OPA hot path. Returns:
allowed | boolean | false means block before the model sees it |
status | "safe" | "violation" | Convenience mirror of allowed |
violations | ComplianceViolation[] | Rule ID, description, severity, reason, confidence |
eventId | string | Identifier of the audit record for this decision |
auditLogged | boolean | Whether the decision reached the Article 12 trail |
enginePath | string | opa, opa_fallback_llm, or opa_error |
latencyMs / opaLatencyMs | number | Server-reported latency |
bundleVersion | string | Rule bundle the decision was evaluated against |
evaluatedRules | string[] | Rule IDs considered |
Per-call context overrides the client defaults:
await ce.check(userPrompt, {
direction: "prompt",
jurisdiction: "EU",
agentId: "hr-screening",
userRole: "recruiter",
});
OpenAI middleware
Wrap an OpenAI client so user messages are checked before they reach the model:
import OpenAI from "openai";
import { ComplyEdgeClient, withCompliance, ComplianceError } from "@complyedge/sdk";
const openai = withCompliance(
new OpenAI(),
new ComplyEdgeClient({ apiKey: process.env.COMPLYEDGE_API_KEY! }),
{ jurisdiction: "EU", blockOnViolation: true }
);
try {
await openai.chat.completions.create({
model: "gpt-4o",
messages: [{ role: "user", content: prompt }],
});
} catch (err) {
if (err instanceof ComplianceError) {
}
}
openai is an optional peer dependency. Install it only if you use the middleware.
Pre-deployment assessment
const assessment = await ce.assessPreDeployment({
systemPrompt: "You screen CVs and rank candidates.",
jurisdiction: "EU",
});
console.log(assessment.riskTier);
console.log(assessment.euAiActCategory);
detectSensitivity(text, context?)
Legacy sensitivity detection (POST /v1/sensitivity/detect), kept for existing
callers. It runs the TrustLint and LLM pipeline, not OPA, and does not write
the Article 12 audit trail. Use check() for runtime enforcement.
Errors
Network and HTTP failures surface as AxiosError. The middleware throws
ComplianceError when a check blocks a request.
Links
License
Apache-2.0. See LICENSE.