SDKs

Official client libraries for PRISM. All SDK calls go through your account middleware.

Account-Bound & Multi-Tenant

Every SDK call is authenticated with your API key and routes through PRISM's middleware:

  • Authentication: JWT validation tied to your account
  • Multi-tenancy: Data isolated by organization via Row-Level Security
  • Validation: All requests pass through T0-T4 validation tiers
  • Billing: Usage tracked and billed to your account

Installation

npm install @prism/sdk

# or
yarn add @prism/sdk

# or
pnpm add @prism/sdk

Quick Start

import PRISM from '@prism/sdk';

// Initialize with your API key (tied to your account)
const prism = new PRISM(process.env.PRISM_API_KEY);

// All requests go through your account middleware
const result = await prism.validate({
  query: "What is quantum computing?",
  provider: 'openai',
  model: 'gpt-4',
  enable_t0: true,  // Enable NLP preprocessing
});

console.log(result.response);     // Validated response
console.log(result.tier);          // Which tier processed it (neuron/slm/llm/elm)
console.log(result.confidence);    // Confidence score (0-1)
console.log(result.cost);          // Cost in USD
console.log(result.savings);       // Savings vs raw API call

API Key Management

Manage your API keys programmatically. Keys are scoped to your account/organization.

// List all API keys for your account
const keys = await prism.listAPIKeys();
console.log(keys);
// [{ id: 1, name: 'Production', key_prefix: 'prism_sk', tier: 'pro', ... }]

// Create a new API key
const newKey = await prism.createAPIKey('Development');
console.log(newKey.api_key.key);  // prism_sk_abc123... (only shown once!)

// Revoke an API key
await prism.revokeAPIKey(keyId);

Multi-Tenant Support

For organizations with multiple users, data is automatically isolated:

// Your API key encodes your organization
// The middleware extracts from your JWT:
// - user_id: Which user is making the request
// - organization_id: Which org they belong to
// - tier: Their subscription tier

// When you query:
const chats = await prism.getChats();

// The API middleware:
// 1. Validates your token
// 2. Sets PostgreSQL session: SET app.organization_id = 'org_123'
// 3. Row-Level Security enforces: WHERE organization_id = current_setting('app.organization_id')
// 4. You only see your organization's data

// Team members in the same org see the same data
// Other organizations cannot access your data

Organization Isolation

  • • Chat history isolated per org
  • • API keys scoped to org
  • • Usage/billing per org
  • • Custom settings per org

User Roles

  • • Owner: Full access, billing
  • • Admin: Manage users, keys
  • • Member: Use API, view data
  • • Viewer: Read-only access

Error Handling

import PRISM, { PRISMError, AuthenticationError, RateLimitError } from '@prism/sdk';

try {
  const result = await prism.validate({ query: "..." });
} catch (error) {
  if (error instanceof AuthenticationError) {
    console.error('Invalid API key - check your key or renew it');
  } else if (error instanceof RateLimitError) {
    console.error(`Rate limited. Retry after ${error.retryAfter} seconds`);
  } else if (error instanceof PRISMError) {
    console.error('API error:', error.message);
  }
}

Ironclad SDK (Post-Quantum Encryption)

For applications requiring post-quantum cryptographic protection:

npm install @velariq/ironclad-shield
import { IroncladClient } from '@velariq/ironclad-shield';

const ironclad = new IroncladClient({
  apiKey: process.env.IRONCLAD_API_KEY,
});

// Encrypt with 5-layer PQC stack (ML-KEM-1024 + X25519 + AES-256-GCM)
const encrypted = await ironclad.encrypt('sensitive data');

// Decrypt
const decrypted = await ironclad.decrypt(encrypted.encrypted, {
  keyId: encrypted.metadata.keyId,
});

console.log(decrypted.data); // 'sensitive data'