JavaScript SDK

The Privatemode SDK for JavaScript and TypeScript (privatemode-ai) connects client applications directly to Privatemode, without running a local proxy by bundling the low-level remote attestation verification code as a Wasm blob with the JavaScript sources. It verifies the deployment through remote attestation and encrypts all inference traffic end-to-end, exposing the interface of the official OpenAI client.

The SDK is compatible with browsers as well as other JS runtimes supporting ECMAScript modules. See the Client page for the full API of the PrivatemodeAI class.

Installation

npm i privatemode-ai

The official openai package is a peer dependency, shared with your application so that both use the same OpenAI SDK types and classes. Recent package managers (npm 7+, pnpm 8+) install it automatically. Add it explicitly (npm i openai) if you import from openai directly or use an older package manager.

Quick start

import { PrivatemodeAI } from 'privatemode-ai';

const client = new PrivatemodeAI({
  apiKey: process.env.PRIVATEMODE_API_KEY!,
});

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

console.log(completion.choices[0]?.message.content);

PrivatemodeAI verifies the Privatemode deployment and establishes an encryption secret lazily before the first request.

Streaming

const stream = await client.chat.completions.create({
  model: 'gpt-oss-120b',
  messages: [{ role: 'user', content: 'Write a short poem.' }],
  stream: true,
});

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

Errors received before streaming begins use the official OpenAI error classes. Once a stream has begun, transport errors are surfaced directly because an HTTP status can no longer represent them.

Supported OpenAI resources

The following SDK resources are supported:

OpenAI SDK methodPrivatemode endpoint
client.chat.completions.create()/v1/chat/completions
client.embeddings.create()/v1/embeddings
client.audio.transcriptions.create()/v1/audio/transcriptions
client.models.list()/v1/models
client.models.retrieve()/v1/models (from the list)

Unsupported OpenAI resources fail with a non-retryable OpenAI.InternalServerError whose code is unsupported_endpoint.