FastPII Docs
FastPII Connect

FastPII Connect Overview

Client SDKs for the FastPII AI Data Security Platform — detect and protect sensitive data before it reaches AI systems.

FastPII Connect Overview

FastPII Connect is the client SDK for the FastPII AI Data Security Platform. It provides typed access to detection, protection, validation, health, and the OpenAI-compatible Gateway — available in both Python and TypeScript.

FastPII detects and protects sensitive information before it reaches AI systems, enabling organisations to use AI securely while meeting privacy and governance requirements.

SDKs available

LanguagePackageInstall
Pythonfastpii-connectpip install fastpii-connect
TypeScriptfastpii-connectnpm install fastpii-connect

When to use Connect vs the open-source SDK

FeatureOpen-source SDK (fastpii)Connect SDK (fastpii-connect)
Installpip install fastpiipip install fastpii-connect / npm install fastpii-connect
LicenseMITMIT
RunsLocally, in-processCalls hosted API
API KeyNot requiredRequired (fpk_...)
Country detectionManual registrationAuto-detects via Intelligence Engine
Session managementNot availableAvailable
Gateway (LLM proxy)Not availableAvailable
CLIfastpii detectfastpii-connect scan
NetworkNonehttps://api.fastpii.com + https://gateway.fastpii.com

Use the open-source SDK when you need local, offline detection with full control. Use Connect when you want managed infrastructure, Intelligence Engine auto-detection, session tracking, or the AI Gateway.

Quick start — Python

pip install fastpii-connect
from fastpii_connect import FastPIIClient

client = FastPIIClient(api_key="fpk_your_api_key")

# Detect sensitive data
result = client.detect("My rodné číslo is 900101/1234")
for entity in result.entities:
    print(f"Found {entity.type}: {entity.original}")

# Protect sensitive data
result = client.protect("My rodné číslo is 900101/1234", mode="replace")
print(result.protected_text)

# Validate an identifier
result = client.validate("900101/1234", entity_type="rodne_cislo")
print(f"Valid: {result.valid}")

# List available detectors
detectors = client.list_detectors(country="CZ")
for d in detectors.detectors:
    print(f"{d.name}: {d.description}")

# Check API health
health = client.health()
print(f"Status: {health.status}, Version: {health.version}")

Quick start — TypeScript

npm install fastpii-connect
import { FastPIIClient } from "fastpii-connect";

const client = new FastPIIClient({ apiKey: "fpk_your_api_key" });

// Detect sensitive data
const detectResult = await client.detect("My rodné číslo is 900101/1234");
for (const entity of detectResult.entities) {
  console.log(`Found ${entity.type}: ${entity.original}`);
}

// Protect sensitive data
const protectResult = await client.protect("My rodné číslo is 900101/1234", { mode: "replace" });
console.log(protectResult.protected_text);

// Validate an identifier
const validateResult = await client.validate("900101/1234", { entity_type: "rodne_cislo" });
console.log(`Valid: ${validateResult.valid}`);

Authentication

Connect authenticates using an API key sent via the X-API-Key header on every request:

# Python — explicit
client = FastPIIClient(api_key="fpk_your_api_key")

# Python — environment variable
export FASTPII_API_KEY="fpk_your_api_key"
client = FastPIIClient()
// TypeScript — explicit
const client = new FastPIIClient({ apiKey: "fpk_your_api_key" });

// TypeScript — environment variable
// Set FASTPII_API_KEY in your environment
const client = new FastPIIClient();

Alternatively, use the CLI to save your key:

fastpii-connect auth login --api-key fpk_your_api_key

The key is stored at ~/.fastpii/config.json and used automatically by the CLI.

Configuration

Python

client = FastPIIClient(
    api_key="fpk_your_api_key",
    base_url="https://api.fastpii.com",  # default
    timeout=30,       # request timeout in seconds
    max_retries=2,    # retries for transient errors (408, 429, 502, 503, 504)
)

TypeScript

const client = new FastPIIClient({
  apiKey: "fpk_your_api_key",
  baseUrl: "https://api.fastpii.com",  // default
  timeout: 30_000,    // request timeout in milliseconds
  maxRetries: 2,      // retries for transient errors
});

Context manager

Python

Use Connect as a context manager to ensure the HTTP client is properly closed:

with FastPIIClient(api_key="fpk_your_api_key") as client:
    result = client.detect("Hello world")
    print(result.entities)

Async Python

from fastpii_connect import AsyncFastPII

async with AsyncFastPII(api_key="fpk_your_api_key") as client:
    result = await client.detect("Hello world")
    print(result.entities)

Session management

Sessions track detected countries across multiple calls, building context over time:

client = FastPIIClient(api_key="fpk_your_api_key")
session = client.create_session()

result1 = session.detect("My rodné číslo is 900101/1234")
print(session.countries)       # ["CZ"]

result2 = session.detect("My PESEL is 90010112345")
print(session.countries)       # ["CZ", "PL"]
print(session.message_count)  # 2

AI Gateway

Connect provides a Gateway client that wraps the OpenAI-compatible chat completions API with automatic sensitive data inspection:

Python

from fastpii_connect import FastPIIClient

client = FastPIIClient(api_key="fpk_your_api_key")

# Non-streaming
response = client.gateway.chat.completions(
    model="gpt-4o",
    messages=[{"role": "user", "content": "Hello!"}],
)
print(response["choices"][0]["message"]["content"])

# Streaming
for event in client.gateway.chat.stream(
    model="gpt-4o",
    messages=[{"role": "user", "content": "Hello!"}],
):
    if hasattr(event, "content"):
        print(event.content, end="")

TypeScript

const client = new FastPIIClient({ apiKey: "fpk_your_api_key" });

// 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);
  }
}

See the Gateway reference for full Gateway documentation.

Rate limits and error handling

Connect handles transient errors (408, 429, 502, 503, 504) with automatic retries. For rate limits and quota errors, catch specific exceptions:

from fastpii_connect.errors import (
    AuthenticationError,
    RateLimitError,
    QuotaExceededError,
    ValidationError,
)

try:
    result = client.detect("text")
except AuthenticationError:
    print("Invalid API key")
except RateLimitError as e:
    print(f"Rate limited. Retry after {e.retry_after} seconds")
except QuotaExceededError:
    print("Monthly quota exceeded")
except ValidationError as e:
    print(f"Request error: {e.message}")

See the error handling reference for the full error hierarchy including Gateway-specific errors.

Next steps

On this page