Developer Guide

Documentation

Learn how to integrate Niyantra's security layer into your AI applications.

Quick Start

Get up and running with Niyantra in under 5 minutes. Follow these steps to start protecting your LLM requests.

1

Get your API Key

Sign in to your dashboard and navigate to Settings → API Keys to generate a new key.

2

Replace your API endpoint

Point your existing OpenAI/Anthropic calls to Niyantra's proxy:

endpoint.sh
bash
# Before (direct to OpenAI)
https://api.openai.com/v1/chat/completions

# After (through Niyantra)
https://api.niyantra.com/v1/chat/completions
3

Add your Niyantra API key

Include your Niyantra key in the X-API-Key header:

example.js
javascript
const response = await fetch('https://api.niyantra.com/v1/chat/completions', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'X-API-Key': 'niy_your_api_key_here',
    'Authorization': 'Bearer sk-your-openai-key'
  },
  body: JSON.stringify({
    model: 'gpt-4',
    messages: [{ role: 'user', content: 'Hello, world!' }]
  })
});
That's it!

All your requests will now be scanned for PII, logged for audit, and optimized for cost. No code changes needed beyond the endpoint swap.

Installation

Install the official Niyantra SDK for your preferred language.

npm
bash
npm install @niyantra/sdk
pip
bash
pip install niyantra

SDK Usage

app.ts
typescript
import { Niyantra } from '@niyantra/sdk';

const niyantra = new Niyantra({
  apiKey: process.env.NIYANTRA_API_KEY,
  llmProvider: 'openai',
  llmApiKey: process.env.OPENAI_API_KEY,
});

const response = await niyantra.chat.completions.create({
  model: 'gpt-4',
  messages: [{ role: 'user', content: 'Analyze this data...' }],
});

console.log(response.pii_detections);

PII Detection

Niyantra automatically detects and can redact 70+ types of personally identifiable information before it reaches your LLM.

Supported PII Types

Identity

SSNAadhaarPANPassport

Contact

EmailPhoneAddress

Financial

Credit CardBank AccountIFSC

Healthcare

MRNLab ResultsDiagnosis

Developer

API KeysTokensPasswords

Network

IP AddressMACURLs

Detection Modes

Detect Only

Scan and log PII but allow the request to proceed unchanged.

scan_mode: "detect"

Redact

Replace detected PII with placeholders before sending to LLM.

scan_mode: "redact"

Block

Reject requests containing critical PII (SSN, credit cards, etc).

scan_mode: "block"

Chat API

Niyantra's Chat API is fully compatible with OpenAI's format, making migration seamless.

request.sh
bash
curl -X POST https://api.niyantra.com/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "X-API-Key: niy_your_key" \
  -H "Authorization: Bearer sk-openai-key" \
  -d '{
    "model": "gpt-4",
    "messages": [
      {"role": "system", "content": "You are a helpful assistant."},
      {"role": "user", "content": "What is the capital of France?"}
    ],
    "scan_mode": "redact",
    "temperature": 0.7
  }'

Response Format

response.json
json
{
  "id": "chatcmpl-abc123",
  "model": "gpt-4",
  "choices": [
    {
      "message": {
        "role": "assistant",
        "content": "The capital of France is Paris."
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 25,
    "completion_tokens": 12,
    "total_tokens": 37
  },
  "niyantra": {
    "pii_detected": [],
    "scan_latency_ms": 12,
    "request_id": "req_xyz789"
  }
}

Security

Niyantra is built with security-first principles. All data is processed locally and never stored.

End-to-End Encryption

All traffic is encrypted using TLS 1.3

Zero Data Retention

Request content is never stored or logged

Token-Based Auth

Secure API keys with granular permissions

Rate Limiting

Protection against abuse and DoS attacks

Compliance

Niyantra helps you meet regulatory requirements with built-in compliance features.

HIPAA

Healthcare data protection with PHI detection and audit trails

GDPR

European data protection with PII redaction and consent management

DPDP India

Indian data protection with Aadhaar, PAN, and ABHA detection

SOC 2

Security controls with comprehensive audit logging