pendra 0.10.0 → 0.12.2

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
@@ -70,6 +70,44 @@ console.log(response.choices[0].message.reasoning_content); // the working, when
70
70
  console.log(response.choices[0].message.content); // the answer
71
71
  ```
72
72
 
73
+ ## Notices, timings and other response extras
74
+
75
+ Replies carry a Pendra-specific `pendra` field alongside `choices`. Read
76
+ `response.pendra?.notice` when an answer looks wrong for no obvious reason —
77
+ `truncated_during_reasoning` is the model saying it spent the whole
78
+ `max_tokens` budget thinking and never reached an answer, which otherwise just
79
+ looks like an empty `message.content`:
80
+
81
+ ```typescript
82
+ if (response.pendra?.notice?.code === 'truncated_during_reasoning') {
83
+ console.log(response.pendra.notice.message);
84
+ // Where the budget went:
85
+ console.log(response.usage?.completion_tokens_details?.reasoning_tokens);
86
+ // Retry with a bigger max_tokens, or with enable_thinking: false.
87
+ }
88
+ ```
89
+
90
+ The other codes are `truncated_during_structured_output` and
91
+ `strict_schema_not_enforced`. The same field carries `pendra.web_tool_steps`
92
+ when the serving worker has web tools enabled.
93
+
94
+ When streaming, the last few chunks report on the request rather than
95
+ continuing the answer — one carries `chunk.usage`, one carries
96
+ `chunk.pendra?.timing` (`ttft_ms`, `tokens_per_second`, `queue_wait_ms`,
97
+ `worker_queue_wait_ms`), and a notice arrives on its own chunk too:
98
+
99
+ ```typescript
100
+ for await (const chunk of stream) {
101
+ process.stdout.write(chunk.choices[0]?.delta?.content ?? '');
102
+ if (chunk.pendra?.notice) console.warn(chunk.pendra.notice.message);
103
+ if (chunk.pendra?.timing) console.log(`${chunk.pendra.timing.tokens_per_second} tok/s`);
104
+ }
105
+ ```
106
+
107
+ Those chunks have no text, which is why the loop above reads content with
108
+ `chunk.choices[0]?.delta?.content` rather than indexing `choices[0]`
109
+ unconditionally.
110
+
73
111
  ## Parameters
74
112
 
75
113
  `chat.completions.create()` passes everything you give it to the API —
package/dist/index.d.mts CHANGED
@@ -28,6 +28,10 @@ interface TranscriptionCreateParams {
28
28
  prompt?: string;
29
29
  response_format?: "json" | "text" | "srt" | "vtt" | "verbose_json";
30
30
  temperature?: number;
31
+ /** Decoding beam width, 1-8. Omit to use the server default (beam search —
32
+ * the highest-accuracy setting). Pass `1` to decode greedily, which is
33
+ * faster but less accurate. */
34
+ beam_size?: number;
31
35
  timestamp_granularities?: ("word" | "segment")[];
32
36
  /** Pin to a specific worker (sent as the `X-Pendra-Worker-Id` header). */
33
37
  worker_id?: string | null;
@@ -44,10 +48,27 @@ declare class Audio {
44
48
  constructor(client: Pendra);
45
49
  }
46
50
 
51
+ /**
52
+ * Breakdown of `completion_tokens`. Currently just the reasoning share, and
53
+ * omitted entirely when a model did no reasoning — so treat a missing value as
54
+ * 0 rather than as unknown.
55
+ */
56
+ interface CompletionTokensDetails {
57
+ reasoning_tokens?: number;
58
+ }
47
59
  interface Usage {
48
60
  prompt_tokens: number;
49
61
  completion_tokens: number;
50
62
  total_tokens: number;
63
+ /**
64
+ * How many of `completion_tokens` a reasoning model spent thinking. Without
65
+ * it you cannot tell "the model had nothing to say" from "the model used its
66
+ * whole budget reasoning and never reached an answer" — the two look
67
+ * identical when `content` is empty, and only the second has a remedy (raise
68
+ * `max_tokens`, or `enable_thinking: false`). The matching advisory arrives
69
+ * on {@link ChatCompletion.pendra} as a `truncated_during_reasoning` notice.
70
+ */
71
+ completion_tokens_details?: CompletionTokensDetails | null;
51
72
  }
52
73
  interface ChatCompletionMessageToolCall {
53
74
  /**
@@ -108,6 +129,100 @@ interface Choice {
108
129
  message: ChatCompletionMessage;
109
130
  finish_reason: string | null;
110
131
  }
132
+ /**
133
+ * A machine-readable advisory about how a completion was produced. `code` is a
134
+ * stable identifier worth switching on; `message` is human-readable and already
135
+ * says what to do about it. At most one rides on a completion.
136
+ */
137
+ interface PendraNotice {
138
+ code:
139
+ /**
140
+ * A reasoning model spent its whole `max_tokens` budget thinking and
141
+ * produced no answer — `content` empty, `finish_reason: "length"`, and the
142
+ * working on `reasoning_content`. Retry with a larger budget, or with
143
+ * `enable_thinking: false`.
144
+ */
145
+ "truncated_during_reasoning"
146
+ /**
147
+ * A `response_format` reply ran out of budget before its JSON was
148
+ * complete, so `content` will not parse. Retry with a larger `max_tokens`,
149
+ * or a shorter prompt if the context window was the limit.
150
+ */
151
+ | "truncated_during_structured_output"
152
+ /**
153
+ * `response_format.json_schema.strict` was set but part of the schema
154
+ * could not be held to, so validate the reply before relying on it.
155
+ */
156
+ | "strict_schema_not_enforced" | (string & {});
157
+ message: string;
158
+ }
159
+ /**
160
+ * Per-request performance for a streaming completion, on the last chunk before
161
+ * `[DONE]`. Non-streaming replies get the same figures in the `Server-Timing`
162
+ * response header instead — headers flush before the first token, so a stream
163
+ * cannot use them.
164
+ *
165
+ * Every field is present only when it was measured, and the whole block is
166
+ * omitted when nothing was (an older worker reports no timings at all).
167
+ */
168
+ interface PendraTiming {
169
+ /** Time to first token, in ms — prompt processing only, queue wait excluded. */
170
+ ttft_ms?: number;
171
+ /** Generation rate over the decode phase. */
172
+ tokens_per_second?: number;
173
+ /** Total time the request waited before generation started, in ms. */
174
+ queue_wait_ms?: number;
175
+ /**
176
+ * How much of `queue_wait_ms` was spent on the worker that served you; the
177
+ * remainder was spent waiting for any worker with a free slot. The first
178
+ * points at that worker's concurrency settings, the second at needing more
179
+ * workers.
180
+ */
181
+ worker_queue_wait_ms?: number;
182
+ /** Time spent loading the model, on a cold start only. */
183
+ model_load_ms?: number;
184
+ /** `true` when the model had to be loaded for this request. */
185
+ cold_start?: boolean;
186
+ }
187
+ /**
188
+ * One web-tool step a model ran while answering — reported only when the
189
+ * serving worker has web tools enabled.
190
+ */
191
+ interface PendraWebToolStep {
192
+ index: number;
193
+ name: "web_fetch" | "web_search" | (string & {});
194
+ /**
195
+ * Streaming only: `"call"` when the model asks for the step, `"result"` once
196
+ * it has run. The non-streaming aggregate carries finished steps, so it has
197
+ * no phase.
198
+ */
199
+ phase?: string;
200
+ id?: string;
201
+ /** The step's arguments, as a JSON string. */
202
+ arguments?: string;
203
+ ok?: boolean;
204
+ /** A truncated preview of what the step returned. */
205
+ result?: string;
206
+ /** Full length of the result, before the `result` preview was truncated. */
207
+ result_chars?: number;
208
+ error?: string;
209
+ }
210
+ /**
211
+ * Pendra's non-OpenAI extension block, a sibling of `choices`. Absent on an
212
+ * ordinary request, and safe for an OpenAI-compatible client to ignore — which
213
+ * is exactly why the advisory that explains an otherwise-inexplicable reply
214
+ * lives here rather than in `choices`.
215
+ */
216
+ interface PendraExtension {
217
+ /** An advisory about this completion — see {@link PendraNotice}. */
218
+ notice?: PendraNotice | null;
219
+ /** Streaming only, on the last chunk before `[DONE]`. */
220
+ timing?: PendraTiming | null;
221
+ /** Streaming only: one web-tool event, on a chunk with an empty delta. */
222
+ web_tool_step?: PendraWebToolStep | null;
223
+ /** Non-streaming: every web-tool step the model ran, in order. */
224
+ web_tool_steps?: PendraWebToolStep[] | null;
225
+ }
111
226
  interface ChatCompletion {
112
227
  id: string;
113
228
  object: string;
@@ -115,6 +230,14 @@ interface ChatCompletion {
115
230
  model: string;
116
231
  choices: Choice[];
117
232
  usage: Usage | null;
233
+ /**
234
+ * Pendra's extension block — read it as `response.pendra?.notice`. Carries
235
+ * the advisory that explains an otherwise-inexplicable reply, most
236
+ * importantly an empty `content` that cost a full budget of reasoning
237
+ * tokens, plus the web-tool steps the model ran. Absent on an ordinary
238
+ * request.
239
+ */
240
+ pendra?: PendraExtension | null;
118
241
  }
119
242
  interface ChoiceDelta {
120
243
  role?: string | null;
@@ -139,6 +262,21 @@ interface ChatCompletionChunk {
139
262
  created: number;
140
263
  model: string;
141
264
  choices: StreamChoice[];
265
+ /**
266
+ * Token counts for the whole request, on a dedicated chunk near the end of
267
+ * the stream. Pendra sets `stream_options.include_usage` server-side, so it
268
+ * arrives whether or not you asked for it.
269
+ */
270
+ usage?: Usage | null;
271
+ /**
272
+ * Pendra's extension block. A stream carries it on chunks that report on the
273
+ * request rather than continuing the answer — a {@link PendraNotice} on a
274
+ * chunk with an empty delta, a {@link PendraWebToolStep} likewise, and
275
+ * {@link PendraTiming} on the last chunk before `[DONE]`. Those chunks have
276
+ * no text, which is why the streaming examples read content with
277
+ * `chunk.choices[0]?.delta?.content` rather than indexing unconditionally.
278
+ */
279
+ pendra?: PendraExtension | null;
142
280
  }
143
281
  /**
144
282
  * Parameters for `client.chat.completions.create()`.
@@ -464,6 +602,23 @@ declare class PrivateInferenceEngine {
464
602
  cachedOrgPublicKeys(): Uint8Array[] | null;
465
603
  cachedOrgPublicKey(): Uint8Array | null;
466
604
  private tofuIdentity;
605
+ /**
606
+ * Drop the cached key set so the next call re-fetches it.
607
+ *
608
+ * The cache is otherwise held for the whole process lifetime, which is
609
+ * correct while a fleet keeps one key but fatal when it re-keys: a
610
+ * long-running server would go on sealing to a fingerprint no worker holds
611
+ * and fail EVERY request until someone restarted it. The API signals a re-key
612
+ * with `X-Pendra-Error-Code: no_private_inference_worker`, and this is what
613
+ * lets the client recover on its own.
614
+ *
615
+ * Pinned clients are deliberately NOT re-fetched on that signal — a pin is an
616
+ * allowlist, so a fetch could only return fingerprints the pin already
617
+ * rejects. They surface the error instead, which is what pinning means.
618
+ */
619
+ invalidateOrgKey(): void;
620
+ /** Whether this client seals only to an explicit fingerprint allowlist. */
621
+ get isPinned(): boolean;
467
622
  /**
468
623
  * Validate the key(s) returned by GET /v1/private-inference/key, apply the pin
469
624
  * allowlist (or auto-trust TOFU), cache the accepted public keys, and return
@@ -544,6 +699,17 @@ declare class Pendra {
544
699
  response: Response;
545
700
  controller: AbortController;
546
701
  }>;
702
+ /**
703
+ * Drop the cached encryption keys when the API reports that no worker holds
704
+ * the one this request was sealed to — the signal that the org's fleet has
705
+ * re-keyed. Returns true if the cache was dropped.
706
+ *
707
+ * A PINNED client is left alone on purpose: a pin is an allowlist, so
708
+ * re-fetching could only return fingerprints the pin already rejects and
709
+ * would loop rather than recover. The error surfaces instead, which is
710
+ * exactly what pinning is for.
711
+ */
712
+ private invalidateKeyCacheIfRekeyed;
547
713
  }
548
714
 
549
715
  declare class APIError extends Error {
@@ -564,4 +730,4 @@ declare class RateLimitError extends APIStatusError {
564
730
  constructor(message?: string);
565
731
  }
566
732
 
567
- export { APIConnectionError, APIError, APIStatusError, type AudioFileInput, AuthenticationError, type ChatCompletion, type ChatCompletionChunk, type ChatCompletionContentPart, type ChatCompletionCreateParams, type ChatCompletionMessage, type ChatCompletionMessageParam, type ChatCompletionMessageToolCall, 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 };
733
+ export { APIConnectionError, APIError, APIStatusError, type AudioFileInput, AuthenticationError, type ChatCompletion, type ChatCompletionChunk, type ChatCompletionContentPart, type ChatCompletionCreateParams, type ChatCompletionMessage, type ChatCompletionMessageParam, type ChatCompletionMessageToolCall, type Choice, type ChoiceDelta, type CompletionTokensDetails, type CreateEmbeddingResponse, type Embedding, type EmbeddingCreateParams, type EmbeddingUsage, type ImageData, type ImageGenerationCreateParams, type ImageResponse, type Model, Pendra, type PendraExtension, type PendraNotice, type PendraOptions, type PendraTiming, type PendraWebToolStep, 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
@@ -28,6 +28,10 @@ interface TranscriptionCreateParams {
28
28
  prompt?: string;
29
29
  response_format?: "json" | "text" | "srt" | "vtt" | "verbose_json";
30
30
  temperature?: number;
31
+ /** Decoding beam width, 1-8. Omit to use the server default (beam search —
32
+ * the highest-accuracy setting). Pass `1` to decode greedily, which is
33
+ * faster but less accurate. */
34
+ beam_size?: number;
31
35
  timestamp_granularities?: ("word" | "segment")[];
32
36
  /** Pin to a specific worker (sent as the `X-Pendra-Worker-Id` header). */
33
37
  worker_id?: string | null;
@@ -44,10 +48,27 @@ declare class Audio {
44
48
  constructor(client: Pendra);
45
49
  }
46
50
 
51
+ /**
52
+ * Breakdown of `completion_tokens`. Currently just the reasoning share, and
53
+ * omitted entirely when a model did no reasoning — so treat a missing value as
54
+ * 0 rather than as unknown.
55
+ */
56
+ interface CompletionTokensDetails {
57
+ reasoning_tokens?: number;
58
+ }
47
59
  interface Usage {
48
60
  prompt_tokens: number;
49
61
  completion_tokens: number;
50
62
  total_tokens: number;
63
+ /**
64
+ * How many of `completion_tokens` a reasoning model spent thinking. Without
65
+ * it you cannot tell "the model had nothing to say" from "the model used its
66
+ * whole budget reasoning and never reached an answer" — the two look
67
+ * identical when `content` is empty, and only the second has a remedy (raise
68
+ * `max_tokens`, or `enable_thinking: false`). The matching advisory arrives
69
+ * on {@link ChatCompletion.pendra} as a `truncated_during_reasoning` notice.
70
+ */
71
+ completion_tokens_details?: CompletionTokensDetails | null;
51
72
  }
52
73
  interface ChatCompletionMessageToolCall {
53
74
  /**
@@ -108,6 +129,100 @@ interface Choice {
108
129
  message: ChatCompletionMessage;
109
130
  finish_reason: string | null;
110
131
  }
132
+ /**
133
+ * A machine-readable advisory about how a completion was produced. `code` is a
134
+ * stable identifier worth switching on; `message` is human-readable and already
135
+ * says what to do about it. At most one rides on a completion.
136
+ */
137
+ interface PendraNotice {
138
+ code:
139
+ /**
140
+ * A reasoning model spent its whole `max_tokens` budget thinking and
141
+ * produced no answer — `content` empty, `finish_reason: "length"`, and the
142
+ * working on `reasoning_content`. Retry with a larger budget, or with
143
+ * `enable_thinking: false`.
144
+ */
145
+ "truncated_during_reasoning"
146
+ /**
147
+ * A `response_format` reply ran out of budget before its JSON was
148
+ * complete, so `content` will not parse. Retry with a larger `max_tokens`,
149
+ * or a shorter prompt if the context window was the limit.
150
+ */
151
+ | "truncated_during_structured_output"
152
+ /**
153
+ * `response_format.json_schema.strict` was set but part of the schema
154
+ * could not be held to, so validate the reply before relying on it.
155
+ */
156
+ | "strict_schema_not_enforced" | (string & {});
157
+ message: string;
158
+ }
159
+ /**
160
+ * Per-request performance for a streaming completion, on the last chunk before
161
+ * `[DONE]`. Non-streaming replies get the same figures in the `Server-Timing`
162
+ * response header instead — headers flush before the first token, so a stream
163
+ * cannot use them.
164
+ *
165
+ * Every field is present only when it was measured, and the whole block is
166
+ * omitted when nothing was (an older worker reports no timings at all).
167
+ */
168
+ interface PendraTiming {
169
+ /** Time to first token, in ms — prompt processing only, queue wait excluded. */
170
+ ttft_ms?: number;
171
+ /** Generation rate over the decode phase. */
172
+ tokens_per_second?: number;
173
+ /** Total time the request waited before generation started, in ms. */
174
+ queue_wait_ms?: number;
175
+ /**
176
+ * How much of `queue_wait_ms` was spent on the worker that served you; the
177
+ * remainder was spent waiting for any worker with a free slot. The first
178
+ * points at that worker's concurrency settings, the second at needing more
179
+ * workers.
180
+ */
181
+ worker_queue_wait_ms?: number;
182
+ /** Time spent loading the model, on a cold start only. */
183
+ model_load_ms?: number;
184
+ /** `true` when the model had to be loaded for this request. */
185
+ cold_start?: boolean;
186
+ }
187
+ /**
188
+ * One web-tool step a model ran while answering — reported only when the
189
+ * serving worker has web tools enabled.
190
+ */
191
+ interface PendraWebToolStep {
192
+ index: number;
193
+ name: "web_fetch" | "web_search" | (string & {});
194
+ /**
195
+ * Streaming only: `"call"` when the model asks for the step, `"result"` once
196
+ * it has run. The non-streaming aggregate carries finished steps, so it has
197
+ * no phase.
198
+ */
199
+ phase?: string;
200
+ id?: string;
201
+ /** The step's arguments, as a JSON string. */
202
+ arguments?: string;
203
+ ok?: boolean;
204
+ /** A truncated preview of what the step returned. */
205
+ result?: string;
206
+ /** Full length of the result, before the `result` preview was truncated. */
207
+ result_chars?: number;
208
+ error?: string;
209
+ }
210
+ /**
211
+ * Pendra's non-OpenAI extension block, a sibling of `choices`. Absent on an
212
+ * ordinary request, and safe for an OpenAI-compatible client to ignore — which
213
+ * is exactly why the advisory that explains an otherwise-inexplicable reply
214
+ * lives here rather than in `choices`.
215
+ */
216
+ interface PendraExtension {
217
+ /** An advisory about this completion — see {@link PendraNotice}. */
218
+ notice?: PendraNotice | null;
219
+ /** Streaming only, on the last chunk before `[DONE]`. */
220
+ timing?: PendraTiming | null;
221
+ /** Streaming only: one web-tool event, on a chunk with an empty delta. */
222
+ web_tool_step?: PendraWebToolStep | null;
223
+ /** Non-streaming: every web-tool step the model ran, in order. */
224
+ web_tool_steps?: PendraWebToolStep[] | null;
225
+ }
111
226
  interface ChatCompletion {
112
227
  id: string;
113
228
  object: string;
@@ -115,6 +230,14 @@ interface ChatCompletion {
115
230
  model: string;
116
231
  choices: Choice[];
117
232
  usage: Usage | null;
233
+ /**
234
+ * Pendra's extension block — read it as `response.pendra?.notice`. Carries
235
+ * the advisory that explains an otherwise-inexplicable reply, most
236
+ * importantly an empty `content` that cost a full budget of reasoning
237
+ * tokens, plus the web-tool steps the model ran. Absent on an ordinary
238
+ * request.
239
+ */
240
+ pendra?: PendraExtension | null;
118
241
  }
119
242
  interface ChoiceDelta {
120
243
  role?: string | null;
@@ -139,6 +262,21 @@ interface ChatCompletionChunk {
139
262
  created: number;
140
263
  model: string;
141
264
  choices: StreamChoice[];
265
+ /**
266
+ * Token counts for the whole request, on a dedicated chunk near the end of
267
+ * the stream. Pendra sets `stream_options.include_usage` server-side, so it
268
+ * arrives whether or not you asked for it.
269
+ */
270
+ usage?: Usage | null;
271
+ /**
272
+ * Pendra's extension block. A stream carries it on chunks that report on the
273
+ * request rather than continuing the answer — a {@link PendraNotice} on a
274
+ * chunk with an empty delta, a {@link PendraWebToolStep} likewise, and
275
+ * {@link PendraTiming} on the last chunk before `[DONE]`. Those chunks have
276
+ * no text, which is why the streaming examples read content with
277
+ * `chunk.choices[0]?.delta?.content` rather than indexing unconditionally.
278
+ */
279
+ pendra?: PendraExtension | null;
142
280
  }
143
281
  /**
144
282
  * Parameters for `client.chat.completions.create()`.
@@ -464,6 +602,23 @@ declare class PrivateInferenceEngine {
464
602
  cachedOrgPublicKeys(): Uint8Array[] | null;
465
603
  cachedOrgPublicKey(): Uint8Array | null;
466
604
  private tofuIdentity;
605
+ /**
606
+ * Drop the cached key set so the next call re-fetches it.
607
+ *
608
+ * The cache is otherwise held for the whole process lifetime, which is
609
+ * correct while a fleet keeps one key but fatal when it re-keys: a
610
+ * long-running server would go on sealing to a fingerprint no worker holds
611
+ * and fail EVERY request until someone restarted it. The API signals a re-key
612
+ * with `X-Pendra-Error-Code: no_private_inference_worker`, and this is what
613
+ * lets the client recover on its own.
614
+ *
615
+ * Pinned clients are deliberately NOT re-fetched on that signal — a pin is an
616
+ * allowlist, so a fetch could only return fingerprints the pin already
617
+ * rejects. They surface the error instead, which is what pinning means.
618
+ */
619
+ invalidateOrgKey(): void;
620
+ /** Whether this client seals only to an explicit fingerprint allowlist. */
621
+ get isPinned(): boolean;
467
622
  /**
468
623
  * Validate the key(s) returned by GET /v1/private-inference/key, apply the pin
469
624
  * allowlist (or auto-trust TOFU), cache the accepted public keys, and return
@@ -544,6 +699,17 @@ declare class Pendra {
544
699
  response: Response;
545
700
  controller: AbortController;
546
701
  }>;
702
+ /**
703
+ * Drop the cached encryption keys when the API reports that no worker holds
704
+ * the one this request was sealed to — the signal that the org's fleet has
705
+ * re-keyed. Returns true if the cache was dropped.
706
+ *
707
+ * A PINNED client is left alone on purpose: a pin is an allowlist, so
708
+ * re-fetching could only return fingerprints the pin already rejects and
709
+ * would loop rather than recover. The error surfaces instead, which is
710
+ * exactly what pinning is for.
711
+ */
712
+ private invalidateKeyCacheIfRekeyed;
547
713
  }
548
714
 
549
715
  declare class APIError extends Error {
@@ -564,4 +730,4 @@ declare class RateLimitError extends APIStatusError {
564
730
  constructor(message?: string);
565
731
  }
566
732
 
567
- export { APIConnectionError, APIError, APIStatusError, type AudioFileInput, AuthenticationError, type ChatCompletion, type ChatCompletionChunk, type ChatCompletionContentPart, type ChatCompletionCreateParams, type ChatCompletionMessage, type ChatCompletionMessageParam, type ChatCompletionMessageToolCall, 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 };
733
+ export { APIConnectionError, APIError, APIStatusError, type AudioFileInput, AuthenticationError, type ChatCompletion, type ChatCompletionChunk, type ChatCompletionContentPart, type ChatCompletionCreateParams, type ChatCompletionMessage, type ChatCompletionMessageParam, type ChatCompletionMessageToolCall, type Choice, type ChoiceDelta, type CompletionTokensDetails, type CreateEmbeddingResponse, type Embedding, type EmbeddingCreateParams, type EmbeddingUsage, type ImageData, type ImageGenerationCreateParams, type ImageResponse, type Model, Pendra, type PendraExtension, type PendraNotice, type PendraOptions, type PendraTiming, type PendraWebToolStep, 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.js CHANGED
@@ -150,6 +150,7 @@ var Transcriptions = class {
150
150
  if (params.prompt) form.append("prompt", params.prompt);
151
151
  if (params.response_format) form.append("response_format", params.response_format);
152
152
  if (params.temperature != null) form.append("temperature", String(params.temperature));
153
+ if (params.beam_size != null) form.append("beam_size", String(params.beam_size));
153
154
  if (params.timestamp_granularities) {
154
155
  for (const g of params.timestamp_granularities) {
155
156
  form.append("timestamp_granularities[]", g);
@@ -665,6 +666,10 @@ var Rerank = class {
665
666
  }
666
667
  };
667
668
 
669
+ // src/version.ts
670
+ var VERSION = "0.12.2";
671
+ var USER_AGENT = `pendra-node/${VERSION}`;
672
+
668
673
  // src/_hpke.ts
669
674
  var import_ed25519 = require("@noble/curves/ed25519.js");
670
675
  var import_chacha = require("@noble/ciphers/chacha.js");
@@ -1058,6 +1063,27 @@ var PrivateInferenceEngine = class {
1058
1063
  const digest = sha256Hex(new TextEncoder().encode(this.apiKey)).slice(0, 16);
1059
1064
  return `${this.baseUrl}|${digest}`;
1060
1065
  }
1066
+ /**
1067
+ * Drop the cached key set so the next call re-fetches it.
1068
+ *
1069
+ * The cache is otherwise held for the whole process lifetime, which is
1070
+ * correct while a fleet keeps one key but fatal when it re-keys: a
1071
+ * long-running server would go on sealing to a fingerprint no worker holds
1072
+ * and fail EVERY request until someone restarted it. The API signals a re-key
1073
+ * with `X-Pendra-Error-Code: no_private_inference_worker`, and this is what
1074
+ * lets the client recover on its own.
1075
+ *
1076
+ * Pinned clients are deliberately NOT re-fetched on that signal — a pin is an
1077
+ * allowlist, so a fetch could only return fingerprints the pin already
1078
+ * rejects. They surface the error instead, which is what pinning means.
1079
+ */
1080
+ invalidateOrgKey() {
1081
+ this.orgPubs = null;
1082
+ }
1083
+ /** Whether this client seals only to an explicit fingerprint allowlist. */
1084
+ get isPinned() {
1085
+ return this.pinnedFingerprints !== null;
1086
+ }
1061
1087
  /**
1062
1088
  * Validate the key(s) returned by GET /v1/private-inference/key, apply the pin
1063
1089
  * allowlist (or auto-trust TOFU), cache the accepted public keys, and return
@@ -1070,7 +1096,7 @@ var PrivateInferenceEngine = class {
1070
1096
  if (this.orgPubs !== null) return this.orgPubs;
1071
1097
  if (!fetchedKeys || fetchedKeys.length === 0) {
1072
1098
  throw new PrivateInferenceError(
1073
- "No private-inference workload key is registered for this organisation. Run `pendra keygen --save` on your worker(s), then reconnect them."
1099
+ "No encryption key is registered for this organisation. Start a worker and it will be issued one automatically."
1074
1100
  );
1075
1101
  }
1076
1102
  const pubs = [];
@@ -1096,7 +1122,7 @@ var PrivateInferenceEngine = class {
1096
1122
  if (accepted.length === 0) {
1097
1123
  const pinned = Array.from(this.pinnedFingerprints).sort().join(", ");
1098
1124
  throw new PrivateInferenceError(
1099
- `None of the org's workload key fingerprints (${fps.join(", ")}) match your pinned fingerprint(s) (${pinned}). Refusing to seal (possible man-in-the-middle). Verify the fingerprint(s) from \`pendra keygen\` and update the pin if you rotated keys.`
1125
+ `None of the org's workload key fingerprints (${fps.join(", ")}) match your pinned fingerprint(s) (${pinned}). Refusing to seal (possible man-in-the-middle). If your fleet re-keyed \u2014 which happens when every worker goes offline at once \u2014 update the pin to a current fingerprint from the console.`
1100
1126
  );
1101
1127
  }
1102
1128
  } else {
@@ -1270,7 +1296,7 @@ var Pendra = class {
1270
1296
  try {
1271
1297
  response = await fetch(url, {
1272
1298
  method: "GET",
1273
- headers: { Authorization: `Bearer ${this.apiKey}` },
1299
+ headers: { Authorization: `Bearer ${this.apiKey}`, "User-Agent": USER_AGENT },
1274
1300
  signal: controller.signal
1275
1301
  });
1276
1302
  } catch (err) {
@@ -1285,7 +1311,7 @@ var Pendra = class {
1285
1311
  }
1286
1312
  if (response.status === 404) {
1287
1313
  throw new PrivateInferenceError(
1288
- "No private-inference workload key is registered for this organisation. Run `pendra keygen --save` on your worker(s), then reconnect them."
1314
+ "No encryption key is registered for this organisation. Start a worker and it will be issued one automatically."
1289
1315
  );
1290
1316
  }
1291
1317
  if (!response.ok) {
@@ -1310,6 +1336,7 @@ var Pendra = class {
1310
1336
  const headers = {
1311
1337
  Authorization: `Bearer ${this.apiKey}`,
1312
1338
  "Content-Type": "application/json",
1339
+ "User-Agent": USER_AGENT,
1313
1340
  ...options.headers ?? {}
1314
1341
  };
1315
1342
  let response;
@@ -1336,6 +1363,7 @@ var Pendra = class {
1336
1363
  }
1337
1364
  if (!response.ok) {
1338
1365
  clearTimeout(timeoutId);
1366
+ this.invalidateKeyCacheIfRekeyed(response);
1339
1367
  let message;
1340
1368
  try {
1341
1369
  const body = await response.json();
@@ -1349,6 +1377,26 @@ var Pendra = class {
1349
1377
  }
1350
1378
  return { response, controller };
1351
1379
  }
1380
+ /**
1381
+ * Drop the cached encryption keys when the API reports that no worker holds
1382
+ * the one this request was sealed to — the signal that the org's fleet has
1383
+ * re-keyed. Returns true if the cache was dropped.
1384
+ *
1385
+ * A PINNED client is left alone on purpose: a pin is an allowlist, so
1386
+ * re-fetching could only return fingerprints the pin already rejects and
1387
+ * would loop rather than recover. The error surfaces instead, which is
1388
+ * exactly what pinning is for.
1389
+ */
1390
+ invalidateKeyCacheIfRekeyed(response) {
1391
+ const engine = this._piEngine;
1392
+ if (!engine || engine.isPinned) return false;
1393
+ if (response.headers?.get("X-Pendra-Error-Code") !== "no_private_inference_worker") {
1394
+ return false;
1395
+ }
1396
+ engine.invalidateOrgKey();
1397
+ this._piKeyFetch = null;
1398
+ return true;
1399
+ }
1352
1400
  };
1353
1401
 
1354
1402
  // src/index.ts