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 32-byte KEK. Encode it as 64 hexadecimal characters. Keep the KEK. Reuse it for later requests.
Create the client:

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 establishes a secure client instance for each API key.

Reasoning models

Reasoning tokens are billed and count against your token rate limits. See Usage for billing, output-token interaction, and instructions to disable or limit reasoning. The valid reasoning_effort values depend on the model family. See Models & Pricing for the values that each family accepts.

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

Chat completion request with an end-to-end encrypted payload and the key material needed to decrypt it.

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

model
string

Model identifier to use for completion

stream
boolean
default:false

If true, returns a server-sent events stream. If false, returns JSON with encryptedResponse and nonce. May also be set inside encryptedInference.

Response

RVENC chat completion response. Returns JSON when stream is false or omitted (default), or a server-sent events stream when stream is true.

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 four 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: heartbeat followed by data: {"message":"processing","timestamp":<ms>} - Keep-alive event sent every 5 seconds while waiting for the first inference token. Not encrypted; clients should ignore it.
  • event: error followed by data: <error_data> - Error event (can be encrypted or plain JSON). Emitted when inference fails or when no inference data is received within 10 minutes.
  • 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: