fastpii-connect
v0.3.1
Published
Client SDK for the FastPII AI Data Security Platform — detect and protect sensitive data before it reaches AI systems
Maintainers
Readme
FastPII Connect — TypeScript SDK
Client SDK for the FastPII AI Data Security Platform.
FastPII detects and protects sensitive information before it reaches AI systems, enabling organisations to use AI securely while meeting privacy and governance requirements.
Installation
npm install fastpii-connect
# or
pnpm add fastpii-connect
# or
yarn add fastpii-connectRequires Node.js 18+.
Quick Start
import { FastPIIClient } from "fastpii-connect";
const client = new FastPIIClient({ apiKey: "fpk_your_api_key" });
// Detect PII
const result = await client.detect("My rodné číslo is 900101/1234");
for (const entity of result.entities) {
console.log(`Found ${entity.type}: ${entity.original}`);
}
// Protect PII
const protected = await client.protect("My rodné číslo is 900101/1234", { mode: "replace" });
console.log(protected.protected_text);
// Validate an identifier
const valid = await client.validate("900101/1234", { entity_type: "rodne_cislo" });
console.log(`Valid: ${valid.valid}`);
// List available detectors
const detectors = await client.listDetectors({ country: "CZ" });
for (const d of detectors.detectors) {
console.log(`${d.name}: ${d.description}`);
}Async/Await
All methods return Promises. Use async/await or .then():
const client = new FastPIIClient({ apiKey: "fpk_your_api_key" });
// async/await
const result = await client.detect("Hello world");
// Promise chain
client.detect("Hello world").then((result) => {
console.log(result.entities);
});Session Management
import { Session, FastPIIClient } from "fastpii-connect";
const client = new FastPIIClient({ apiKey: "fpk_your_api_key" });
const session = new Session(client);
const r1 = await session.detect("My rodné číslo is 900101/1234");
console.log(session.countries); // ["CZE"]
const r2 = await session.detect("My PESEL is 90010112345");
console.log(session.countries); // ["CZE", "POL"]
console.log(session.messageCount); // 2Gateway (AI Chat Completions)
// Non-streaming
const response = await client.gateway.chat.completions({
model: "gpt-4o",
messages: [{ role: "user", content: "Hello!" }],
});
console.log(response.choices[0].message.content);
// Streaming
for await (const event of client.gateway.chat.stream({
model: "gpt-4o",
messages: [{ role: "user", content: "Hello!" }],
})) {
if ("content" in event) {
process.stdout.write(event.content);
}
}Error Handling
import {
FastPIIError,
AuthenticationError,
RateLimitError,
QuotaExceededError,
ValidationError,
} from "fastpii-connect";
try {
const result = await client.detect("text");
} catch (error) {
if (error instanceof AuthenticationError) {
console.log("Invalid API key");
} else if (error instanceof RateLimitError) {
console.log(`Rate limited. Retry after ${error.retryAfter} seconds`);
} else if (error instanceof QuotaExceededError) {
console.log("Monthly quota exceeded");
} else if (error instanceof FastPIIError) {
console.log(`FastPII error: ${error.message}`);
}
}Configuration
const client = new FastPIIClient({
apiKey: "fpk_your_api_key", // or set FASTPII_API_KEY env var
baseUrl: "https://api.fastpii.com", // default
timeout: 30, // request timeout in seconds
maxRetries: 2, // retries for 408, 429, 502, 503, 504
});Protection Modes
| Mode | Description | Example |
|---|---|---|
| replace | Replace with [REDACTED] | My email is [REDACTED] |
| mask | Replace with * characters | My email is ************ |
| hash | Replace with SHA-256 hash | My email is a5dc0ea20c... |
| tokenize | Replace with reversible token | My email is a5dc0ea20c... |
Environment Variables
| Variable | Description |
|---|---|
| FASTPII_API_KEY | API key (used if apiKey not provided) |
| FASTPII_BASE_URL | Base URL override (used if baseUrl not provided) |
License
MIT — see LICENSE file.
