pendra 0.10.0 → 0.12.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
@@ -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()`.
@@ -564,4 +702,4 @@ declare class RateLimitError extends APIStatusError {
564
702
  constructor(message?: string);
565
703
  }
566
704
 
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 };
705
+ 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()`.
@@ -564,4 +702,4 @@ declare class RateLimitError extends APIStatusError {
564
702
  constructor(message?: string);
565
703
  }
566
704
 
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 };
705
+ 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);