@runinfra/sdk 0.2.0 → 0.3.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/CHANGELOG.md +130 -0
- package/README.md +233 -5
- package/dist/index.d.ts +475 -9
- package/dist/index.js +787 -91
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,28 +1,70 @@
|
|
|
1
|
-
export declare const RUNINFRA_SDK_VERSION = "0.2
|
|
1
|
+
export declare const RUNINFRA_SDK_VERSION = "0.3.2";
|
|
2
2
|
export interface RunInfraOptions {
|
|
3
3
|
apiKey: string;
|
|
4
4
|
pipelineId?: string;
|
|
5
5
|
baseURL?: string;
|
|
6
|
+
/**
|
|
7
|
+
* The timeout of every call, in milliseconds. Left out, a non-streamed call
|
|
8
|
+
* is given 750 seconds, and a streamed call 190 seconds to its response
|
|
9
|
+
* headers and to each later read. The `fetch` in use has its own limits:
|
|
10
|
+
* Node's built-in `fetch` waits at most 300 seconds for the response
|
|
11
|
+
* headers, whatever this says.
|
|
12
|
+
*/
|
|
6
13
|
timeoutMs?: number;
|
|
7
14
|
maxRetries?: number;
|
|
8
15
|
retryBaseMs?: number;
|
|
16
|
+
/**
|
|
17
|
+
* The `fetch` every call is sent with. Defaults to the runtime's own. Pass
|
|
18
|
+
* one whose own time limits allow more when a non-streamed call must wait
|
|
19
|
+
* longer for its response headers than the runtime's `fetch` does.
|
|
20
|
+
*/
|
|
9
21
|
fetch?: typeof fetch;
|
|
10
22
|
dangerouslyAllowBrowser?: boolean;
|
|
11
23
|
}
|
|
12
24
|
export interface RunInfraRequestOptions {
|
|
13
25
|
clientRequestId?: string;
|
|
14
26
|
idempotencyKey?: string;
|
|
27
|
+
/** The timeout of this call, in milliseconds. It wins over the client's `timeoutMs` and over the defaults. */
|
|
15
28
|
timeoutMs?: number;
|
|
16
29
|
maxRetries?: number;
|
|
17
30
|
retryBaseMs?: number;
|
|
18
31
|
headers?: Record<string, string>;
|
|
19
32
|
extraBody?: Record<string, unknown>;
|
|
20
33
|
}
|
|
34
|
+
/** One call the model asks for, on an assistant message's `tool_calls`. */
|
|
35
|
+
export interface ChatCompletionMessageToolCall {
|
|
36
|
+
/** The call's id. The `tool` message that answers the call repeats it as `tool_call_id`. */
|
|
37
|
+
id: string;
|
|
38
|
+
type: "function";
|
|
39
|
+
function: {
|
|
40
|
+
name: string;
|
|
41
|
+
/** The arguments as a JSON string. Parse and check them before you run the tool. */
|
|
42
|
+
arguments: string;
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* One message of a chat. `system`, `developer` and `user` messages carry
|
|
47
|
+
* `content`. An `assistant` message carries `content`, a non-empty
|
|
48
|
+
* `tool_calls`, or both. A `tool` message carries `content` and the
|
|
49
|
+
* `tool_call_id` of the call it answers; `ChatToolMessage` types that one.
|
|
50
|
+
*/
|
|
21
51
|
export interface ChatMessage {
|
|
22
|
-
role: "system" | "user" | "assistant" | "tool" | string;
|
|
23
|
-
|
|
52
|
+
role: "system" | "developer" | "user" | "assistant" | "tool" | string;
|
|
53
|
+
/** `null` or left out on an assistant message that carries only `tool_calls`. */
|
|
54
|
+
content?: string | Array<Record<string, unknown>> | null;
|
|
24
55
|
name?: string;
|
|
56
|
+
/** On a `tool` message: the `id` of the call this message answers. */
|
|
25
57
|
tool_call_id?: string;
|
|
58
|
+
/** On an `assistant` message: the calls the model asked for. */
|
|
59
|
+
tool_calls?: ChatCompletionMessageToolCall[];
|
|
60
|
+
/** On an answered `assistant` message: the model's thinking, when the model reports it. */
|
|
61
|
+
reasoning?: string | null;
|
|
62
|
+
}
|
|
63
|
+
/** The message that answers one tool call: the result as `content`, and the call's id. */
|
|
64
|
+
export interface ChatToolMessage extends ChatMessage {
|
|
65
|
+
role: "tool";
|
|
66
|
+
content: string | Array<Record<string, unknown>>;
|
|
67
|
+
tool_call_id: string;
|
|
26
68
|
}
|
|
27
69
|
export interface ChatCompletionRequest {
|
|
28
70
|
model: string;
|
|
@@ -46,12 +88,66 @@ export interface ChatCompletionRequest {
|
|
|
46
88
|
seed?: number;
|
|
47
89
|
logprobs?: boolean;
|
|
48
90
|
top_logprobs?: number;
|
|
91
|
+
/** `-1` or `0` turns it off. */
|
|
92
|
+
top_k?: number;
|
|
93
|
+
min_p?: number;
|
|
94
|
+
repetition_penalty?: number;
|
|
95
|
+
/** How many choices to generate. */
|
|
96
|
+
n?: number;
|
|
97
|
+
best_of?: number;
|
|
98
|
+
logit_bias?: Record<string, number>;
|
|
99
|
+
/** `false` asks for one tool call at a time. Whether it is honored depends on the model. */
|
|
100
|
+
parallel_tool_calls?: boolean;
|
|
101
|
+
/** How much the model reasons, such as `"none"`, `"low"` or `"high"`. The accepted values depend on the model. */
|
|
102
|
+
reasoning_effort?: string;
|
|
103
|
+
/** The reasoning object some routers send. Do not send it beside a `reasoning_effort` that disagrees. */
|
|
104
|
+
reasoning?: {
|
|
105
|
+
effort?: string;
|
|
106
|
+
enabled?: boolean;
|
|
107
|
+
exclude?: boolean;
|
|
108
|
+
} & Record<string, unknown>;
|
|
109
|
+
/** `false` hides the model's reasoning from the answer. */
|
|
110
|
+
include_reasoning?: boolean;
|
|
111
|
+
/** A cache-affinity hint for requests that share a prompt prefix. */
|
|
112
|
+
prompt_cache_key?: string;
|
|
113
|
+
service_tier?: string;
|
|
114
|
+
store?: boolean;
|
|
115
|
+
safety_identifier?: string;
|
|
116
|
+
modalities?: string[];
|
|
117
|
+
audio?: Record<string, unknown>;
|
|
118
|
+
prediction?: Record<string, unknown>;
|
|
119
|
+
verbosity?: string;
|
|
120
|
+
web_search_options?: Record<string, unknown>;
|
|
121
|
+
moderation?: unknown;
|
|
122
|
+
/** The older spelling of `tools`. Prefer `tools`. */
|
|
123
|
+
functions?: Array<Record<string, unknown>>;
|
|
124
|
+
/** The older spelling of `tool_choice`. Prefer `tool_choice`. */
|
|
125
|
+
function_call?: string | Record<string, unknown>;
|
|
126
|
+
}
|
|
127
|
+
/** One piece of a tool call on a stream. Pieces of the same call share `index`; join their `arguments`. */
|
|
128
|
+
export interface ChatCompletionStreamToolCallDelta {
|
|
129
|
+
index: number;
|
|
130
|
+
/** On the first piece of a call. */
|
|
131
|
+
id?: string;
|
|
132
|
+
type?: "function";
|
|
133
|
+
function?: {
|
|
134
|
+
/** On the first piece of a call. */
|
|
135
|
+
name?: string;
|
|
136
|
+
/** The next piece of the arguments' JSON string. */
|
|
137
|
+
arguments?: string;
|
|
138
|
+
};
|
|
49
139
|
}
|
|
50
140
|
export interface ChatCompletionStreamEvent extends Record<string, unknown> {
|
|
51
141
|
choices?: Array<{
|
|
142
|
+
index?: number;
|
|
52
143
|
delta?: {
|
|
53
|
-
|
|
144
|
+
role?: string;
|
|
145
|
+
content?: string | null;
|
|
146
|
+
/** The next piece of the model's thinking, when the model reports it. */
|
|
147
|
+
reasoning?: string | null;
|
|
148
|
+
tool_calls?: ChatCompletionStreamToolCallDelta[];
|
|
54
149
|
} & Record<string, unknown>;
|
|
150
|
+
finish_reason?: string | null;
|
|
55
151
|
} & Record<string, unknown>>;
|
|
56
152
|
}
|
|
57
153
|
export interface RunInfraRequestMetadata extends Record<string, unknown> {
|
|
@@ -212,6 +308,219 @@ export interface ModelListResponse extends RunInfraRequestMetadata {
|
|
|
212
308
|
object?: string;
|
|
213
309
|
data: ModelObject[];
|
|
214
310
|
}
|
|
311
|
+
/**
|
|
312
|
+
* The state of a batch job. A job starts in `validating` while its input file
|
|
313
|
+
* is read, then moves by itself through `checked` and `queued` to `running`.
|
|
314
|
+
* `completed`, `expired`, `cancelled`, and `failed` are final.
|
|
315
|
+
*/
|
|
316
|
+
export type BatchState = "validating" | "checked" | "queued" | "running" | "paused" | "cancelling" | "completed" | "expired" | "cancelled" | "failed";
|
|
317
|
+
/** Why a paused job waits. Set exactly when `batch_state` is `paused`. */
|
|
318
|
+
export type BatchPauseReason = "funds" | "destination" | "source" | "key_limit" | "daily_room";
|
|
319
|
+
/** Why a job ended. `null` while the job is open. */
|
|
320
|
+
export type BatchEndReason = "all_done" | "max_cost_reached" | "cancel_asked" | "key_revoked" | "account_deleted" | "window_ended" | "model_withdrawn" | "not_flex" | "not_started" | "check_failed";
|
|
321
|
+
/** Why a job's input file was refused. Set only when `end_reason` is `check_failed`. */
|
|
322
|
+
export type BatchCheckError = "url_not_public" | "link_expires_too_soon" | "file_too_large" | "link_changed" | "link_not_supported";
|
|
323
|
+
/** A notice about a job: data only. */
|
|
324
|
+
export type BatchNotice = "batch_ended" | "batch_paused" | "batch_expires_soon";
|
|
325
|
+
/** Why a line of the input file was refused when the file was read. */
|
|
326
|
+
export type BatchLineCheckCode = "invalid_json" | "line_too_large" | "invalid_request" | "media_not_supported" | "prompt_too_large";
|
|
327
|
+
/** The code of a line that failed after its job started, as an error delivery carries it. */
|
|
328
|
+
export type BatchDeliveryErrorCode = "invalid_request" | "prompt_too_large" | "model_error" | "link_changed";
|
|
329
|
+
/** Why batch is not available, on a `flex_not_available` refusal (`error.reason`). */
|
|
330
|
+
export type BatchUnavailableReason = "model" | "partner" | "price";
|
|
331
|
+
/**
|
|
332
|
+
* The refusal codes a caller of the batch routes can receive, as
|
|
333
|
+
* `RunInfraError.code` carries them. Codes every route can answer
|
|
334
|
+
* (`invalid_api_key` on 401, `rate_limit_exceeded` on 429) are not repeated
|
|
335
|
+
* here.
|
|
336
|
+
*/
|
|
337
|
+
export type BatchRefusalCode = "batch_not_open" | "invalid_request" | "not_found" | "model_not_sold" | "flex_not_available" | "url_not_public" | "link_expires_too_soon" | "destination_unreachable" | "needs_funds" | "key_spend_limit_reached" | "batch_ended" | "batches_scope_violation";
|
|
338
|
+
/** Where a job's answers go. A webhook address is the only destination. */
|
|
339
|
+
export interface BatchDestination {
|
|
340
|
+
type: "webhook";
|
|
341
|
+
/** A public HTTPS address on port 443, at most 8,192 bytes. */
|
|
342
|
+
url: string;
|
|
343
|
+
}
|
|
344
|
+
export interface BatchCreateRequest {
|
|
345
|
+
/** A model that offers batch. */
|
|
346
|
+
model: string;
|
|
347
|
+
/**
|
|
348
|
+
* A public HTTPS link (port 443, at most 8,192 bytes) to a JSONL file of at
|
|
349
|
+
* most 50 MiB whose host serves byte ranges. A signed link must stay valid
|
|
350
|
+
* until the job's window ends.
|
|
351
|
+
*/
|
|
352
|
+
input_url: string;
|
|
353
|
+
destination: BatchDestination;
|
|
354
|
+
/** The most the job may cost, in cents: a whole number from 1 to 100,000,000. */
|
|
355
|
+
max_cost_cents: number;
|
|
356
|
+
/** The job's window in hours. 24 is the only value, and the default. */
|
|
357
|
+
window_hours?: 24;
|
|
358
|
+
/** A label of at most 64 characters. */
|
|
359
|
+
name?: string;
|
|
360
|
+
}
|
|
361
|
+
export interface BatchListParams {
|
|
362
|
+
/** Page size, from 1 to 50. The gateway's default is 20. */
|
|
363
|
+
limit?: number;
|
|
364
|
+
/** The `next_cursor` of the page before. */
|
|
365
|
+
cursor?: string;
|
|
366
|
+
state?: BatchState;
|
|
367
|
+
/** A model slug. */
|
|
368
|
+
model?: string;
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* A batch job, as every batch route answers it. `failed` never includes an
|
|
372
|
+
* undelivered line, and once a job has ended the counts `succeeded`,
|
|
373
|
+
* `failed`, `expired`, `cancelled`, `undelivered`, and `lines_invalid` add up
|
|
374
|
+
* to `lines_total`.
|
|
375
|
+
*/
|
|
376
|
+
export interface BatchJob {
|
|
377
|
+
id: string;
|
|
378
|
+
/** `null` when the model is no longer listed. */
|
|
379
|
+
model_slug: string | null;
|
|
380
|
+
batch_state: BatchState;
|
|
381
|
+
pause_reason: BatchPauseReason | null;
|
|
382
|
+
/** Who started the job: an API key, or a person in the dashboard. Never a name. */
|
|
383
|
+
made_by: {
|
|
384
|
+
kind: "person" | "key";
|
|
385
|
+
};
|
|
386
|
+
/** Every line read from the file, the invalid ones included. */
|
|
387
|
+
lines_total: number;
|
|
388
|
+
lines_invalid: number;
|
|
389
|
+
succeeded: number;
|
|
390
|
+
failed: number;
|
|
391
|
+
/** Lines the job had not run when its window ended. They are not charged. */
|
|
392
|
+
expired: number;
|
|
393
|
+
cancelled: number;
|
|
394
|
+
/**
|
|
395
|
+
* Answered lines the address did not acknowledge with a 2xx in time. They
|
|
396
|
+
* are not charged and are not sent again.
|
|
397
|
+
*/
|
|
398
|
+
undelivered: number;
|
|
399
|
+
/** What the job's lines were charged so far, in microcents (millionths of a cent). */
|
|
400
|
+
cost_microcents: number;
|
|
401
|
+
max_cost_cents: number | null;
|
|
402
|
+
/** ISO 8601 UTC with milliseconds. */
|
|
403
|
+
created_at: string;
|
|
404
|
+
started_at: string | null;
|
|
405
|
+
/** The end of the job's window. */
|
|
406
|
+
expires_at: string;
|
|
407
|
+
finished_at: string | null;
|
|
408
|
+
destination_type: "webhook" | null;
|
|
409
|
+
notice: BatchNotice | null;
|
|
410
|
+
/** The API key the job runs as. */
|
|
411
|
+
key_id: string | null;
|
|
412
|
+
end_reason: BatchEndReason | null;
|
|
413
|
+
check_error: BatchCheckError | null;
|
|
414
|
+
name: string | null;
|
|
415
|
+
}
|
|
416
|
+
/** The lines one check code refused: how many, and the first line numbers (1-based, at most five). */
|
|
417
|
+
export interface BatchLineCheckErrors {
|
|
418
|
+
code: BatchLineCheckCode;
|
|
419
|
+
count: number;
|
|
420
|
+
first_lines: number[];
|
|
421
|
+
}
|
|
422
|
+
/** The gateway's estimate of the most a job's lines can cost. */
|
|
423
|
+
export interface BatchQuote {
|
|
424
|
+
input_cost_cents: number;
|
|
425
|
+
output_cost_ceiling_cents: number;
|
|
426
|
+
/** `input_cost_cents` plus `output_cost_ceiling_cents`. */
|
|
427
|
+
most_cents: number;
|
|
428
|
+
flex_input_cents_per_million: number;
|
|
429
|
+
flex_output_cents_per_million: number;
|
|
430
|
+
est_input_tokens: number;
|
|
431
|
+
/** An estimate, never a promise. */
|
|
432
|
+
can_finish_in_window: boolean;
|
|
433
|
+
covered_until_after: string | null;
|
|
434
|
+
}
|
|
435
|
+
/** A job as `batches.retrieve()` answers it: the job, the lines its check refused, and its quote. */
|
|
436
|
+
export interface BatchJobDetail extends BatchJob {
|
|
437
|
+
errors: BatchLineCheckErrors[];
|
|
438
|
+
/** `null` while the file is still read, once the job has ended, and when no quote can be made now. */
|
|
439
|
+
quote: BatchQuote | null;
|
|
440
|
+
}
|
|
441
|
+
export interface BatchCreateResponse extends RunInfraRequestMetadata {
|
|
442
|
+
batch: BatchJob;
|
|
443
|
+
}
|
|
444
|
+
export interface BatchRetrieveResponse extends RunInfraRequestMetadata {
|
|
445
|
+
batch: BatchJobDetail;
|
|
446
|
+
}
|
|
447
|
+
export interface BatchListResponse extends RunInfraRequestMetadata {
|
|
448
|
+
/** Newest first. */
|
|
449
|
+
batches: BatchJob[];
|
|
450
|
+
/** Pass it as `cursor` for the next page. `null` on the last page. */
|
|
451
|
+
next_cursor: string | null;
|
|
452
|
+
}
|
|
453
|
+
export interface BatchCancelResponse extends RunInfraRequestMetadata {
|
|
454
|
+
batch_id: string;
|
|
455
|
+
/** `cancelled` when no line had run; `cancelling` while lines in flight settle. */
|
|
456
|
+
batch_state: "cancelling" | "cancelled";
|
|
457
|
+
}
|
|
458
|
+
export interface BatchDeliveryUsage {
|
|
459
|
+
prompt_tokens: number;
|
|
460
|
+
completion_tokens: number;
|
|
461
|
+
total_tokens: number;
|
|
462
|
+
}
|
|
463
|
+
export interface BatchDeliveryCost {
|
|
464
|
+
/** What the line cost, in microcents (millionths of a cent). */
|
|
465
|
+
microcents: number;
|
|
466
|
+
}
|
|
467
|
+
/**
|
|
468
|
+
* The test delivery a `batches.create()` call sends to the destination before
|
|
469
|
+
* it answers. The address must reply 2xx with a body that CONTAINS `value`.
|
|
470
|
+
*/
|
|
471
|
+
export interface BatchTestDelivery {
|
|
472
|
+
id: string;
|
|
473
|
+
test: true;
|
|
474
|
+
value: string;
|
|
475
|
+
}
|
|
476
|
+
/** One answered line. `id` is the same for the same line and attempt. Key your own writes on it. */
|
|
477
|
+
export interface BatchAnswerDelivery {
|
|
478
|
+
id: string;
|
|
479
|
+
batch_id: string;
|
|
480
|
+
custom_id: string;
|
|
481
|
+
/** The line's 1-based number in the input file. */
|
|
482
|
+
line: number;
|
|
483
|
+
attempt: number;
|
|
484
|
+
test: false;
|
|
485
|
+
/** The chat completion object. */
|
|
486
|
+
response: Record<string, unknown>;
|
|
487
|
+
error?: undefined;
|
|
488
|
+
usage: BatchDeliveryUsage | null;
|
|
489
|
+
cost: BatchDeliveryCost | null;
|
|
490
|
+
}
|
|
491
|
+
/** One line that failed after its job started. It carries no usage and no cost. */
|
|
492
|
+
export interface BatchErrorDelivery {
|
|
493
|
+
id: string;
|
|
494
|
+
batch_id: string;
|
|
495
|
+
/** `null` when the file changed after it was checked (`link_changed`); `line` names the line then. */
|
|
496
|
+
custom_id: string | null;
|
|
497
|
+
line: number;
|
|
498
|
+
attempt: number;
|
|
499
|
+
test: false;
|
|
500
|
+
error: {
|
|
501
|
+
code: BatchDeliveryErrorCode;
|
|
502
|
+
};
|
|
503
|
+
response?: undefined;
|
|
504
|
+
usage: null;
|
|
505
|
+
cost: null;
|
|
506
|
+
}
|
|
507
|
+
export type BatchDelivery = BatchTestDelivery | BatchAnswerDelivery | BatchErrorDelivery;
|
|
508
|
+
export interface VerifyBatchDeliveryOptions {
|
|
509
|
+
/** The RAW request body exactly as it arrived: a string or bytes, never a re-serialized object. */
|
|
510
|
+
payload: string | Uint8Array | ArrayBuffer;
|
|
511
|
+
/** The request's headers, in any case: a `Headers` object or a plain object such as Node's `req.headers`. */
|
|
512
|
+
headers: Headers | Record<string, string | string[] | undefined>;
|
|
513
|
+
/** The workspace's batch signing secret as the dashboard shows it: `whsec_` followed by base64. */
|
|
514
|
+
secret: string;
|
|
515
|
+
/**
|
|
516
|
+
* The most the delivery's timestamp may differ from the clock, in seconds.
|
|
517
|
+
* 300 by default, so a captured delivery cannot be replayed later. A number
|
|
518
|
+
* sets another tolerance; `null` turns the check off.
|
|
519
|
+
*/
|
|
520
|
+
toleranceSeconds?: number | null;
|
|
521
|
+
/** The clock the timestamp is compared with, in Unix seconds. Defaults to now. */
|
|
522
|
+
now?: number;
|
|
523
|
+
}
|
|
215
524
|
export interface ConstructWebhookEventOptions {
|
|
216
525
|
payload: string | Uint8Array | ArrayBuffer;
|
|
217
526
|
signatureHeader: string;
|
|
@@ -223,9 +532,32 @@ export declare class RunInfraError extends Error {
|
|
|
223
532
|
readonly status: number;
|
|
224
533
|
readonly type: string;
|
|
225
534
|
readonly requestId?: string;
|
|
535
|
+
/**
|
|
536
|
+
* The wait the API named with the error, in milliseconds: `Retry-After-Ms`
|
|
537
|
+
* when the response carries it, else `Retry-After`. Set on every error whose
|
|
538
|
+
* response named a wait, whatever its status.
|
|
539
|
+
*/
|
|
226
540
|
readonly retryAfterMs?: number;
|
|
227
541
|
readonly code?: string;
|
|
228
542
|
readonly param?: string;
|
|
543
|
+
/**
|
|
544
|
+
* The closed cause word of a batch route's refusal, when its error body
|
|
545
|
+
* names one (`error.reason`): `model`, `partner`, or `price` on
|
|
546
|
+
* `flex_not_available`. Other routes do not set it.
|
|
547
|
+
*/
|
|
548
|
+
readonly reason?: string;
|
|
549
|
+
/**
|
|
550
|
+
* What the API said about asking again, when it said it: `x-should-retry` on
|
|
551
|
+
* the response, or `retryable` inside the error object. `false` means the
|
|
552
|
+
* same request will fail again. Left unset when the API said nothing.
|
|
553
|
+
*/
|
|
554
|
+
readonly retryable?: boolean;
|
|
555
|
+
/**
|
|
556
|
+
* The `X-Client-Request-Id` the SDK sent with the call, set on a timeout.
|
|
557
|
+
* A call that timed out before any response has no server request id, so
|
|
558
|
+
* this is the id to quote to support.
|
|
559
|
+
*/
|
|
560
|
+
readonly clientRequestId?: string;
|
|
229
561
|
constructor(message: string, input: {
|
|
230
562
|
status: number;
|
|
231
563
|
type: string;
|
|
@@ -233,6 +565,9 @@ export declare class RunInfraError extends Error {
|
|
|
233
565
|
retryAfterMs?: number;
|
|
234
566
|
code?: string;
|
|
235
567
|
param?: string;
|
|
568
|
+
reason?: string;
|
|
569
|
+
retryable?: boolean;
|
|
570
|
+
clientRequestId?: string;
|
|
236
571
|
});
|
|
237
572
|
}
|
|
238
573
|
export declare class AuthenticationError extends RunInfraError {
|
|
@@ -244,6 +579,12 @@ export declare class PermissionDeniedError extends RunInfraError {
|
|
|
244
579
|
export declare class RateLimitError extends RunInfraError {
|
|
245
580
|
constructor(message: string, status: number, requestId?: string, retryAfterMs?: number, code?: string, param?: string);
|
|
246
581
|
}
|
|
582
|
+
/**
|
|
583
|
+
* A `402` from the gateway. On a batch route, read `code` to tell
|
|
584
|
+
* `needs_funds` (the account has never added funds) from
|
|
585
|
+
* `key_spend_limit_reached` (this API key reached its own monthly limit;
|
|
586
|
+
* raise the key's limit or use another key).
|
|
587
|
+
*/
|
|
247
588
|
export declare class InsufficientCreditsError extends RunInfraError {
|
|
248
589
|
/** Remaining workspace balance in cents, when the gateway reports it. */
|
|
249
590
|
readonly currentBalanceCents?: number;
|
|
@@ -263,8 +604,15 @@ export declare class DeploymentError extends RunInfraError {
|
|
|
263
604
|
export declare class ModelNotFoundError extends RunInfraError {
|
|
264
605
|
constructor(message: string, status: number, requestId?: string, code?: string, param?: string);
|
|
265
606
|
}
|
|
607
|
+
/**
|
|
608
|
+
* A call that ran out of time: the SDK's own timeout, or the runtime's `fetch`
|
|
609
|
+
* giving up on the response headers or the body by its own clock.
|
|
610
|
+
* `clientRequestId` holds the `X-Client-Request-Id` the SDK sent with the
|
|
611
|
+
* call; `requestId` is set only when a response had begun. A call is never
|
|
612
|
+
* sent again after a timeout: the API may still be working on it.
|
|
613
|
+
*/
|
|
266
614
|
export declare class RunInfraTimeoutError extends RunInfraError {
|
|
267
|
-
constructor(message?: string, requestId?: string);
|
|
615
|
+
constructor(message?: string, requestId?: string, clientRequestId?: string);
|
|
268
616
|
}
|
|
269
617
|
export declare class RunInfraConnectionError extends RunInfraError {
|
|
270
618
|
constructor(message?: string, requestId?: string);
|
|
@@ -272,6 +620,32 @@ export declare class RunInfraConnectionError extends RunInfraError {
|
|
|
272
620
|
export declare class RunInfraStreamParseError extends RunInfraError {
|
|
273
621
|
constructor(message?: string, requestId?: string);
|
|
274
622
|
}
|
|
623
|
+
/**
|
|
624
|
+
* The API ended an open stream with a failure: a frame that holds an `error`
|
|
625
|
+
* object, or a `response.failed` event on a Responses stream. `type`, `code`
|
|
626
|
+
* and `param` are the API's own, `retryable` is set when the API marked the
|
|
627
|
+
* failure, and `requestId` is the request id the frame names, else the
|
|
628
|
+
* stream's. `status` is `0`: the failure arrived after the HTTP status. The
|
|
629
|
+
* events before the failure were already yielded. The answer is not whole.
|
|
630
|
+
*/
|
|
631
|
+
export declare class RunInfraStreamError extends RunInfraError {
|
|
632
|
+
constructor(message: string, input: {
|
|
633
|
+
type: string;
|
|
634
|
+
requestId?: string;
|
|
635
|
+
code?: string;
|
|
636
|
+
param?: string;
|
|
637
|
+
retryable?: boolean;
|
|
638
|
+
});
|
|
639
|
+
}
|
|
640
|
+
/**
|
|
641
|
+
* A stream's body ended without its end marker: `[DONE]` on a chat stream,
|
|
642
|
+
* `response.completed` on a Responses stream. The connection was cut or the
|
|
643
|
+
* stream was closed early, so the answer is not whole even though the HTTP
|
|
644
|
+
* status was 200. The events before the end were already yielded.
|
|
645
|
+
*/
|
|
646
|
+
export declare class RunInfraStreamIncompleteError extends RunInfraError {
|
|
647
|
+
constructor(message?: string, requestId?: string);
|
|
648
|
+
}
|
|
275
649
|
export declare class UnsupportedOperationError extends RunInfraError {
|
|
276
650
|
constructor(message: string);
|
|
277
651
|
}
|
|
@@ -280,24 +654,82 @@ export declare class WebhookVerificationError extends RunInfraError {
|
|
|
280
654
|
}
|
|
281
655
|
export declare function verifyWebhookSignature(options: ConstructWebhookEventOptions): true;
|
|
282
656
|
export declare function constructWebhookEvent<T = Record<string, unknown>>(options: ConstructWebhookEventOptions): T;
|
|
657
|
+
/**
|
|
658
|
+
* Verifies one batch delivery posted to your own address and returns it parsed
|
|
659
|
+
* and typed: the test delivery of `batches.create()`, one line's answer, or
|
|
660
|
+
* one line's error.
|
|
661
|
+
*
|
|
662
|
+
* Pass the RAW request body, exactly the bytes that arrived, and the request's
|
|
663
|
+
* headers in any case. The signature is the Standard Webhooks one: header
|
|
664
|
+
* `webhook-signature` holds `v1,` followed by the base64 HMAC-SHA-256 of
|
|
665
|
+
* `<webhook-id>.<webhook-timestamp>.<raw body>`, compared in constant time.
|
|
666
|
+
* Parsing the body and serializing it again changes the bytes and fails the
|
|
667
|
+
* check.
|
|
668
|
+
*
|
|
669
|
+
* `secret` is the workspace's batch signing secret as the dashboard shows it:
|
|
670
|
+
* `whsec_` followed by base64. The HMAC key is the base64-DECODED bytes after
|
|
671
|
+
* the prefix, not the text. Header `x-rightnow-signature-version` names the
|
|
672
|
+
* version of the secret that signed; a rotated secret stops verifying.
|
|
673
|
+
*
|
|
674
|
+
* The delivery's `webhook-timestamp` must be within 300 seconds of the clock
|
|
675
|
+
* by default, so a captured delivery cannot be replayed later. A number in
|
|
676
|
+
* `toleranceSeconds` sets another tolerance, `toleranceSeconds: null` turns
|
|
677
|
+
* the check off, and `now` sets the clock it is compared with.
|
|
678
|
+
*
|
|
679
|
+
* ANSWERING THE TEST DELIVERY: `batches.create()` posts
|
|
680
|
+
* `{ id, test: true, value }` to the destination before it answers, and the
|
|
681
|
+
* address passes only when it replies 2xx with a body that CONTAINS the posted
|
|
682
|
+
* `value`. A fixed `200 OK` fails the create with `destination_unreachable`.
|
|
683
|
+
* Line deliveries (`test: false`) are acknowledged by any 2xx. Each answered
|
|
684
|
+
* line is sent to the address once: if the address does not answer 2xx in
|
|
685
|
+
* time, the line is counted `undelivered`, it is not charged, and it is not
|
|
686
|
+
* sent again.
|
|
687
|
+
*
|
|
688
|
+
* Throws `WebhookVerificationError` when a header is missing, the signature
|
|
689
|
+
* does not match, the timestamp is outside the tolerance, or the body is not a
|
|
690
|
+
* delivery. Every failure of this helper is a `WebhookVerificationError`.
|
|
691
|
+
*/
|
|
692
|
+
export declare function verifyBatchDelivery(options: VerifyBatchDeliveryOptions): BatchDelivery;
|
|
283
693
|
export declare class RunInfraAudioResponse {
|
|
284
694
|
readonly contentType: string;
|
|
285
695
|
readonly requestId?: string;
|
|
286
696
|
private readonly response;
|
|
287
697
|
private readonly readTimeoutMs?;
|
|
288
698
|
private readonly sensitiveValues;
|
|
289
|
-
|
|
699
|
+
/** The `X-Client-Request-Id` the SDK sent with the call. A timeout while the body is read names it. */
|
|
700
|
+
private readonly clientRequestId?;
|
|
701
|
+
constructor(response: Response, readTimeoutMs?: number, sensitiveValues?: readonly string[], clientRequestId?: string);
|
|
290
702
|
arrayBuffer(): Promise<ArrayBuffer>;
|
|
291
703
|
blob(): Promise<Blob>;
|
|
292
704
|
stream(): ReadableStream<Uint8Array> | null;
|
|
293
705
|
private readBody;
|
|
706
|
+
/** A failed body read as the SDK's error. A timeout names the request id the SDK sent. */
|
|
707
|
+
private bodyReadFailure;
|
|
294
708
|
}
|
|
709
|
+
/**
|
|
710
|
+
* The events of one streamed answer.
|
|
711
|
+
*
|
|
712
|
+
* Iterating yields each event as it arrives. The iteration ends quietly only
|
|
713
|
+
* when the stream carried its end marker: `[DONE]` on a chat stream,
|
|
714
|
+
* `response.completed` on a Responses stream. It throws instead, after
|
|
715
|
+
* yielding every event that came first, when the API reports a failure on the
|
|
716
|
+
* open stream (`RunInfraStreamError`) or when the body ends without the end
|
|
717
|
+
* marker (`RunInfraStreamIncompleteError`). Leaving the loop early throws
|
|
718
|
+
* nothing.
|
|
719
|
+
*
|
|
720
|
+
* When the API answers the call with one JSON object instead of an event
|
|
721
|
+
* stream, the iteration yields that object once and ends quietly. That is the
|
|
722
|
+
* answer to a streamed call that repeats an `Idempotency-Key`: the object
|
|
723
|
+
* carries `_idempotent_replay: true`, as a non-streamed answer does.
|
|
724
|
+
*/
|
|
295
725
|
export declare class RunInfraStream<TEvent extends Record<string, unknown> = Record<string, unknown>> implements AsyncIterable<TEvent> {
|
|
296
726
|
readonly response: Response;
|
|
297
727
|
readonly requestId?: string;
|
|
298
728
|
private readonly readTimeoutMs?;
|
|
299
729
|
private readonly sensitiveValues;
|
|
300
|
-
|
|
730
|
+
/** The `X-Client-Request-Id` the SDK sent with the call. A timeout while the stream is read names it. */
|
|
731
|
+
private readonly clientRequestId?;
|
|
732
|
+
constructor(response: Response, readTimeoutMs?: number, sensitiveValues?: readonly string[], clientRequestId?: string);
|
|
301
733
|
[Symbol.asyncIterator](): AsyncIterator<TEvent>;
|
|
302
734
|
}
|
|
303
735
|
export declare class RunInfra {
|
|
@@ -342,6 +774,33 @@ export declare class RunInfra {
|
|
|
342
774
|
readonly images: {
|
|
343
775
|
generate: (request: ImageGenerateRequest, options?: RunInfraRequestOptions) => Promise<ImageGenerationResponse>;
|
|
344
776
|
};
|
|
777
|
+
/**
|
|
778
|
+
* Batch jobs.
|
|
779
|
+
*
|
|
780
|
+
* Preview. A job takes a JSONL file of chat completion requests and posts
|
|
781
|
+
* each answer, signed, to your webhook address. A job has a window of 24
|
|
782
|
+
* hours. Lines run when the model has spare capacity. A line the job has
|
|
783
|
+
* not run when its window ends is counted `expired` and is not charged. Use
|
|
784
|
+
* a workspace-scoped key; verify deliveries with `verifyBatchDelivery`.
|
|
785
|
+
*/
|
|
786
|
+
readonly batches: {
|
|
787
|
+
/**
|
|
788
|
+
* Creates a job, which then starts by itself. The gateway first posts a
|
|
789
|
+
* signed test delivery to `destination.url`, so this call can take 20
|
|
790
|
+
* seconds: its default timeout is never below 30 seconds. Pass
|
|
791
|
+
* `idempotencyKey` to make the call safe to retry; without one it is sent
|
|
792
|
+
* once. Sending the same create again with the same key and the same body
|
|
793
|
+
* answers the earlier job as a normal success: no error and no second
|
|
794
|
+
* job. The same key with a different body is refused with 409.
|
|
795
|
+
*/
|
|
796
|
+
create: (request: BatchCreateRequest, options?: RunInfraRequestOptions) => Promise<BatchCreateResponse>;
|
|
797
|
+
/** Lists the workspace's jobs, newest first. Page with `next_cursor`. */
|
|
798
|
+
list: (params?: BatchListParams, options?: RunInfraRequestOptions) => Promise<BatchListResponse>;
|
|
799
|
+
/** Reads one job with the lines its check refused and its quote. */
|
|
800
|
+
retrieve: (batchId: string, options?: RunInfraRequestOptions) => Promise<BatchRetrieveResponse>;
|
|
801
|
+
/** Cancels a job: `cancelled` when no line had run, else `cancelling` while lines in flight settle. Sent once, never retried. */
|
|
802
|
+
cancel: (batchId: string, options?: RunInfraRequestOptions) => Promise<BatchCancelResponse>;
|
|
803
|
+
};
|
|
345
804
|
readonly webhooks: {
|
|
346
805
|
verifySignature: typeof verifyWebhookSignature;
|
|
347
806
|
constructEvent: typeof constructWebhookEvent;
|
|
@@ -361,13 +820,20 @@ export declare class RunInfra {
|
|
|
361
820
|
private readonly apiKey;
|
|
362
821
|
private readonly baseURL;
|
|
363
822
|
private readonly hasPipelineScope;
|
|
364
|
-
|
|
823
|
+
/** The caller's own client timeout. Left unset, each call uses the default of its kind. */
|
|
824
|
+
private readonly timeoutMs?;
|
|
365
825
|
private readonly maxRetries;
|
|
366
826
|
private readonly retryBaseMs;
|
|
367
827
|
private readonly fetcher;
|
|
368
828
|
constructor(options: RunInfraOptions);
|
|
369
829
|
private request;
|
|
830
|
+
/**
|
|
831
|
+
* The timeout of one call. The caller's own setting wins: the call's
|
|
832
|
+
* `timeoutMs`, else the client's. With neither, a non-streamed call is given
|
|
833
|
+
* 750 seconds for the whole call, and a streamed call 190 seconds to its
|
|
834
|
+
* response headers and to each later read. `minDefaultTimeoutMs` is the
|
|
835
|
+
* least a call uses when the caller names no timeout for that call.
|
|
836
|
+
*/
|
|
370
837
|
private requestTimeoutMs;
|
|
371
|
-
private rawRequest;
|
|
372
838
|
private sendWithRetry;
|
|
373
839
|
}
|