Skip to main content
POST
Encrypted Chat Completions (RVENC)

TypeScript SDK

The SDK is available on GitHub: premAI-io/api-sdk-ts

Basic Setup

Create a client with auto-generated encryption keys:

Pre-generate Keys

You can pre-generate encryption keys and reuse them:

Non-streaming Requests

Streaming Requests

Configuration

OpenAI-Compatible API Server

Run the SDK as a standalone server. The server automatically manages one DEK store for each API key:
Use the server with any OpenAI-compatible client:
You can also use the SDK directly in Node.js:
The server caches clients in memory for each API key. This increases performance.

API Reference

Authorizations

Authorization
string
header
required

Send your access token as header Authorization: Bearer {accessToken}

Authorization
string
header
required

Your API key that starts with sk_live or sk_test. You can create yours at go.prem.io/api-keys.

Body

application/json

Request body for rvenc (raw volatile encrypted) chat completion. Contains an encrypted payload with cryptographic materials needed for decryption.

encryptedInference
string
required

Encrypted JSON string containing all chat completion parameters. When decrypted, this string must match the structure shown in the expandable _decryptedInference property below (reference only - do not send this property).

cipherText
string
required

Cipher text for shared secret generation (ECDH key exchange)

nonce
string
required

Nonce used for encrypting the inference payload

Response

Server-sent events stream with encrypted OpenAI-compatible chat completion chunks. Each chunk in the stream is encrypted and must be decrypted using the same shared secret and nonce from the request.

Server-sent events (SSE) stream response structure. The actual response is a text stream, but this schema documents the structure for reference.

stream
string
required

Server-sent events (SSE) stream with encrypted chat completion chunks. The stream contains three types of events:

  • event: data followed by data: <encrypted_hex_string> - Encrypted chunk that must be decrypted using the same shared secret and nonce from the request. When decrypted, each chunk matches the structure shown in the _decryptedChunk property below (reference only).
  • event: error followed by data: <error_data> - Error event (can be encrypted or plain JSON)
  • event: done followed by data: [DONE] - Stream completion marker

Each encrypted data: line contains a hex-encoded string. Decrypt each chunk using XChaCha20-Poly1305 with the shared secret and nonce from your request.

_decryptedChunk
object
read-only

Reference only - This shows the structure that each encrypted chunk should contain when decrypted. Decrypt each chunk in the stream using the same shared secret and nonce from your request to get this structure.

Examples: