pendra 0.2.0 → 0.6.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
@@ -20,18 +20,28 @@ const client = new Pendra({
20
20
  });
21
21
 
22
22
  const response = await client.chat.completions.create({
23
- model: 'llama3.2',
23
+ model: 'qwen3.5:0.8b',
24
24
  messages: [{ role: 'user', content: 'Hello!' }],
25
25
  });
26
26
 
27
27
  console.log(response.choices[0].message.content);
28
28
  ```
29
29
 
30
+ ### Your first request — full sequence
31
+
32
+ Pendra serves inference from workers you (or your org) run, so a brand-new account needs three things in place before that `chat.completions.create()` call returns a 200:
33
+
34
+ 1. **A worker connected**. Install Pendra on any host with a GPU or CPU and run `pendra setup`. The wizard walks through pasting a worker key from [console.pendra.ai/workers](https://console.pendra.ai/workers) and connecting to the API.
35
+ 2. **A model on disk**. The worker only serves models it has locally. From the worker host run, e.g., `pendra models install qwen3.5:0.8b`. Browse [console.pendra.ai/models](https://console.pendra.ai/models) for the full catalogue.
36
+ 3. **An API key**. Create one at [console.pendra.ai/api-keys](https://console.pendra.ai/api-keys) and pass it as `apiKey` above.
37
+
38
+ If your call returns `404 Model 'X' is in the catalogue but no connected worker has it installed yet`, skip back to step 2 — that's the API telling you the model is known but hasn't been pulled onto a worker yet.
39
+
30
40
  ## Streaming
31
41
 
32
42
  ```typescript
33
43
  const stream = await client.chat.completions.create({
34
- model: 'llama3.2',
44
+ model: 'qwen3.5:0.8b',
35
45
  messages: [{ role: 'user', content: 'Write a poem' }],
36
46
  stream: true,
37
47
  });
@@ -87,7 +97,7 @@ Image generation is non-streaming — the response is returned as a single JSON
87
97
 
88
98
  // Everything else stays the same
89
99
  const res = await client.chat.completions.create({
90
- model: 'llama3.2',
100
+ model: 'qwen3.5:0.8b',
91
101
  messages: [{ role: 'user', content: 'Hi' }],
92
102
  });
93
103
  ```
package/dist/index.d.mts CHANGED
@@ -1,3 +1,49 @@
1
+ interface TranscriptionSegment {
2
+ id: number;
3
+ start: number;
4
+ end: number;
5
+ text: string;
6
+ }
7
+ interface TranscriptionResponse {
8
+ text: string;
9
+ language?: string;
10
+ duration?: number;
11
+ segments?: TranscriptionSegment[];
12
+ }
13
+ /** Source for the audio bytes. A `File` works in browsers and Node ≥20
14
+ * (where `Blob`/`FormData`/`File` are stable globals — Node 18 only ships
15
+ * these behind `--experimental-fetch` until 18.17, so this package
16
+ * targets Node 20+ for predictable behaviour). For buffers, Node streams,
17
+ * or plain `Blob`s without a filename, prefer the `{ filename, content }`
18
+ * form so the multipart upload carries a filename + extension — the API
19
+ * uses these for format detection and may reject uploads that lack one. */
20
+ type AudioFileInput = Blob | {
21
+ filename: string;
22
+ content: Blob | ArrayBuffer | Uint8Array;
23
+ };
24
+ interface TranscriptionCreateParams {
25
+ file: AudioFileInput;
26
+ model: string;
27
+ language?: string;
28
+ prompt?: string;
29
+ response_format?: "json" | "text" | "srt" | "vtt" | "verbose_json";
30
+ temperature?: number;
31
+ timestamp_granularities?: ("word" | "segment")[];
32
+ /** Pin to a specific worker (sent as the `X-Pendra-Worker-Id` header). */
33
+ worker_id?: string | null;
34
+ }
35
+
36
+ declare class Transcriptions {
37
+ private client;
38
+ constructor(client: Pendra);
39
+ create(params: TranscriptionCreateParams): Promise<TranscriptionResponse>;
40
+ }
41
+
42
+ declare class Audio {
43
+ transcriptions: Transcriptions;
44
+ constructor(client: Pendra);
45
+ }
46
+
1
47
  interface Usage {
2
48
  prompt_tokens: number;
3
49
  completion_tokens: number;
@@ -47,6 +93,12 @@ interface ChatCompletionCreateParams {
47
93
  top_p?: number | null;
48
94
  stop?: string | string[] | null;
49
95
  stream?: boolean;
96
+ /**
97
+ * Optionally pin the request to a specific worker that serves this model.
98
+ * Sent as the `X-Pendra-Worker-Id` header; when omitted, the least-busy
99
+ * worker is chosen automatically.
100
+ */
101
+ worker_id?: string | null;
50
102
  }
51
103
 
52
104
  declare class Stream implements AsyncIterable<ChatCompletionChunk> {
@@ -70,6 +122,7 @@ declare class Completions {
70
122
  stream?: false;
71
123
  }): Promise<ChatCompletion>;
72
124
  create(params: ChatCompletionCreateParams): Promise<ChatCompletion | Stream>;
125
+ private createEncrypted;
73
126
  }
74
127
 
75
128
  declare class Chat {
@@ -77,6 +130,51 @@ declare class Chat {
77
130
  constructor(client: Pendra);
78
131
  }
79
132
 
133
+ interface EmbeddingCreateParams {
134
+ model: string;
135
+ input: string | string[];
136
+ encoding_format?: "float" | "base64";
137
+ dimensions?: number;
138
+ user?: string;
139
+ /** Pin to a specific worker (sent as the `X-Pendra-Worker-Id` header). */
140
+ worker_id?: string | null;
141
+ }
142
+ interface Embedding {
143
+ object: "embedding";
144
+ /** Array of floats, or a base64-encoded string if encoding_format="base64". */
145
+ embedding: number[] | string;
146
+ index: number;
147
+ }
148
+ interface EmbeddingUsage {
149
+ prompt_tokens: number;
150
+ total_tokens: number;
151
+ }
152
+ interface CreateEmbeddingResponse {
153
+ object: "list";
154
+ data: Embedding[];
155
+ model: string;
156
+ usage: EmbeddingUsage;
157
+ }
158
+
159
+ declare class Embeddings {
160
+ private client;
161
+ constructor(client: Pendra);
162
+ /**
163
+ * Create embeddings for the given input.
164
+ *
165
+ * @example
166
+ * ```ts
167
+ * const result = await client.embeddings.create({
168
+ * model: "nomic-embed-text:latest",
169
+ * input: "Hello world",
170
+ * });
171
+ * console.log(result.data[0].embedding);
172
+ * ```
173
+ */
174
+ create(params: EmbeddingCreateParams): Promise<CreateEmbeddingResponse>;
175
+ private createEncrypted;
176
+ }
177
+
80
178
  interface ImageGenerationCreateParams {
81
179
  model: string;
82
180
  prompt: string;
@@ -86,6 +184,8 @@ interface ImageGenerationCreateParams {
86
184
  num_inference_steps?: number;
87
185
  seed?: number;
88
186
  negative_prompt?: string;
187
+ /** Pin to a specific worker (sent as the `X-Pendra-Worker-Id` header). */
188
+ worker_id?: string | null;
89
189
  }
90
190
  interface ImageData {
91
191
  b64_json?: string;
@@ -120,10 +220,160 @@ declare class Models {
120
220
  list(): Promise<Model[]>;
121
221
  }
122
222
 
223
+ interface RerankCreateParams {
224
+ model: string;
225
+ query: string;
226
+ documents: string[];
227
+ /** Return only the top_n most relevant documents (all when omitted). Must be >= 1. */
228
+ top_n?: number;
229
+ /** When true, each result echoes the original document text. */
230
+ return_documents?: boolean;
231
+ /** Pin to a specific worker (sent as the `X-Pendra-Worker-Id` header). */
232
+ worker_id?: string | null;
233
+ }
234
+ interface RerankResultDocument {
235
+ text: string;
236
+ }
237
+ interface RerankResult {
238
+ index: number;
239
+ relevance_score: number;
240
+ /** Present only when the request set return_documents=true. */
241
+ document?: RerankResultDocument;
242
+ }
243
+ /** Cohere-compatible rerank response: results sorted by relevance (desc). */
244
+ interface RerankResponse {
245
+ id: string;
246
+ results: RerankResult[];
247
+ meta: Record<string, unknown>;
248
+ }
249
+
250
+ declare class Rerank {
251
+ private client;
252
+ constructor(client: Pendra);
253
+ /**
254
+ * Rerank `documents` by relevance to `query` (Cohere-compatible).
255
+ *
256
+ * @example
257
+ * ```ts
258
+ * const result = await client.rerank.create({
259
+ * model: "bge-reranker-v2-m3",
260
+ * query: "What is the capital of France?",
261
+ * documents: ["Paris is the capital of France.", "Berlin is in Germany."],
262
+ * top_n: 1,
263
+ * });
264
+ * console.log(result.results[0].index, result.results[0].relevance_score);
265
+ * ```
266
+ */
267
+ create(params: RerankCreateParams): Promise<RerankResponse>;
268
+ private createEncrypted;
269
+ }
270
+
271
+ interface ResponseInner {
272
+ v?: number;
273
+ enc?: string;
274
+ seq: number;
275
+ ciphertext: string;
276
+ }
277
+ /**
278
+ * Decrypts a worker's sealed response. Derives the response DEK once from the
279
+ * first frame's `enc` (HPKE Export to the client's ephemeral key) and enforces a
280
+ * monotonic `seq` across streaming chunks.
281
+ */
282
+ declare class ResponseDecryptor {
283
+ private respPriv;
284
+ private dek;
285
+ private nextSeq;
286
+ constructor(responsePrivateKey: Uint8Array);
287
+ private ensureDek;
288
+ /** Decrypt a non-streaming result envelope `{v, enc, seq, ciphertext}`. */
289
+ openResult(inner: ResponseInner): Uint8Array;
290
+ /** Decrypt one streaming chunk envelope, enforcing monotonic `seq`. */
291
+ openChunk(inner: ResponseInner): Uint8Array;
292
+ }
293
+ interface AffinityMessage {
294
+ role?: string;
295
+ content?: unknown;
296
+ }
297
+
298
+ /**
299
+ * Private Inference engine: resolves and caches the org workload public key
300
+ * (TOFU by default, or an explicit pinned fingerprint), then seals requests to
301
+ * it. Byte-for-byte port of the Python SDK's `_private_inference_engine`.
302
+ *
303
+ * Deliberately HTTP-agnostic — the calling resource performs the key-fetch GET
304
+ * and hands the returned keys to `resolveOrgKey`, so all the trust logic lives
305
+ * here in one place and is unit-testable without a network. TOFU file I/O uses a
306
+ * dynamic `import("node:fs")` so browser bundles (which require a pinned
307
+ * fingerprint) never need it.
308
+ */
309
+
310
+ declare class PrivateInferenceError extends Error {
311
+ constructor(message: string);
312
+ }
313
+ interface FetchedKey {
314
+ public_key: string;
315
+ fingerprint?: string;
316
+ }
317
+ interface EngineOptions {
318
+ baseUrl: string;
319
+ apiKey: string;
320
+ pinnedFingerprint?: string | null;
321
+ affinitySalt?: Uint8Array | null;
322
+ tofuPath?: string | null;
323
+ }
324
+ declare class PrivateInferenceEngine {
325
+ private baseUrl;
326
+ private apiKey;
327
+ private pinnedFingerprint;
328
+ private affinitySalt;
329
+ private tofuPath;
330
+ private orgPub;
331
+ constructor(opts: EngineOptions);
332
+ cachedOrgPublicKey(): Uint8Array | null;
333
+ private tofuIdentity;
334
+ /**
335
+ * Validate the key(s) returned by GET /v1/private-inference/key against the
336
+ * pin or TOFU record, cache the accepted public key, and return it. Throws
337
+ * PrivateInferenceError on absence or a fingerprint mismatch.
338
+ */
339
+ resolveOrgKey(fetchedKeys: FetchedKey[]): Promise<Uint8Array>;
340
+ private checkTofu;
341
+ private loadTofu;
342
+ private saveTofu;
343
+ /**
344
+ * Seal a request body to the resolved org key. Returns `{ topLevel, decryptor }`.
345
+ * `messages` (chat only) drives the affinity token; pass undefined for non-chat.
346
+ */
347
+ seal(args: {
348
+ model: string;
349
+ stream: boolean;
350
+ taskType: string;
351
+ body: Uint8Array;
352
+ messages?: AffinityMessage[] | null;
353
+ }): {
354
+ topLevel: Record<string, unknown>;
355
+ decryptor: ResponseDecryptor;
356
+ };
357
+ get keyFetchUrl(): string;
358
+ }
359
+
123
360
  interface PendraOptions {
124
361
  apiKey?: string;
125
362
  baseURL?: string;
126
363
  timeout?: number;
364
+ /**
365
+ * Enable end-to-end encrypted (private) inference. When `true`, chat and
366
+ * embeddings requests are sealed to your org's workload key (TOFU-pinned on
367
+ * first use) and the responses are decrypted client-side — Pendra relays only
368
+ * ciphertext. Pass `{ pinnedFingerprint }` to hard-pin the org key fingerprint
369
+ * (required in browser bundles, which cannot use the TOFU key store).
370
+ *
371
+ * Defaults to the `PENDRA_PRIVATE_INFERENCE` environment variable
372
+ * (`1`/`true`/`yes`/`on` enables it).
373
+ */
374
+ privateInference?: boolean | {
375
+ pinnedFingerprint?: string;
376
+ };
127
377
  }
128
378
  declare class Pendra {
129
379
  readonly apiKey: string;
@@ -131,13 +381,29 @@ declare class Pendra {
131
381
  readonly timeout: number;
132
382
  chat: Chat;
133
383
  images: Images;
384
+ embeddings: Embeddings;
134
385
  models: Models;
386
+ audio: Audio;
387
+ rerank: Rerank;
388
+ /** @internal Whether end-to-end encrypted inference is enabled for this client. */
389
+ readonly privateInferenceEnabled: boolean;
390
+ private _piEngine;
391
+ private _piKeyFetch;
135
392
  constructor(options?: PendraOptions);
393
+ /**
394
+ * @internal
395
+ * Return the private-inference engine with its org key resolved. Fetches
396
+ * `GET {baseUrl}/v1/private-inference/key` exactly once (subsequent calls reuse
397
+ * the cached key). Throws if private inference is not enabled.
398
+ */
399
+ _privateEngine(): Promise<PrivateInferenceEngine>;
400
+ private _fetchAndResolveOrgKey;
136
401
  /** @internal */
137
402
  _fetch(path: string, options: {
138
403
  method: string;
139
404
  body?: Record<string, unknown>;
140
405
  stream?: boolean;
406
+ headers?: Record<string, string>;
141
407
  }): Promise<{
142
408
  response: Response;
143
409
  controller: AbortController;
@@ -162,4 +428,4 @@ declare class RateLimitError extends APIStatusError {
162
428
  constructor(message?: string);
163
429
  }
164
430
 
165
- export { APIConnectionError, APIError, APIStatusError, AuthenticationError, type ChatCompletion, type ChatCompletionChunk, type ChatCompletionCreateParams, type ChatCompletionMessage, type Choice, type ChoiceDelta, type ImageData, type ImageGenerationCreateParams, type ImageResponse, type Model, Pendra, type PendraOptions, RateLimitError, Stream, type StreamChoice, type Usage, Pendra as default };
431
+ export { APIConnectionError, APIError, APIStatusError, type AudioFileInput, AuthenticationError, type ChatCompletion, type ChatCompletionChunk, type ChatCompletionCreateParams, type ChatCompletionMessage, type Choice, type ChoiceDelta, type CreateEmbeddingResponse, type Embedding, type EmbeddingCreateParams, type EmbeddingUsage, type ImageData, type ImageGenerationCreateParams, type ImageResponse, type Model, Pendra, type PendraOptions, PrivateInferenceError, RateLimitError, type RerankCreateParams, type RerankResponse, type RerankResult, type RerankResultDocument, Stream, type StreamChoice, type TranscriptionCreateParams, type TranscriptionResponse, type TranscriptionSegment, type Usage, Pendra as default };
package/dist/index.d.ts CHANGED
@@ -1,3 +1,49 @@
1
+ interface TranscriptionSegment {
2
+ id: number;
3
+ start: number;
4
+ end: number;
5
+ text: string;
6
+ }
7
+ interface TranscriptionResponse {
8
+ text: string;
9
+ language?: string;
10
+ duration?: number;
11
+ segments?: TranscriptionSegment[];
12
+ }
13
+ /** Source for the audio bytes. A `File` works in browsers and Node ≥20
14
+ * (where `Blob`/`FormData`/`File` are stable globals — Node 18 only ships
15
+ * these behind `--experimental-fetch` until 18.17, so this package
16
+ * targets Node 20+ for predictable behaviour). For buffers, Node streams,
17
+ * or plain `Blob`s without a filename, prefer the `{ filename, content }`
18
+ * form so the multipart upload carries a filename + extension — the API
19
+ * uses these for format detection and may reject uploads that lack one. */
20
+ type AudioFileInput = Blob | {
21
+ filename: string;
22
+ content: Blob | ArrayBuffer | Uint8Array;
23
+ };
24
+ interface TranscriptionCreateParams {
25
+ file: AudioFileInput;
26
+ model: string;
27
+ language?: string;
28
+ prompt?: string;
29
+ response_format?: "json" | "text" | "srt" | "vtt" | "verbose_json";
30
+ temperature?: number;
31
+ timestamp_granularities?: ("word" | "segment")[];
32
+ /** Pin to a specific worker (sent as the `X-Pendra-Worker-Id` header). */
33
+ worker_id?: string | null;
34
+ }
35
+
36
+ declare class Transcriptions {
37
+ private client;
38
+ constructor(client: Pendra);
39
+ create(params: TranscriptionCreateParams): Promise<TranscriptionResponse>;
40
+ }
41
+
42
+ declare class Audio {
43
+ transcriptions: Transcriptions;
44
+ constructor(client: Pendra);
45
+ }
46
+
1
47
  interface Usage {
2
48
  prompt_tokens: number;
3
49
  completion_tokens: number;
@@ -47,6 +93,12 @@ interface ChatCompletionCreateParams {
47
93
  top_p?: number | null;
48
94
  stop?: string | string[] | null;
49
95
  stream?: boolean;
96
+ /**
97
+ * Optionally pin the request to a specific worker that serves this model.
98
+ * Sent as the `X-Pendra-Worker-Id` header; when omitted, the least-busy
99
+ * worker is chosen automatically.
100
+ */
101
+ worker_id?: string | null;
50
102
  }
51
103
 
52
104
  declare class Stream implements AsyncIterable<ChatCompletionChunk> {
@@ -70,6 +122,7 @@ declare class Completions {
70
122
  stream?: false;
71
123
  }): Promise<ChatCompletion>;
72
124
  create(params: ChatCompletionCreateParams): Promise<ChatCompletion | Stream>;
125
+ private createEncrypted;
73
126
  }
74
127
 
75
128
  declare class Chat {
@@ -77,6 +130,51 @@ declare class Chat {
77
130
  constructor(client: Pendra);
78
131
  }
79
132
 
133
+ interface EmbeddingCreateParams {
134
+ model: string;
135
+ input: string | string[];
136
+ encoding_format?: "float" | "base64";
137
+ dimensions?: number;
138
+ user?: string;
139
+ /** Pin to a specific worker (sent as the `X-Pendra-Worker-Id` header). */
140
+ worker_id?: string | null;
141
+ }
142
+ interface Embedding {
143
+ object: "embedding";
144
+ /** Array of floats, or a base64-encoded string if encoding_format="base64". */
145
+ embedding: number[] | string;
146
+ index: number;
147
+ }
148
+ interface EmbeddingUsage {
149
+ prompt_tokens: number;
150
+ total_tokens: number;
151
+ }
152
+ interface CreateEmbeddingResponse {
153
+ object: "list";
154
+ data: Embedding[];
155
+ model: string;
156
+ usage: EmbeddingUsage;
157
+ }
158
+
159
+ declare class Embeddings {
160
+ private client;
161
+ constructor(client: Pendra);
162
+ /**
163
+ * Create embeddings for the given input.
164
+ *
165
+ * @example
166
+ * ```ts
167
+ * const result = await client.embeddings.create({
168
+ * model: "nomic-embed-text:latest",
169
+ * input: "Hello world",
170
+ * });
171
+ * console.log(result.data[0].embedding);
172
+ * ```
173
+ */
174
+ create(params: EmbeddingCreateParams): Promise<CreateEmbeddingResponse>;
175
+ private createEncrypted;
176
+ }
177
+
80
178
  interface ImageGenerationCreateParams {
81
179
  model: string;
82
180
  prompt: string;
@@ -86,6 +184,8 @@ interface ImageGenerationCreateParams {
86
184
  num_inference_steps?: number;
87
185
  seed?: number;
88
186
  negative_prompt?: string;
187
+ /** Pin to a specific worker (sent as the `X-Pendra-Worker-Id` header). */
188
+ worker_id?: string | null;
89
189
  }
90
190
  interface ImageData {
91
191
  b64_json?: string;
@@ -120,10 +220,160 @@ declare class Models {
120
220
  list(): Promise<Model[]>;
121
221
  }
122
222
 
223
+ interface RerankCreateParams {
224
+ model: string;
225
+ query: string;
226
+ documents: string[];
227
+ /** Return only the top_n most relevant documents (all when omitted). Must be >= 1. */
228
+ top_n?: number;
229
+ /** When true, each result echoes the original document text. */
230
+ return_documents?: boolean;
231
+ /** Pin to a specific worker (sent as the `X-Pendra-Worker-Id` header). */
232
+ worker_id?: string | null;
233
+ }
234
+ interface RerankResultDocument {
235
+ text: string;
236
+ }
237
+ interface RerankResult {
238
+ index: number;
239
+ relevance_score: number;
240
+ /** Present only when the request set return_documents=true. */
241
+ document?: RerankResultDocument;
242
+ }
243
+ /** Cohere-compatible rerank response: results sorted by relevance (desc). */
244
+ interface RerankResponse {
245
+ id: string;
246
+ results: RerankResult[];
247
+ meta: Record<string, unknown>;
248
+ }
249
+
250
+ declare class Rerank {
251
+ private client;
252
+ constructor(client: Pendra);
253
+ /**
254
+ * Rerank `documents` by relevance to `query` (Cohere-compatible).
255
+ *
256
+ * @example
257
+ * ```ts
258
+ * const result = await client.rerank.create({
259
+ * model: "bge-reranker-v2-m3",
260
+ * query: "What is the capital of France?",
261
+ * documents: ["Paris is the capital of France.", "Berlin is in Germany."],
262
+ * top_n: 1,
263
+ * });
264
+ * console.log(result.results[0].index, result.results[0].relevance_score);
265
+ * ```
266
+ */
267
+ create(params: RerankCreateParams): Promise<RerankResponse>;
268
+ private createEncrypted;
269
+ }
270
+
271
+ interface ResponseInner {
272
+ v?: number;
273
+ enc?: string;
274
+ seq: number;
275
+ ciphertext: string;
276
+ }
277
+ /**
278
+ * Decrypts a worker's sealed response. Derives the response DEK once from the
279
+ * first frame's `enc` (HPKE Export to the client's ephemeral key) and enforces a
280
+ * monotonic `seq` across streaming chunks.
281
+ */
282
+ declare class ResponseDecryptor {
283
+ private respPriv;
284
+ private dek;
285
+ private nextSeq;
286
+ constructor(responsePrivateKey: Uint8Array);
287
+ private ensureDek;
288
+ /** Decrypt a non-streaming result envelope `{v, enc, seq, ciphertext}`. */
289
+ openResult(inner: ResponseInner): Uint8Array;
290
+ /** Decrypt one streaming chunk envelope, enforcing monotonic `seq`. */
291
+ openChunk(inner: ResponseInner): Uint8Array;
292
+ }
293
+ interface AffinityMessage {
294
+ role?: string;
295
+ content?: unknown;
296
+ }
297
+
298
+ /**
299
+ * Private Inference engine: resolves and caches the org workload public key
300
+ * (TOFU by default, or an explicit pinned fingerprint), then seals requests to
301
+ * it. Byte-for-byte port of the Python SDK's `_private_inference_engine`.
302
+ *
303
+ * Deliberately HTTP-agnostic — the calling resource performs the key-fetch GET
304
+ * and hands the returned keys to `resolveOrgKey`, so all the trust logic lives
305
+ * here in one place and is unit-testable without a network. TOFU file I/O uses a
306
+ * dynamic `import("node:fs")` so browser bundles (which require a pinned
307
+ * fingerprint) never need it.
308
+ */
309
+
310
+ declare class PrivateInferenceError extends Error {
311
+ constructor(message: string);
312
+ }
313
+ interface FetchedKey {
314
+ public_key: string;
315
+ fingerprint?: string;
316
+ }
317
+ interface EngineOptions {
318
+ baseUrl: string;
319
+ apiKey: string;
320
+ pinnedFingerprint?: string | null;
321
+ affinitySalt?: Uint8Array | null;
322
+ tofuPath?: string | null;
323
+ }
324
+ declare class PrivateInferenceEngine {
325
+ private baseUrl;
326
+ private apiKey;
327
+ private pinnedFingerprint;
328
+ private affinitySalt;
329
+ private tofuPath;
330
+ private orgPub;
331
+ constructor(opts: EngineOptions);
332
+ cachedOrgPublicKey(): Uint8Array | null;
333
+ private tofuIdentity;
334
+ /**
335
+ * Validate the key(s) returned by GET /v1/private-inference/key against the
336
+ * pin or TOFU record, cache the accepted public key, and return it. Throws
337
+ * PrivateInferenceError on absence or a fingerprint mismatch.
338
+ */
339
+ resolveOrgKey(fetchedKeys: FetchedKey[]): Promise<Uint8Array>;
340
+ private checkTofu;
341
+ private loadTofu;
342
+ private saveTofu;
343
+ /**
344
+ * Seal a request body to the resolved org key. Returns `{ topLevel, decryptor }`.
345
+ * `messages` (chat only) drives the affinity token; pass undefined for non-chat.
346
+ */
347
+ seal(args: {
348
+ model: string;
349
+ stream: boolean;
350
+ taskType: string;
351
+ body: Uint8Array;
352
+ messages?: AffinityMessage[] | null;
353
+ }): {
354
+ topLevel: Record<string, unknown>;
355
+ decryptor: ResponseDecryptor;
356
+ };
357
+ get keyFetchUrl(): string;
358
+ }
359
+
123
360
  interface PendraOptions {
124
361
  apiKey?: string;
125
362
  baseURL?: string;
126
363
  timeout?: number;
364
+ /**
365
+ * Enable end-to-end encrypted (private) inference. When `true`, chat and
366
+ * embeddings requests are sealed to your org's workload key (TOFU-pinned on
367
+ * first use) and the responses are decrypted client-side — Pendra relays only
368
+ * ciphertext. Pass `{ pinnedFingerprint }` to hard-pin the org key fingerprint
369
+ * (required in browser bundles, which cannot use the TOFU key store).
370
+ *
371
+ * Defaults to the `PENDRA_PRIVATE_INFERENCE` environment variable
372
+ * (`1`/`true`/`yes`/`on` enables it).
373
+ */
374
+ privateInference?: boolean | {
375
+ pinnedFingerprint?: string;
376
+ };
127
377
  }
128
378
  declare class Pendra {
129
379
  readonly apiKey: string;
@@ -131,13 +381,29 @@ declare class Pendra {
131
381
  readonly timeout: number;
132
382
  chat: Chat;
133
383
  images: Images;
384
+ embeddings: Embeddings;
134
385
  models: Models;
386
+ audio: Audio;
387
+ rerank: Rerank;
388
+ /** @internal Whether end-to-end encrypted inference is enabled for this client. */
389
+ readonly privateInferenceEnabled: boolean;
390
+ private _piEngine;
391
+ private _piKeyFetch;
135
392
  constructor(options?: PendraOptions);
393
+ /**
394
+ * @internal
395
+ * Return the private-inference engine with its org key resolved. Fetches
396
+ * `GET {baseUrl}/v1/private-inference/key` exactly once (subsequent calls reuse
397
+ * the cached key). Throws if private inference is not enabled.
398
+ */
399
+ _privateEngine(): Promise<PrivateInferenceEngine>;
400
+ private _fetchAndResolveOrgKey;
136
401
  /** @internal */
137
402
  _fetch(path: string, options: {
138
403
  method: string;
139
404
  body?: Record<string, unknown>;
140
405
  stream?: boolean;
406
+ headers?: Record<string, string>;
141
407
  }): Promise<{
142
408
  response: Response;
143
409
  controller: AbortController;
@@ -162,4 +428,4 @@ declare class RateLimitError extends APIStatusError {
162
428
  constructor(message?: string);
163
429
  }
164
430
 
165
- export { APIConnectionError, APIError, APIStatusError, AuthenticationError, type ChatCompletion, type ChatCompletionChunk, type ChatCompletionCreateParams, type ChatCompletionMessage, type Choice, type ChoiceDelta, type ImageData, type ImageGenerationCreateParams, type ImageResponse, type Model, Pendra, type PendraOptions, RateLimitError, Stream, type StreamChoice, type Usage, Pendra as default };
431
+ export { APIConnectionError, APIError, APIStatusError, type AudioFileInput, AuthenticationError, type ChatCompletion, type ChatCompletionChunk, type ChatCompletionCreateParams, type ChatCompletionMessage, type Choice, type ChoiceDelta, type CreateEmbeddingResponse, type Embedding, type EmbeddingCreateParams, type EmbeddingUsage, type ImageData, type ImageGenerationCreateParams, type ImageResponse, type Model, Pendra, type PendraOptions, PrivateInferenceError, RateLimitError, type RerankCreateParams, type RerankResponse, type RerankResult, type RerankResultDocument, Stream, type StreamChoice, type TranscriptionCreateParams, type TranscriptionResponse, type TranscriptionSegment, type Usage, Pendra as default };