Skip to main content
POST
/
rvenc
/
chat
/
completions
Encrypted Chat Completions (RVENC)
curl --request POST \
  --url https://proxy.cci.prem.io/rvenc/chat/completions \
  --header 'Authorization: <api-key>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "encryptedInference": "<string>",
  "cipherText": "<string>",
  "nonce": "<string>"
}
'
{
  "stream": "<string>",
  "_decryptedChunk": {
    "id": "<string>",
    "object": "chat.completion.chunk",
    "created": 123,
    "model": "<string>",
    "choices": [
      {
        "index": 123,
        "delta": {
          "role": "assistant",
          "content": "<string>",
          "reasoning_content": "<string>",
          "tool_calls": [
            {}
          ]
        },
        "logprobs": null,
        "finish_reason": "stop",
        "matched_stop": null
      }
    ],
    "system_fingerprint": "<string>",
    "usage": null,
    "error": {
      "message": "<string>",
      "type": "<string>"
    }
  }
}

TypeScript SDK

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

Usage

Basic Setup

Create a client with auto-generated encryption keys:
import createRvencClient from "./index";

const client = await createRvencClient({
  apiKey: "your-api-key",
});

Pre-generate Keys

You can pre-generate encryption keys and reuse them:
import createRvencClient, { generateEncryptionKeys } from "./index";

const encryptionKeys = await generateEncryptionKeys();

const client = await createRvencClient({
  apiKey: "your-api-key",
  encryptionKeys,
  requestTimeoutMs: 60000,  // optional
  maxBufferSize: 20 * 1024 * 1024, // optional
});

Non-streaming Requests

const response = await client.chat.completions.create({
  model: "openai/gpt-oss-120b",
  messages: [{ role: "user", content: "Hello!" }],
});

Streaming Requests

const stream = await client.chat.completions.create({
  model: "openai/gpt-oss-120b",
  messages: [{ role: "user", content: "Hello!" }],
  stream: true,
});

for await (const chunk of stream) {
  process.stdout.write(chunk.choices[0]?.delta?.content || "");
}

Configuration

OptionDefaultDescription
apiKeyrequiredAuthorization token
encryptionKeysauto-generatedPre-generated { sharedSecret, cipherText }
requestTimeoutMs30000Request timeout in ms
maxBufferSize10MBMax SSE buffer size

OpenAI-Compatible API Server

Run as a standalone server with automatic DEK store management per API key:
npm start
# Server runs on http://localhost:3000
Use with any OpenAI-compatible client:
curl http://localhost:3000/v1/chat/completions \
  -H "Authorization: Bearer your-api-key" \
  -H "Content-Type: application/json" \
  -d '{"model": "openai/gpt-oss-120b", "messages": [{"role": "user", "content": "Hello!"}], "stream": false}'
Or use the SDK directly in Node.js:
import OpenAI from "openai";

const client = new OpenAI({
  apiKey: "your-api-key",
  baseURL: "http://localhost:3000/v1",
});

const stream = await client.chat.completions.create({
  model: "openai/gpt-oss-120b",
  messages: [{ role: "user", content: "Count to 10" }],
  stream: true,
});

for await (const chunk of stream) {
  process.stdout.write(chunk.choices[0]?.delta?.content || "");
}
The server caches clients in memory per API key for better 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

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:
{
"id": "cd9d05b657a041a6a14ab2fc890a7d7e",
"object": "chat.completion.chunk",
"created": 1764004858,
"model": "openai/gpt-oss-120b",
"choices": [
{
"index": 0,
"delta": {
"role": null,
"content": null,
"reasoning_content": "This ",
"tool_calls": null
},
"logprobs": null,
"finish_reason": null,
"matched_stop": null
}
],
"usage": null
}
{
"id": "cd9d05b657a041a6a14ab2fc890a7d7e",
"object": "chat.completion.chunk",
"created": 1764004858,
"model": "openai/gpt-oss-120b",
"choices": [
{
"index": 0,
"delta": {
"role": "assistant",
"content": "Hello",
"reasoning_content": null,
"tool_calls": null
},
"logprobs": null,
"finish_reason": null,
"matched_stop": null
}
],
"usage": null
}
{
"id": "cd9d05b657a041a6a14ab2fc890a7d7e",
"object": "chat.completion.chunk",
"created": 1764004858,
"model": "openai/gpt-oss-120b",
"choices": [
{
"index": 0,
"delta": [],
"logprobs": null,
"finish_reason": "stop",
"matched_stop": null
}
],
"usage": null
}