pendra 0.9.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 +67 -0
- package/dist/index.d.mts +228 -5
- package/dist/index.d.ts +228 -5
- package/dist/index.js +6 -21
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +6 -21
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -51,6 +51,73 @@ for await (const chunk of stream) {
|
|
|
51
51
|
}
|
|
52
52
|
```
|
|
53
53
|
|
|
54
|
+
## Reasoning models
|
|
55
|
+
|
|
56
|
+
A reasoning model's chain-of-thought comes back separately from its answer, on
|
|
57
|
+
`reasoning_content` (mirrored on `reasoning`, and streamed as
|
|
58
|
+
`delta.reasoning_content`). On a hybrid model you can skip the thinking
|
|
59
|
+
entirely and get straight to the answer:
|
|
60
|
+
|
|
61
|
+
```typescript
|
|
62
|
+
const response = await client.chat.completions.create({
|
|
63
|
+
model: 'qwen3.6:27b',
|
|
64
|
+
messages: [{ role: 'user', content: "Classify: 'ship it'. positive or negative?" }],
|
|
65
|
+
max_tokens: 5,
|
|
66
|
+
enable_thinking: false, // or reasoning_effort: 'none'
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
console.log(response.choices[0].message.reasoning_content); // the working, when thinking is on
|
|
70
|
+
console.log(response.choices[0].message.content); // the answer
|
|
71
|
+
```
|
|
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
|
+
|
|
111
|
+
## Parameters
|
|
112
|
+
|
|
113
|
+
`chat.completions.create()` passes everything you give it to the API —
|
|
114
|
+
including fields these types don't declare yet, so a Chat Completions
|
|
115
|
+
parameter newer than your SDK version still reaches the model. TypeScript
|
|
116
|
+
rejects an undeclared key written straight into the call (that's what catches
|
|
117
|
+
typos), so pass a newer one through a variable or a cast when you mean it. The
|
|
118
|
+
only field that isn't sent as JSON is `worker_id`, which travels as the
|
|
119
|
+
`X-Pendra-Worker-Id` routing header.
|
|
120
|
+
|
|
54
121
|
## List Models
|
|
55
122
|
|
|
56
123
|
```typescript
|
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
|
/**
|
|
@@ -67,12 +88,141 @@ interface ChatCompletionMessage {
|
|
|
67
88
|
role: string;
|
|
68
89
|
content: string | null;
|
|
69
90
|
tool_calls?: ChatCompletionMessageToolCall[];
|
|
91
|
+
/**
|
|
92
|
+
* A reasoning model's chain-of-thought, kept separate from the answer in
|
|
93
|
+
* `content`. The API sends it as `reasoning_content` and mirrors it on
|
|
94
|
+
* `reasoning` for wider client compatibility — both are populated here.
|
|
95
|
+
* Turn the thinking off with `enable_thinking: false`.
|
|
96
|
+
*/
|
|
97
|
+
reasoning_content?: string | null;
|
|
98
|
+
/** Mirror of {@link ChatCompletionMessage.reasoning_content}. */
|
|
99
|
+
reasoning?: string | null;
|
|
100
|
+
}
|
|
101
|
+
/** One part of a multimodal message — text, or an image for a vision model. */
|
|
102
|
+
type ChatCompletionContentPart = {
|
|
103
|
+
type: "text";
|
|
104
|
+
text: string;
|
|
105
|
+
} | {
|
|
106
|
+
type: "image_url";
|
|
107
|
+
image_url: {
|
|
108
|
+
url: string;
|
|
109
|
+
detail?: "auto" | "low" | "high";
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
/**
|
|
113
|
+
* A message you send. `content` is a plain string for text, or an array of
|
|
114
|
+
* parts for a vision model. Tool results come back as
|
|
115
|
+
* `{ role: "tool", tool_call_id, content }`.
|
|
116
|
+
*/
|
|
117
|
+
interface ChatCompletionMessageParam {
|
|
118
|
+
role: string;
|
|
119
|
+
content: string | ChatCompletionContentPart[] | null;
|
|
120
|
+
/** Names a participant, e.g. which function a tool/function message is from. */
|
|
121
|
+
name?: string;
|
|
122
|
+
/** On a `"tool"` message, the id of the call this is the result of. */
|
|
123
|
+
tool_call_id?: string;
|
|
124
|
+
/** On an assistant message you replay back, the calls it made. */
|
|
125
|
+
tool_calls?: ChatCompletionMessageToolCall[];
|
|
70
126
|
}
|
|
71
127
|
interface Choice {
|
|
72
128
|
index: number;
|
|
73
129
|
message: ChatCompletionMessage;
|
|
74
130
|
finish_reason: string | null;
|
|
75
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
|
+
}
|
|
76
226
|
interface ChatCompletion {
|
|
77
227
|
id: string;
|
|
78
228
|
object: string;
|
|
@@ -80,11 +230,26 @@ interface ChatCompletion {
|
|
|
80
230
|
model: string;
|
|
81
231
|
choices: Choice[];
|
|
82
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;
|
|
83
241
|
}
|
|
84
242
|
interface ChoiceDelta {
|
|
85
243
|
role?: string | null;
|
|
86
244
|
content?: string | null;
|
|
87
245
|
tool_calls?: ChatCompletionMessageToolCall[];
|
|
246
|
+
/**
|
|
247
|
+
* Streaming chain-of-thought, arriving in its own deltas before the content
|
|
248
|
+
* deltas start. Same both-spellings rule as {@link ChatCompletionMessage}.
|
|
249
|
+
*/
|
|
250
|
+
reasoning_content?: string | null;
|
|
251
|
+
/** Mirror of {@link ChoiceDelta.reasoning_content}. */
|
|
252
|
+
reasoning?: string | null;
|
|
88
253
|
}
|
|
89
254
|
interface StreamChoice {
|
|
90
255
|
index: number;
|
|
@@ -97,13 +262,34 @@ interface ChatCompletionChunk {
|
|
|
97
262
|
created: number;
|
|
98
263
|
model: string;
|
|
99
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;
|
|
100
280
|
}
|
|
281
|
+
/**
|
|
282
|
+
* Parameters for `client.chat.completions.create()`.
|
|
283
|
+
*
|
|
284
|
+
* Every field except `worker_id` (which travels as a header) is sent to the
|
|
285
|
+
* API as you pass it — including keys this interface doesn't declare, so a
|
|
286
|
+
* Chat Completions field newer than your SDK version still reaches the model.
|
|
287
|
+
* TypeScript will reject an undeclared key written directly in the call, which
|
|
288
|
+
* is what catches typos; pass it through a variable or a cast when you mean it.
|
|
289
|
+
*/
|
|
101
290
|
interface ChatCompletionCreateParams {
|
|
102
291
|
model: string;
|
|
103
|
-
messages:
|
|
104
|
-
role: string;
|
|
105
|
-
content: string;
|
|
106
|
-
}>;
|
|
292
|
+
messages: ChatCompletionMessageParam[];
|
|
107
293
|
temperature?: number | null;
|
|
108
294
|
max_tokens?: number | null;
|
|
109
295
|
top_p?: number | null;
|
|
@@ -117,10 +303,16 @@ interface ChatCompletionCreateParams {
|
|
|
117
303
|
presence_penalty?: number | null;
|
|
118
304
|
/** Classic repetition penalty (1.0 = off; e.g. 1.1–1.3 discourages repeats). */
|
|
119
305
|
repeat_penalty?: number | null;
|
|
306
|
+
/** How many recent tokens `repeat_penalty` looks back over (default 64). */
|
|
307
|
+
repeat_last_n?: number | null;
|
|
120
308
|
/** Seed the sampler for reproducible output. */
|
|
121
309
|
seed?: number | null;
|
|
122
310
|
stop?: string | string[] | null;
|
|
123
311
|
stream?: boolean;
|
|
312
|
+
/** Ask for `usage` on the final streamed chunk. */
|
|
313
|
+
stream_options?: {
|
|
314
|
+
include_usage?: boolean;
|
|
315
|
+
} | null;
|
|
124
316
|
/**
|
|
125
317
|
* Functions the model may call, in the OpenAI tools format. When the model
|
|
126
318
|
* calls one, the reply's `choices[0].message.tool_calls` is populated and
|
|
@@ -132,6 +324,37 @@ interface ChatCompletionCreateParams {
|
|
|
132
324
|
tool_choice?: unknown;
|
|
133
325
|
/** Allow the model to request several tool calls in one reply. */
|
|
134
326
|
parallel_tool_calls?: boolean | null;
|
|
327
|
+
/**
|
|
328
|
+
* Constrain the reply's shape — `{ type: "json_object" }` for any JSON, or
|
|
329
|
+
* `{ type: "json_schema", json_schema: { ... } }` to pin it to a schema.
|
|
330
|
+
*/
|
|
331
|
+
response_format?: {
|
|
332
|
+
type: "text" | "json_object" | "json_schema";
|
|
333
|
+
json_schema?: Record<string, unknown>;
|
|
334
|
+
} | null;
|
|
335
|
+
/**
|
|
336
|
+
* Set `false` to make a reasoning model answer directly, skipping its
|
|
337
|
+
* chain-of-thought. Defaults to `true`. Only "hybrid" models can toggle it.
|
|
338
|
+
*/
|
|
339
|
+
enable_thinking?: boolean | null;
|
|
340
|
+
/**
|
|
341
|
+
* How hard a reasoning model should think — `"low"`, `"medium"`, `"high"`,
|
|
342
|
+
* or `"none"` (alias `"minimal"`) to turn thinking off, the same as
|
|
343
|
+
* `enable_thinking: false`.
|
|
344
|
+
*/
|
|
345
|
+
reasoning_effort?: "none" | "minimal" | "low" | "medium" | "high" | (string & {}) | null;
|
|
346
|
+
/** Bias specific tokens, keyed by token id (-100 to 100). */
|
|
347
|
+
logit_bias?: Record<string, number> | null;
|
|
348
|
+
/** Return log-probabilities for the chosen tokens (model permitting). */
|
|
349
|
+
logprobs?: boolean | null;
|
|
350
|
+
/** How many alternatives to report per position when `logprobs` is on. */
|
|
351
|
+
top_logprobs?: number | null;
|
|
352
|
+
/** OpenAI's newer spelling of `max_tokens`. */
|
|
353
|
+
max_completion_tokens?: number | null;
|
|
354
|
+
/** How many completions to generate. */
|
|
355
|
+
n?: number | null;
|
|
356
|
+
/** An opaque end-user id, passed through for your own attribution. */
|
|
357
|
+
user?: string | null;
|
|
135
358
|
/**
|
|
136
359
|
* Optionally pin the request to a specific worker that serves this model.
|
|
137
360
|
* Sent as the `X-Pendra-Worker-Id` header; when omitted, the least-busy
|
|
@@ -479,4 +702,4 @@ declare class RateLimitError extends APIStatusError {
|
|
|
479
702
|
constructor(message?: string);
|
|
480
703
|
}
|
|
481
704
|
|
|
482
|
-
export { APIConnectionError, APIError, APIStatusError, type AudioFileInput, AuthenticationError, type ChatCompletion, type ChatCompletionChunk, type ChatCompletionCreateParams, type ChatCompletionMessage, 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
|
/**
|
|
@@ -67,12 +88,141 @@ interface ChatCompletionMessage {
|
|
|
67
88
|
role: string;
|
|
68
89
|
content: string | null;
|
|
69
90
|
tool_calls?: ChatCompletionMessageToolCall[];
|
|
91
|
+
/**
|
|
92
|
+
* A reasoning model's chain-of-thought, kept separate from the answer in
|
|
93
|
+
* `content`. The API sends it as `reasoning_content` and mirrors it on
|
|
94
|
+
* `reasoning` for wider client compatibility — both are populated here.
|
|
95
|
+
* Turn the thinking off with `enable_thinking: false`.
|
|
96
|
+
*/
|
|
97
|
+
reasoning_content?: string | null;
|
|
98
|
+
/** Mirror of {@link ChatCompletionMessage.reasoning_content}. */
|
|
99
|
+
reasoning?: string | null;
|
|
100
|
+
}
|
|
101
|
+
/** One part of a multimodal message — text, or an image for a vision model. */
|
|
102
|
+
type ChatCompletionContentPart = {
|
|
103
|
+
type: "text";
|
|
104
|
+
text: string;
|
|
105
|
+
} | {
|
|
106
|
+
type: "image_url";
|
|
107
|
+
image_url: {
|
|
108
|
+
url: string;
|
|
109
|
+
detail?: "auto" | "low" | "high";
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
/**
|
|
113
|
+
* A message you send. `content` is a plain string for text, or an array of
|
|
114
|
+
* parts for a vision model. Tool results come back as
|
|
115
|
+
* `{ role: "tool", tool_call_id, content }`.
|
|
116
|
+
*/
|
|
117
|
+
interface ChatCompletionMessageParam {
|
|
118
|
+
role: string;
|
|
119
|
+
content: string | ChatCompletionContentPart[] | null;
|
|
120
|
+
/** Names a participant, e.g. which function a tool/function message is from. */
|
|
121
|
+
name?: string;
|
|
122
|
+
/** On a `"tool"` message, the id of the call this is the result of. */
|
|
123
|
+
tool_call_id?: string;
|
|
124
|
+
/** On an assistant message you replay back, the calls it made. */
|
|
125
|
+
tool_calls?: ChatCompletionMessageToolCall[];
|
|
70
126
|
}
|
|
71
127
|
interface Choice {
|
|
72
128
|
index: number;
|
|
73
129
|
message: ChatCompletionMessage;
|
|
74
130
|
finish_reason: string | null;
|
|
75
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
|
+
}
|
|
76
226
|
interface ChatCompletion {
|
|
77
227
|
id: string;
|
|
78
228
|
object: string;
|
|
@@ -80,11 +230,26 @@ interface ChatCompletion {
|
|
|
80
230
|
model: string;
|
|
81
231
|
choices: Choice[];
|
|
82
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;
|
|
83
241
|
}
|
|
84
242
|
interface ChoiceDelta {
|
|
85
243
|
role?: string | null;
|
|
86
244
|
content?: string | null;
|
|
87
245
|
tool_calls?: ChatCompletionMessageToolCall[];
|
|
246
|
+
/**
|
|
247
|
+
* Streaming chain-of-thought, arriving in its own deltas before the content
|
|
248
|
+
* deltas start. Same both-spellings rule as {@link ChatCompletionMessage}.
|
|
249
|
+
*/
|
|
250
|
+
reasoning_content?: string | null;
|
|
251
|
+
/** Mirror of {@link ChoiceDelta.reasoning_content}. */
|
|
252
|
+
reasoning?: string | null;
|
|
88
253
|
}
|
|
89
254
|
interface StreamChoice {
|
|
90
255
|
index: number;
|
|
@@ -97,13 +262,34 @@ interface ChatCompletionChunk {
|
|
|
97
262
|
created: number;
|
|
98
263
|
model: string;
|
|
99
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;
|
|
100
280
|
}
|
|
281
|
+
/**
|
|
282
|
+
* Parameters for `client.chat.completions.create()`.
|
|
283
|
+
*
|
|
284
|
+
* Every field except `worker_id` (which travels as a header) is sent to the
|
|
285
|
+
* API as you pass it — including keys this interface doesn't declare, so a
|
|
286
|
+
* Chat Completions field newer than your SDK version still reaches the model.
|
|
287
|
+
* TypeScript will reject an undeclared key written directly in the call, which
|
|
288
|
+
* is what catches typos; pass it through a variable or a cast when you mean it.
|
|
289
|
+
*/
|
|
101
290
|
interface ChatCompletionCreateParams {
|
|
102
291
|
model: string;
|
|
103
|
-
messages:
|
|
104
|
-
role: string;
|
|
105
|
-
content: string;
|
|
106
|
-
}>;
|
|
292
|
+
messages: ChatCompletionMessageParam[];
|
|
107
293
|
temperature?: number | null;
|
|
108
294
|
max_tokens?: number | null;
|
|
109
295
|
top_p?: number | null;
|
|
@@ -117,10 +303,16 @@ interface ChatCompletionCreateParams {
|
|
|
117
303
|
presence_penalty?: number | null;
|
|
118
304
|
/** Classic repetition penalty (1.0 = off; e.g. 1.1–1.3 discourages repeats). */
|
|
119
305
|
repeat_penalty?: number | null;
|
|
306
|
+
/** How many recent tokens `repeat_penalty` looks back over (default 64). */
|
|
307
|
+
repeat_last_n?: number | null;
|
|
120
308
|
/** Seed the sampler for reproducible output. */
|
|
121
309
|
seed?: number | null;
|
|
122
310
|
stop?: string | string[] | null;
|
|
123
311
|
stream?: boolean;
|
|
312
|
+
/** Ask for `usage` on the final streamed chunk. */
|
|
313
|
+
stream_options?: {
|
|
314
|
+
include_usage?: boolean;
|
|
315
|
+
} | null;
|
|
124
316
|
/**
|
|
125
317
|
* Functions the model may call, in the OpenAI tools format. When the model
|
|
126
318
|
* calls one, the reply's `choices[0].message.tool_calls` is populated and
|
|
@@ -132,6 +324,37 @@ interface ChatCompletionCreateParams {
|
|
|
132
324
|
tool_choice?: unknown;
|
|
133
325
|
/** Allow the model to request several tool calls in one reply. */
|
|
134
326
|
parallel_tool_calls?: boolean | null;
|
|
327
|
+
/**
|
|
328
|
+
* Constrain the reply's shape — `{ type: "json_object" }` for any JSON, or
|
|
329
|
+
* `{ type: "json_schema", json_schema: { ... } }` to pin it to a schema.
|
|
330
|
+
*/
|
|
331
|
+
response_format?: {
|
|
332
|
+
type: "text" | "json_object" | "json_schema";
|
|
333
|
+
json_schema?: Record<string, unknown>;
|
|
334
|
+
} | null;
|
|
335
|
+
/**
|
|
336
|
+
* Set `false` to make a reasoning model answer directly, skipping its
|
|
337
|
+
* chain-of-thought. Defaults to `true`. Only "hybrid" models can toggle it.
|
|
338
|
+
*/
|
|
339
|
+
enable_thinking?: boolean | null;
|
|
340
|
+
/**
|
|
341
|
+
* How hard a reasoning model should think — `"low"`, `"medium"`, `"high"`,
|
|
342
|
+
* or `"none"` (alias `"minimal"`) to turn thinking off, the same as
|
|
343
|
+
* `enable_thinking: false`.
|
|
344
|
+
*/
|
|
345
|
+
reasoning_effort?: "none" | "minimal" | "low" | "medium" | "high" | (string & {}) | null;
|
|
346
|
+
/** Bias specific tokens, keyed by token id (-100 to 100). */
|
|
347
|
+
logit_bias?: Record<string, number> | null;
|
|
348
|
+
/** Return log-probabilities for the chosen tokens (model permitting). */
|
|
349
|
+
logprobs?: boolean | null;
|
|
350
|
+
/** How many alternatives to report per position when `logprobs` is on. */
|
|
351
|
+
top_logprobs?: number | null;
|
|
352
|
+
/** OpenAI's newer spelling of `max_tokens`. */
|
|
353
|
+
max_completion_tokens?: number | null;
|
|
354
|
+
/** How many completions to generate. */
|
|
355
|
+
n?: number | null;
|
|
356
|
+
/** An opaque end-user id, passed through for your own attribution. */
|
|
357
|
+
user?: string | null;
|
|
135
358
|
/**
|
|
136
359
|
* Optionally pin the request to a specific worker that serves this model.
|
|
137
360
|
* Sent as the `X-Pendra-Worker-Id` header; when omitted, the least-busy
|
|
@@ -479,4 +702,4 @@ declare class RateLimitError extends APIStatusError {
|
|
|
479
702
|
constructor(message?: string);
|
|
480
703
|
}
|
|
481
704
|
|
|
482
|
-
export { APIConnectionError, APIError, APIStatusError, type AudioFileInput, AuthenticationError, type ChatCompletion, type ChatCompletionChunk, type ChatCompletionCreateParams, type ChatCompletionMessage, 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 };
|