Client Initialization

The KeyKing Node.js SDK operates natively in Edge and serverless environments. It uses Zero-Trust Lazy Decryption to ensure your keys are never stored in plaintext memory until the exact moment a request is fired.

Zero-Trust Lazy Decryption

The SDK derives a 256-bit encryption key from your password using PBKDF2 (100,000 iterations, SHA-256) combined with a 32-byte salt from your vault.kk payload. Decryption is performed purely in memory using the native Web Crypto API (globalThis.crypto.subtle), meaning zero heavy runtime dependencies.

TypeScript
import { KeyKing } from "keyking-sdk";

// Decrypts lazily on the first API call
const keyking = new KeyKing({
vault: process.env.KEYKING_VAULT,
password: process.env.KEYKING_PASSWORD,
routingRules: [{ provider: "Anthropic", model: "claude-3-5-sonnet-20241022" }
]
});

Exposed Methods

  • keyking.chat.completions.create(request)

    Drop-in replacement for OpenAI. Supports standard params and Server-Sent Events (SSE) streaming for all providers.

  • keyking.getProviders()

    Returns a Promise of all available providers present in the loaded vault.

  • keyking.hasProvider(provider)

    Returns a boolean indicating if a specific provider's key is available.