pendra 0.16.0 → 0.17.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/dist/index.d.ts CHANGED
@@ -1,60 +1,3 @@
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
- /** 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;
35
- timestamp_granularities?: ("word" | "segment")[];
36
- /** Pin to a specific worker (sent as the `X-Pendra-Worker-Id` header). */
37
- worker_id?: string | null;
38
- }
39
-
40
- declare class Transcriptions {
41
- private client;
42
- constructor(client: Pendra);
43
- create(params: TranscriptionCreateParams): Promise<TranscriptionResponse>;
44
- /**
45
- * Private-inference transcription. There is no multipart upload: the audio
46
- * bytes ride inside the envelope (sealed under the request's data key) and
47
- * the request options are the sealed JSON body, POSTed as JSON to the same
48
- * route.
49
- */
50
- private createEncrypted;
51
- }
52
-
53
- declare class Audio {
54
- transcriptions: Transcriptions;
55
- constructor(client: Pendra);
56
- }
57
-
58
1
  /**
59
2
  * Breakdown of `completion_tokens`. Currently just the reasoning share, and
60
3
  * omitted entirely when a model did no reasoning — so treat a missing value as
@@ -214,6 +157,22 @@ interface PendraWebToolStep {
214
157
  result_chars?: number;
215
158
  error?: string;
216
159
  }
160
+ /**
161
+ * The Pendra GPU worker that served a request ("placement"). `id` is the
162
+ * worker's stable id — the one `worker_id` pins a request to, and the one the
163
+ * console shows — and `name` is the name it was given in the console, or `null`
164
+ * when it has none.
165
+ */
166
+ interface PendraWorker {
167
+ id: string;
168
+ name: string | null;
169
+ /**
170
+ * The worker release that served the request (e.g. `"3.115.1"`), as reported
171
+ * when the worker last connected. `null` when unknown — an older API, or a
172
+ * worker that reported none.
173
+ */
174
+ version: string | null;
175
+ }
217
176
  /**
218
177
  * Pendra's non-OpenAI extension block, a sibling of `choices`. Absent on an
219
178
  * ordinary request, and safe for an OpenAI-compatible client to ignore — which
@@ -229,6 +188,18 @@ interface PendraExtension {
229
188
  web_tool_step?: PendraWebToolStep | null;
230
189
  /** Non-streaming: every web-tool step the model ran, in order. */
231
190
  web_tool_steps?: PendraWebToolStep[] | null;
191
+ /**
192
+ * The worker that served the request. On a non-streaming reply it rides on
193
+ * the response itself; on a stream it arrives on the last chunk before
194
+ * `[DONE]`, alongside {@link PendraExtension.timing}. Absent when the API
195
+ * didn't report one (an older API, or a request no worker served).
196
+ */
197
+ worker?: PendraWorker | null;
198
+ /**
199
+ * Pendra's id for this request, reported with {@link PendraExtension.worker}.
200
+ * Quote it with the worker id when asking Pendra support about a request.
201
+ */
202
+ request_id?: string | null;
232
203
  }
233
204
  interface ChatCompletion {
234
205
  id: string;
@@ -241,8 +212,8 @@ interface ChatCompletion {
241
212
  * Pendra's extension block — read it as `response.pendra?.notice`. Carries
242
213
  * the advisory that explains an otherwise-inexplicable reply, most
243
214
  * importantly an empty `content` that cost a full budget of reasoning
244
- * tokens, plus the web-tool steps the model ran. Absent on an ordinary
245
- * request.
215
+ * tokens, plus the web-tool steps the model ran — and which worker served
216
+ * the request, as `response.pendra?.worker`.
246
217
  */
247
218
  pendra?: PendraExtension | null;
248
219
  }
@@ -279,8 +250,9 @@ interface ChatCompletionChunk {
279
250
  * Pendra's extension block. A stream carries it on chunks that report on the
280
251
  * request rather than continuing the answer — a {@link PendraNotice} on a
281
252
  * chunk with an empty delta, a {@link PendraWebToolStep} likewise, and
282
- * {@link PendraTiming} on the last chunk before `[DONE]`. Those chunks have
283
- * no text, which is why the streaming examples read content with
253
+ * {@link PendraTiming} and the serving {@link PendraWorker} on the last chunk
254
+ * before `[DONE]` (also readable as `stream.worker` once iterated). Those
255
+ * chunks have no text, which is why the streaming examples read content with
284
256
  * `chunk.choices[0]?.delta?.content` rather than indexing unconditionally.
285
257
  */
286
258
  pendra?: PendraExtension | null;
@@ -370,6 +342,121 @@ interface ChatCompletionCreateParams {
370
342
  worker_id?: string | null;
371
343
  }
372
344
 
345
+ interface TranscriptionSegment {
346
+ id: number;
347
+ start: number;
348
+ end: number;
349
+ text: string;
350
+ }
351
+ interface TranscriptionResponse {
352
+ text: string;
353
+ language?: string;
354
+ duration?: number;
355
+ segments?: TranscriptionSegment[];
356
+ /**
357
+ * Pendra's extension block — `pendra?.worker` names the worker that served
358
+ * the request. Set for every `response_format`, including the plain-text
359
+ * ones. Absent when the API didn't report one.
360
+ */
361
+ pendra?: PendraExtension | null;
362
+ }
363
+ /** Source for the audio bytes. A `File` works in browsers and Node ≥20
364
+ * (where `Blob`/`FormData`/`File` are stable globals — Node 18 only ships
365
+ * these behind `--experimental-fetch` until 18.17, so this package
366
+ * targets Node 20+ for predictable behaviour). For buffers, Node streams,
367
+ * or plain `Blob`s without a filename, prefer the `{ filename, content }`
368
+ * form so the multipart upload carries a filename + extension — the API
369
+ * uses these for format detection and may reject uploads that lack one. */
370
+ type AudioFileInput = Blob | {
371
+ filename: string;
372
+ content: Blob | ArrayBuffer | Uint8Array;
373
+ };
374
+ interface TranscriptionCreateParams {
375
+ file: AudioFileInput;
376
+ model: string;
377
+ language?: string;
378
+ prompt?: string;
379
+ response_format?: "json" | "text" | "srt" | "vtt" | "verbose_json";
380
+ temperature?: number;
381
+ /** Decoding beam width, 1-8. Omit to use the server default (beam search —
382
+ * the highest-accuracy setting). Pass `1` to decode greedily, which is
383
+ * faster but less accurate. */
384
+ beam_size?: number;
385
+ timestamp_granularities?: ("word" | "segment")[];
386
+ /** Pin to a specific worker (sent as the `X-Pendra-Worker-Id` header). */
387
+ worker_id?: string | null;
388
+ }
389
+ interface SpeechCreateParams {
390
+ /** The text-to-speech model to use. */
391
+ model: string;
392
+ /** The text to speak. */
393
+ input: string;
394
+ /** The voice to speak in. Omit to use the model's default voice. */
395
+ voice?: string | null;
396
+ /** The audio format to return. Only `"wav"` is supported, and is the default. */
397
+ response_format?: "wav";
398
+ /** Pin to a specific worker (sent as the `X-Pendra-Worker-Id` header). */
399
+ worker_id?: string | null;
400
+ }
401
+ interface SpeechResponse {
402
+ /** The generated audio file (a complete WAV file, header included). */
403
+ audio: Uint8Array;
404
+ /** The audio format, e.g. `"wav"`. */
405
+ format: string;
406
+ /** Length of the audio in milliseconds, or `null` when the API didn't report it. */
407
+ duration_ms: number | null;
408
+ /**
409
+ * Pendra's extension block — `pendra?.worker` names the worker that served
410
+ * the request. Absent when the API didn't report one.
411
+ */
412
+ pendra?: PendraExtension | null;
413
+ /**
414
+ * The audio as an `ArrayBuffer` (a copy), matching the OpenAI SDK's
415
+ * `speech.arrayBuffer()` so `Buffer.from(await speech.arrayBuffer())` keeps
416
+ * working.
417
+ */
418
+ arrayBuffer(): Promise<ArrayBuffer>;
419
+ }
420
+
421
+ declare class Speech {
422
+ private client;
423
+ constructor(client: Pendra);
424
+ /**
425
+ * Turn text into spoken audio (OpenAI-compatible).
426
+ *
427
+ * @example
428
+ * ```ts
429
+ * import { writeFileSync } from "node:fs";
430
+ *
431
+ * const speech = await client.audio.speech.create({
432
+ * model: "qwen3-tts",
433
+ * input: "Hello from Pendra.",
434
+ * });
435
+ * writeFileSync("speech.wav", speech.audio);
436
+ * ```
437
+ */
438
+ create(params: SpeechCreateParams): Promise<SpeechResponse>;
439
+ }
440
+
441
+ declare class Transcriptions {
442
+ private client;
443
+ constructor(client: Pendra);
444
+ create(params: TranscriptionCreateParams): Promise<TranscriptionResponse>;
445
+ /**
446
+ * Private-inference transcription. There is no multipart upload: the audio
447
+ * bytes ride inside the envelope (sealed under the request's data key) and
448
+ * the request options are the sealed JSON body, POSTed as JSON to the same
449
+ * route.
450
+ */
451
+ private createEncrypted;
452
+ }
453
+
454
+ declare class Audio {
455
+ transcriptions: Transcriptions;
456
+ speech: Speech;
457
+ constructor(client: Pendra);
458
+ }
459
+
373
460
  /**
374
461
  * Async-iterable reader for a streaming chat completion.
375
462
  *
@@ -391,6 +478,10 @@ interface ChatCompletionCreateParams {
391
478
  * stream ends — a `break`, or a frame that throws — aborts the request, so the
392
479
  * connection is released and the worker stops generating tokens nobody will
393
480
  * read (#2216).
481
+ *
482
+ * The worker that served the stream is reported on its trailer chunk, the last
483
+ * one before `[DONE]` — `stream.worker` and `stream.requestId` hold it once
484
+ * that chunk has been iterated.
394
485
  */
395
486
  declare class Stream implements AsyncIterable<ChatCompletionChunk> {
396
487
  private reader;
@@ -398,9 +489,21 @@ declare class Stream implements AsyncIterable<ChatCompletionChunk> {
398
489
  private sse;
399
490
  private done;
400
491
  private controller;
492
+ private placement;
401
493
  private idleTimeoutMs;
402
494
  constructor(response: Response, controller: AbortController, idleTimeoutMs?: number);
403
495
  [Symbol.asyncIterator](): AsyncIterator<ChatCompletionChunk>;
496
+ /**
497
+ * The worker that served this stream, or `null` until the chunk reporting it
498
+ * — the trailer, just before `[DONE]` — has been iterated (and on an API too
499
+ * old to report it). Same as that chunk's `pendra.worker`.
500
+ */
501
+ get worker(): PendraWorker | null;
502
+ /**
503
+ * Pendra's id for this request, reported alongside {@link Stream.worker};
504
+ * `null` until then.
505
+ */
506
+ get requestId(): string | null;
404
507
  abort(): void;
405
508
  }
406
509
 
@@ -446,6 +549,11 @@ interface CreateEmbeddingResponse {
446
549
  data: Embedding[];
447
550
  model: string;
448
551
  usage: EmbeddingUsage;
552
+ /**
553
+ * Pendra's extension block — `pendra?.worker` names the worker that served
554
+ * the request. Absent when the API didn't report one.
555
+ */
556
+ pendra?: PendraExtension | null;
449
557
  }
450
558
 
451
559
  declare class Embeddings {
@@ -486,6 +594,11 @@ interface ImageData {
486
594
  interface ImageResponse {
487
595
  created: number;
488
596
  data: ImageData[];
597
+ /**
598
+ * Pendra's extension block — `pendra?.worker` names the worker that served
599
+ * the request. Absent when the API didn't report one.
600
+ */
601
+ pendra?: PendraExtension | null;
489
602
  }
490
603
 
491
604
  declare class Generations {
@@ -538,6 +651,11 @@ interface RerankResponse {
538
651
  id: string;
539
652
  results: RerankResult[];
540
653
  meta: Record<string, unknown>;
654
+ /**
655
+ * Pendra's extension block — `pendra?.worker` names the worker that served
656
+ * the request. Absent when the API didn't report one.
657
+ */
658
+ pendra?: PendraExtension | null;
541
659
  }
542
660
 
543
661
  declare class Rerank {
@@ -828,4 +946,4 @@ declare class APIStreamError extends APIError {
828
946
  });
829
947
  }
830
948
 
831
- export { APIConnectionError, APIError, APIResponseValidationError, APIStatusError, type APIStatusErrorOptions, APIStreamError, 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 };
949
+ export { APIConnectionError, APIError, APIResponseValidationError, APIStatusError, type APIStatusErrorOptions, APIStreamError, 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, type PendraWorker, PrivateInferenceError, RateLimitError, type RerankCreateParams, type RerankResponse, type RerankResult, type RerankResultDocument, type SpeechCreateParams, type SpeechResponse, Stream, type StreamChoice, type TranscriptionCreateParams, type TranscriptionResponse, type TranscriptionSegment, type Usage, Pendra as default };