@blindfold/sdk
v1.3.0
Published
JavaScript/TypeScript SDK for Blindfold Gateway
Downloads
404
Maintainers
Readme
Blindfold JS SDK
The official JavaScript/TypeScript SDK for Blindfold - The Privacy API for AI.
Securely tokenize, mask, redact, and encrypt sensitive data (PII) before sending it to LLMs or third-party services.
How to use it
1. Install SDK
Javascript/ Typescript
npm install @blindfold/sdk
# or
yarn add @blindfold/sdk
# or
pnpm add @blindfold/sdkPython SDK
pip install blindfold-sdk2. Get Blindfold API key
- Sign up to Blindfold here.
- Sign up to Blindfold here.
- Get your API key here.
- Set environment variable with your API key
BLINDFOLD_API_KEY=sk-***Initialization
import { Blindfold } from '@blindfold/sdk';
const client = new Blindfold({
apiKey: 'your-api-key-here',
// Optional: Track specific end-user for audit logs
userId: 'user_123'
});Tokenize (Reversible)
Replace sensitive data with reversible tokens (e.g., <Person_1>).
const response = await client.tokenize(
"Contact John Doe at [email protected]",
{
// Optional: Use a pre-configured policy
policy: 'gdpr_eu', // or 'hipaa_us', 'basic'
// Optional: Filter specific entities
entities: ['person', 'email address'],
// Optional: Set confidence threshold
score_threshold: 0.4
}
);
console.log(response.text);
// "Contact <Person_1> at <Email Address_1>"
console.log(response.mapping);
// { "<Person_1>": "John Doe", "<Email Address_1>": "[email protected]" }Detokenize
Restore original values from tokens.
⚡ Note: Detokenization is performed client-side for better performance, security, and offline support. No API call is made.
// No await needed - runs locally!
const original = client.detokenize(
"AI response for <Person_1>",
response.mapping
);
console.log(original.text);
// "AI response for John Doe"
console.log(original.replacements_made);
// 1Mask
Partially hide sensitive data (e.g., ****-****-****-1234).
const response = await client.mask(
"Credit card: 4532-7562-9102-3456",
{
masking_char: '*',
chars_to_show: 4,
from_end: true
}
);
console.log(response.text);
// "Credit card: ***************3456"Redact
Permanently remove sensitive data.
const response = await client.redact(
"My password is secret123",
{
entities: ['person', 'email address']
}
);Hash
Replace data with deterministic hashes (useful for analytics/matching).
const response = await client.hash(
"User ID: 12345",
{
hash_type: 'sha256',
hash_prefix: 'ID_'
}
);Synthesize
Replace real data with realistic fake data.
const response = await client.synthesize(
"John lives in New York",
{
language: 'en'
}
);
console.log(response.text);
// "Michael lives in Boston" (example)Encrypt
Encrypt sensitive data using AES (reversible with key).
const response = await client.encrypt(
"Secret message",
{
encryption_key: 'your-secure-key-min-16-chars'
}
);Batch Processing
Process multiple texts in a single request (max 100 texts):
const result = await client.tokenizeBatch(
["Contact John Doe", "[email protected]", "No PII here"],
{ policy: "gdpr_eu" }
);
console.log(result.total); // 3
console.log(result.succeeded); // 3
console.log(result.failed); // 0
result.results.forEach(item => console.log(item.text));All methods have batch variants: tokenizeBatch, detectBatch, redactBatch, maskBatch, synthesizeBatch, hashBatch, encryptBatch.
Configuration
Entity Types
Common supported entities:
personemail addressphone numbercredit card numberip addressaddressdate of birthorganizationibansocial security numbermedical conditionpassport numberdriver's license number
Error Handling
The SDK throws typed errors:
import { AuthenticationError, APIError, NetworkError } from '@blindfold/sdk';
try {
await client.tokenize("...");
} catch (error) {
if (error instanceof AuthenticationError) {
// Handle invalid API key
} else if (error instanceof APIError) {
// Handle API error (e.g. validation)
} else if (error instanceof NetworkError) {
// Handle network issues
}
}