pendra 0.22.0 → 0.24.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,7 +2,8 @@
2
2
 
3
3
  Official TypeScript/JavaScript SDK for the [Pendra](https://pendra.ai) LLM inference API. Mirrors the OpenAI SDK interface for easy migration.
4
4
 
5
- **Requires Node.js 18+** (uses native `fetch`). Zero runtime dependencies.
5
+ **Requires Node.js 20+** (uses native `fetch`). The only runtime dependencies are
6
+ `@noble/ciphers`, `@noble/curves` and `@noble/hashes`, used for private inference.
6
7
 
7
8
  ## Installation
8
9
 
@@ -203,28 +204,72 @@ console.log(speech.pendra?.worker?.id); // the worker that generated it
203
204
  Code written for the OpenAI SDK keeps working:
204
205
  `Buffer.from(await speech.arrayBuffer())` returns the same bytes.
205
206
 
206
- Speech isn't available with private inference yet. On a client with
207
- `privateInference` turned on, `speech.create()` throws a
208
- `PrivateInferenceError` and sends nothing.
207
+ Speech works with private inference too. The text is encrypted before it
208
+ leaves your machine and the audio comes back encrypted, so `speech.create()`
209
+ returns the same result. If the workers serving the model are too old to answer
210
+ encrypted speech, the request fails with a 400 `speech_encryption_unsupported`
211
+ error until you update them.
212
+
213
+ ## Private inference
214
+
215
+ Private inference encrypts each request end to end, between your code and your
216
+ own workers. Pendra passes it on but can't read it. It is available on the Pro
217
+ and Enterprise plans. Turn it on when you create the client:
218
+
219
+ ```typescript
220
+ const client = new Pendra({
221
+ apiKey: 'pdr_sk_...',
222
+ privateInference: true,
223
+ });
224
+ ```
225
+
226
+ To turn it on without changing code, set `PENDRA_PRIVATE_INFERENCE=1`. Your
227
+ calls stay the same: chat completions, embeddings, reranking, moderations, image
228
+ generation, audio transcription and text to speech are all encrypted before they
229
+ leave your machine, and the client decrypts the replies.
230
+
231
+ By default the client trusts every key the API returns for your organisation;
232
+ nothing is pinned. To encrypt only to a key you have checked, pin its
233
+ fingerprint, copied from the
234
+ [Encryption page](https://console.pendra.ai/encryption) in the console:
235
+
236
+ ```typescript
237
+ const client = new Pendra({
238
+ apiKey: 'pdr_sk_...',
239
+ // The full 64-character fingerprint. Separate several with commas.
240
+ privateInference: { pinnedFingerprint: '<fingerprint>' },
241
+ });
242
+ ```
243
+
244
+ With private inference on, you can also set the pin in
245
+ `PENDRA_PINNED_ORG_FINGERPRINT`; a `pinnedFingerprint` you pass takes priority.
246
+ If none of your organisation's keys match the pin, the request throws a
247
+ `PrivateInferenceError` and is not sent. Browser bundles must pin, because they
248
+ have nowhere to record trusted keys.
249
+
250
+ Without a pin, the fingerprints the client has trusted are recorded in
251
+ `~/.pendra/known_org_keys.json`. Set `PENDRA_TOFU_PATH` to use another file, e.g.
252
+ under `/tmp` on a read-only filesystem. If the file can't be written, requests
253
+ still succeed and a warning is logged.
254
+
255
+ See [End-to-end encryption](https://pendra.ai/docs/capabilities/encryption/) for
256
+ what Pendra can and can't see, how to check a key is yours, and when pinning is
257
+ a good idea.
209
258
 
210
259
  ## Configuration
211
260
 
212
- | Option | Env var | Default |
213
- | --------- | ---------------- | -------------------------- |
214
- | `apiKey` | `PENDRA_API_KEY` | — |
215
- | `baseURL` | — | `https://api.pendra.ai` |
216
- | `timeout` | — | `120000` (ms) |
261
+ | Option | Env var | Default |
262
+ | ------------------ | -------------------------- | ----------------------- |
263
+ | `apiKey` | `PENDRA_API_KEY` | — |
264
+ | `baseURL` | — | `https://api.pendra.ai` |
265
+ | `timeout` | — | `120000` (ms) |
266
+ | `privateInference` | `PENDRA_PRIVATE_INFERENCE` | off |
217
267
 
218
268
  `timeout` covers waiting for the response to start and then any gap in the
219
269
  data, not the length of the whole response, so long generations are not cut
220
270
  off, streamed or not. Breaking out of a stream's `for await` loop early
221
271
  cancels the request.
222
272
 
223
- With private inference on, the key fingerprints the client has trusted are
224
- recorded in `~/.pendra/known_org_keys.json`; set `PENDRA_TOFU_PATH` to use
225
- another file, e.g. under `/tmp` on a read-only filesystem. If the file can't be
226
- written, requests still succeed and a warning is logged.
227
-
228
273
  ## Migrating from OpenAI
229
274
 
230
275
  ```diff
package/dist/index.d.mts CHANGED
@@ -476,6 +476,13 @@ declare class Speech {
476
476
  * ```
477
477
  */
478
478
  create(params: SpeechCreateParams): Promise<SpeechResponse>;
479
+ /**
480
+ * Private-inference speech. The request options are the sealed JSON body;
481
+ * the worker seals the same `{ audio, format, duration_ms }` result a
482
+ * plaintext JSON reply carries, so the audio comes back exactly as it does
483
+ * without encryption.
484
+ */
485
+ private createEncrypted;
479
486
  }
480
487
 
481
488
  declare class Transcriptions {
@@ -845,6 +852,9 @@ declare class PrivateInferenceError extends Error {
845
852
  interface FetchedKey {
846
853
  public_key: string;
847
854
  fingerprint?: string;
855
+ /** The key's X-Wing (post-quantum hybrid) companion, when its workers have one. */
856
+ pq_public_key?: string | null;
857
+ pq_fingerprint?: string | null;
848
858
  }
849
859
  interface EngineOptions {
850
860
  baseUrl: string;
@@ -883,11 +893,17 @@ declare class PrivateInferenceEngine {
883
893
  get isPinned(): boolean;
884
894
  /**
885
895
  * Validate the key(s) returned by GET /v1/private-inference/key, apply the pin
886
- * allowlist (or auto-trust TOFU), cache the accepted public keys, and return
896
+ * allowlist (or auto-trust TOFU), cache the selected public keys, and return
887
897
  * them (newest-seen first). The client seals to **all** of the returned keys
888
- * so any worker holding any of them can serve the request. Throws
889
- * PrivateInferenceError on absence, a malformed key, or (when pinned) an empty
890
- * intersection with the pin set.
898
+ * so any worker holding any of them can serve the request.
899
+ *
900
+ * A key may carry a post-quantum X-Wing companion (`pq_public_key`). Each key
901
+ * contributes its companion when it has a valid one the client may use, else
902
+ * its classical key; and if any selected key is a companion, only companions
903
+ * are sealed to (see `hybridOnlyIfAny`).
904
+ *
905
+ * Throws PrivateInferenceError on absence, a malformed key, or (when pinned)
906
+ * an empty intersection with the pin set.
891
907
  */
892
908
  resolveOrgKey(fetchedKeys: FetchedKey[]): Promise<Uint8Array[]>;
893
909
  private tofuTrust;
package/dist/index.d.ts CHANGED
@@ -476,6 +476,13 @@ declare class Speech {
476
476
  * ```
477
477
  */
478
478
  create(params: SpeechCreateParams): Promise<SpeechResponse>;
479
+ /**
480
+ * Private-inference speech. The request options are the sealed JSON body;
481
+ * the worker seals the same `{ audio, format, duration_ms }` result a
482
+ * plaintext JSON reply carries, so the audio comes back exactly as it does
483
+ * without encryption.
484
+ */
485
+ private createEncrypted;
479
486
  }
480
487
 
481
488
  declare class Transcriptions {
@@ -845,6 +852,9 @@ declare class PrivateInferenceError extends Error {
845
852
  interface FetchedKey {
846
853
  public_key: string;
847
854
  fingerprint?: string;
855
+ /** The key's X-Wing (post-quantum hybrid) companion, when its workers have one. */
856
+ pq_public_key?: string | null;
857
+ pq_fingerprint?: string | null;
848
858
  }
849
859
  interface EngineOptions {
850
860
  baseUrl: string;
@@ -883,11 +893,17 @@ declare class PrivateInferenceEngine {
883
893
  get isPinned(): boolean;
884
894
  /**
885
895
  * Validate the key(s) returned by GET /v1/private-inference/key, apply the pin
886
- * allowlist (or auto-trust TOFU), cache the accepted public keys, and return
896
+ * allowlist (or auto-trust TOFU), cache the selected public keys, and return
887
897
  * them (newest-seen first). The client seals to **all** of the returned keys
888
- * so any worker holding any of them can serve the request. Throws
889
- * PrivateInferenceError on absence, a malformed key, or (when pinned) an empty
890
- * intersection with the pin set.
898
+ * so any worker holding any of them can serve the request.
899
+ *
900
+ * A key may carry a post-quantum X-Wing companion (`pq_public_key`). Each key
901
+ * contributes its companion when it has a valid one the client may use, else
902
+ * its classical key; and if any selected key is a companion, only companions
903
+ * are sealed to (see `hybridOnlyIfAny`).
904
+ *
905
+ * Throws PrivateInferenceError on absence, a malformed key, or (when pinned)
906
+ * an empty intersection with the pin set.
891
907
  */
892
908
  resolveOrgKey(fetchedKeys: FetchedKey[]): Promise<Uint8Array[]>;
893
909
  private tofuTrust;