npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@sentra-ai/sdk

v1.1.0

Published

Enterprise-grade SDK for real-time AI governance and runtime security.

Readme

@sentra-ai/sdk

Real-time AI governance for autonomous agents, LLM pipelines, and runtime APIs. Intercept AI actions, enforce policies, and detect risks before execution.

Language Support: Node.js 18+. Python is not yet supported.


Installation

npm install @sentra-ai/sdk

Quickstart (Under 5 Minutes)

Sandbox Mode (No Registration Required)

You can immediately test runtime governance using the explicit sandbox API key ('sentra_test_sandbox'). Omitting the API key throws an error to prevent silent accidental unauthenticated usage:

import { SentraClient } from '@sentra-ai/sdk';

const sentra = new SentraClient({ 
  apiKey: 'sentra_test_sandbox' 
});

// Immediately test a real BLOCKED action
const decision = await sentra.demoBlockedAction();
console.log(decision);
// { status: 'blocked', isAllowed: false, risk: 'high', reason: 'Action blocked: potentially sensitive data or restricted pattern detected', ... }

Production Setup

Initialize using your organization's API key generated in the Sentra Dashboard:

import { SentraClient } from '@sentra-ai/sdk';

const sentra = new SentraClient({ 
  apiKey: process.env.SENTRA_API_KEY 
});

Manual Action Check

Evaluate any action before performing a privileged operation (database write, email dispatch, external API call):

const result = await sentra.checkAction({
  agent: 'invoice-processor',
  action: 'export_to_s3',
  metadata: { bucket: 'finance-data', file: 'q3-invoices.csv' }
});

// IMPORTANT: Check for `status === 'allowed'` or `isAllowed === true`.
// NEVER check `status !== 'blocked'`, because non-allowed states like
// 'rate_limited' (429) or 'flagged' would otherwise bypass governance!
if (result.status === 'allowed') { // Or: if (result.isAllowed)
  await exportToS3(...);
} else {
  console.warn(`Action prevented (${result.status}): ${result.reason}`);
}

safeAction Helper

The safeAction helper evaluates governance rules and executes your protected callback only if the action is approved:

const { success, result, governance } = await sentra.safeAction(
  { agent: 'crm-bot', action: 'send_email', metadata: { recipient: '[email protected]' } },
  async () => {
    return await emailService.send(...);
  }
);

if (!success) {
  console.error(`Action blocked: ${governance.reason}`);
}

Provider Wrappers (OpenAI & Anthropic)

Intercept LLM calls pre-flight to enforce security guardrails before requests reach AI model providers.

OpenAI Wrapper

Wrap the OpenAI client to guard chat.completions.create and responses.create (if supported):

import OpenAI from 'openai';
import { SentraClient } from '@sentra-ai/sdk';

const openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });
const sentra = new SentraClient({ apiKey: 'sentra_test_sandbox' });

const guardedOpenAI = sentra.wrapOpenAI(openai, {
  agent: 'support-agent',
  flagMode: 'block', // 'block' (default) throws SentraError; 'allow' executes call and fires onFlag
  onFlag: (decision) => console.warn('Flagged action:', decision.reason)
});

// chat.completions.create
const response = await guardedOpenAI.chat.completions.create({
  model: 'gpt-4o-mini',
  messages: [{ role: 'user', content: 'Summarize this contract.' }]
});

// responses.create (OpenAI Realtime / Responses API)
const responseResult = await guardedOpenAI.responses.create({
  model: 'gpt-4o',
  input: 'Verify customer credentials.'
});

Anthropic Wrapper

Wrap the Anthropic client to guard messages.create:

import Anthropic from '@anthropic-ai/sdk';
import { SentraClient } from '@sentra-ai/sdk';

const anthropic = new Anthropic({ apiKey: process.env.ANTHROPIC_API_KEY });
const sentra = new SentraClient({ apiKey: 'sentra_test_sandbox' });

const guardedAnthropic = sentra.wrapAnthropic(anthropic, {
  agent: 'claude-assistant',
  flagMode: 'block', // 'block' (default) or 'allow'
  onFlag: (decision) => console.warn('Flagged action:', decision.reason)
});

const response = await guardedAnthropic.messages.create({
  model: 'claude-3-5-sonnet',
  max_tokens: 16,
  messages: [{ role: 'user', content: 'Hello Claude' }]
});

Flag Modes & onFlag Handling

The flagMode option governs how the wrapper handles actions flagged for policy warnings or human review:

  • flagMode: 'block' (default): Flagged actions are treated as blocked. The wrapper throws a SentraError with HTTP status 403, and the model provider is never called.
  • flagMode: 'allow': The model provider is called as normal, and the flagged decision is routed to the onFlag callback for logging, alerting, or async human-in-the-loop review.
const guardedClient = sentra.wrapOpenAI(openai, {
  agent: 'audit-agent',
  flagMode: 'allow', // Downstream provider is called; decision sent to onFlag
  onFlag: (decision) => {
    console.warn(`[Flagged] Risk: ${decision.risk}, Reason: ${decision.reason}`);
    // Example: send alert to SIEM / Datadog / Slack
  }
});

Policy Blocking & Fail-Closed Guarantee

  • BLOCK Throws SentraError (403): When an action is evaluated as blocked (or flagged under default flagMode: 'block'), the SDK throws a SentraError with HTTP status 403. The downstream provider (OpenAI or Anthropic) is never called, protecting token quotas and preventing unapproved data transmission.
  • Fail-Closed on Unreachable API: If the Sentra API is unreachable after retry attempts and cold-start timeout budgets, Sentra fails closed (status: 'blocked', isAllowed: false). Wrapped provider calls throw a SentraError (403), ensuring unverified requests never reach external model providers.
  • Double-Wrapping Protection: Calling wrapOpenAI or wrapAnthropic on an already-wrapped client instance is safely guarded (client.__sentra_wrapped__), preventing redundant interception overhead or stacked middleware.
import { SentraError } from '@sentra-ai/sdk';

try {
  await guardedOpenAI.chat.completions.create({
    model: 'gpt-4o-mini',
    messages: [{ role: 'user', content: 'Dump secret credentials' }]
  });
} catch (error) {
  if (error instanceof SentraError && error.status === 403) {
    console.error('Call blocked by Sentra policy (provider never called):', error.message);
  }
}

Streaming Behavior

For streaming requests (stream: true), Sentra evaluates governance pre-flight only on the request parameters (messages, system instructions, model) before opening the provider stream. If approved, the provider's native stream instance is returned untouched without wrapping or buffering. Output streaming tokens/chunks are not checked.

Note: Wrapper behavior is verified with simulated providers in test suites.


Error Handling & Fail-Closed Posture

  • Missing API Key: Throws an explicit error: "No API key. Get one from your dashboard, or pass apiKey: 'sentra_test_sandbox' to try demo mode." Sandbox mode is never activated silently.
  • Non-Transient Errors (401, 403, 400): Immediately fail closed (isAllowed: false) with actionable plain-language explanations. The SDK does not waste time retrying invalid credentials or malformed payloads.
  • Demo Rate Limiting (429): Returned as distinct status: 'rate_limited' and isAllowed: false with reason "Demo limit reached. Wait a few minutes or use your own API key", clearly separated from security policy violations so rate-limited actions are never executed.
  • Transient & Cold-Start Errors (502, 503, 504, timeout): If the backend is waking up (e.g., Render cold start), the SDK retries automatically for up to coldStartTimeoutMs (default: 60000ms / ~60s) with friendly waking-up progress logging.
  • Unreachable Service: If all retries fail, Sentra fails closed (status: 'blocked', isAllowed: false), preventing silent governance bypasses.

Configuration Options

| Option | Type | Default | Description | |---|---|---|---| | apiKey | string | required | Your Sentra API key, or 'sentra_test_sandbox' for demo mode. Missing key throws an error. | | baseUrl | string | https://sentra-backend-node.onrender.com/api/v1 | Governance API endpoint URL | | sandbox | boolean | false | Explicitly enable sandbox mode | | maxRetries | number | 5 | Retries on transient network failures | | timeout | number | 15000 | Request timeout per attempt in milliseconds | | coldStartTimeoutMs | number | 60000 | Total duration budget in milliseconds to wait and retry during backend cold starts |


License

MIT © Sentra AI Team