Skip to main content
The @centure/node-sdk package provides type-safe TypeScript support for detecting prompt injection attacks in your Node.js applications.

Installation

1

Install the package

Install the SDK using your preferred package manager:
npm install @centure/node-sdk
2

Get your API key

Obtain your API key from the Centure dashboard. Store it securely in your environment variables.
Never commit API keys to version control. Use environment variables or a secrets manager.
3

Initialize the client

Create a client instance with your API key:
import { CentureClient } from "@centure/node-sdk";

// Using environment variable
const client = new CentureClient();

// Or provide API key directly
const client = new CentureClient({
  apiKey: "your-api-key",
  baseUrl: "https://api.centure.ai", // Optional
});
Set the CENTURE_API_KEY environment variable to avoid passing the API key in code.

Scan Text Content

Detect prompt injection attempts in text messages, user inputs, or prompts:
const result = await client.scanText("Your text content here");

console.log("Is safe:", result.is_safe);
console.log("Detected categories:", result.categories);
console.log("Request ID:", result.request_id);

Response Example

{
  "is_safe": false,
  "categories": [
    {
      "code": "context_injection",
      "confidence": "high"
    }
  ],
  "request_id": "req_abc123",
  "api_key_id": "key_xyz789",
  "request_units": 1,
  "service_tier": "standard"
}

Scan Images

Detect text-based prompt injection in images using base64 encoding or Buffer objects:
const base64Image = "iVBORw0KGgoAAAANSUhEUgAA...";
const result = await client.scanImage(base64Image);

console.log("Is safe:", result.is_safe);
console.log("Detected threats:", result.categories);
The SDK automatically converts Buffer objects to base64 format for transmission.

Error Handling

Handle specific error scenarios with typed error classes:
import {
  CentureClient,
  BadRequestError,
  UnauthorizedError,
  PayloadTooLargeError,
  MissingApiKeyError,
} from "@centure/node-sdk";

try {
  const result = await client.scanText("content");
} catch (error) {
  if (error instanceof UnauthorizedError) {
    console.error("Invalid API key");
  } else if (error instanceof BadRequestError) {
    console.error("Invalid request:", error.message);
  } else if (error instanceof PayloadTooLargeError) {
    console.error("Image exceeds size limit");
  } else if (error instanceof MissingApiKeyError) {
    console.error("API key not provided");
  }
}

Next Steps

API Reference

Explore response types, threat categories, and advanced configuration options

MCP Integration

Secure Model Context Protocol applications with automatic scanning

npm Package

View package details and version history on npm

GitHub Repository

View source code, report issues, and contribute