pareta 0.1.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/LICENSE +202 -0
- package/README.md +108 -0
- package/dist/index.cjs +1118 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +550 -0
- package/dist/index.d.ts +550 -0
- package/dist/index.mjs +1082 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +36 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,550 @@
|
|
|
1
|
+
/** One named SSE event: the event type + its parsed (or raw-string) data. */
|
|
2
|
+
interface SSEEvent {
|
|
3
|
+
event: string;
|
|
4
|
+
data: unknown;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Response objects — hand-written wrappers over the raw server JSON, a faithful
|
|
9
|
+
* port of the Python `_models.py`. Each keeps the raw payload on `.raw` and
|
|
10
|
+
* exposes it via `.toDict()`, so nothing the API returns is lost behind the
|
|
11
|
+
* typed layer.
|
|
12
|
+
*
|
|
13
|
+
* Alias / D3 boundary (a BACKEND contract, the SDK adds no alias logic):
|
|
14
|
+
* `Endpoint.model`, `EvalResult.modelId`, leaderboard names and
|
|
15
|
+
* `run.candidateModels` are per-task PUBLIC aliases — real open-weights ids
|
|
16
|
+
* never cross. Frontier (vendor) ids are in the clear.
|
|
17
|
+
*/
|
|
18
|
+
type Raw = Record<string, any>;
|
|
19
|
+
/** Base: holds the raw payload, dict-style escape hatches. */
|
|
20
|
+
declare class BaseModel {
|
|
21
|
+
/** The raw server JSON, untouched. */
|
|
22
|
+
readonly raw: Raw;
|
|
23
|
+
constructor(raw?: Raw);
|
|
24
|
+
/** The raw server JSON (alias of `.raw`, mirrors Python `.to_dict()`). */
|
|
25
|
+
toDict(): Raw;
|
|
26
|
+
/** Read an arbitrary key off the raw payload. */
|
|
27
|
+
get<T = unknown>(key: string, fallback?: T): T;
|
|
28
|
+
}
|
|
29
|
+
declare class Usage extends BaseModel {
|
|
30
|
+
get promptTokens(): number | null;
|
|
31
|
+
get completionTokens(): number | null;
|
|
32
|
+
get totalTokens(): number | null;
|
|
33
|
+
}
|
|
34
|
+
declare class Message extends BaseModel {
|
|
35
|
+
get role(): string | null;
|
|
36
|
+
get content(): string | null;
|
|
37
|
+
}
|
|
38
|
+
declare class Choice extends BaseModel {
|
|
39
|
+
get index(): number | null;
|
|
40
|
+
get finishReason(): string | null;
|
|
41
|
+
get message(): Message;
|
|
42
|
+
/** Streaming chunks carry `delta` instead of `message`. */
|
|
43
|
+
get delta(): Message;
|
|
44
|
+
}
|
|
45
|
+
declare class ChatCompletion extends BaseModel {
|
|
46
|
+
get id(): string | null;
|
|
47
|
+
get model(): string | null;
|
|
48
|
+
get created(): number | null;
|
|
49
|
+
get choices(): Choice[];
|
|
50
|
+
get usage(): Usage;
|
|
51
|
+
}
|
|
52
|
+
/** One SSE delta. `chunk.choices[0].delta.content` is the incremental text. */
|
|
53
|
+
declare class ChatCompletionChunk extends ChatCompletion {
|
|
54
|
+
}
|
|
55
|
+
declare class Model extends BaseModel {
|
|
56
|
+
get id(): string | null;
|
|
57
|
+
get ownedBy(): string | null;
|
|
58
|
+
get created(): number | null;
|
|
59
|
+
}
|
|
60
|
+
/** The OpenAI-compatible `/v1/models` list. Exposes `.data` and is iterable. */
|
|
61
|
+
declare class ModelList extends BaseModel implements Iterable<Model> {
|
|
62
|
+
get data(): Model[];
|
|
63
|
+
get length(): number;
|
|
64
|
+
[Symbol.iterator](): Iterator<Model>;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* A deployed endpoint. `id` (== name) is what you pass to
|
|
68
|
+
* `chat.completions.create({ model })`. `model` is the per-task public alias.
|
|
69
|
+
*/
|
|
70
|
+
declare class Endpoint extends BaseModel {
|
|
71
|
+
get id(): string | null;
|
|
72
|
+
get name(): string | null;
|
|
73
|
+
get model(): string | null;
|
|
74
|
+
get status(): string | null;
|
|
75
|
+
get task(): string | null;
|
|
76
|
+
get url(): string | null;
|
|
77
|
+
get isLive(): boolean;
|
|
78
|
+
}
|
|
79
|
+
declare class Task extends BaseModel {
|
|
80
|
+
get id(): string | null;
|
|
81
|
+
get defaultScorer(): string | null;
|
|
82
|
+
get hasBlobInput(): boolean;
|
|
83
|
+
}
|
|
84
|
+
declare class TaskMatchCandidate extends BaseModel {
|
|
85
|
+
get taskId(): string | null;
|
|
86
|
+
get score(): number | null;
|
|
87
|
+
get confidence(): string | null;
|
|
88
|
+
}
|
|
89
|
+
/** Result of `tasks.match()`: `.matched`, `.chosen` (best or null), `.candidates`. */
|
|
90
|
+
declare class TaskMatch extends BaseModel {
|
|
91
|
+
get query(): string | null;
|
|
92
|
+
get matched(): boolean;
|
|
93
|
+
get chosen(): TaskMatchCandidate | null;
|
|
94
|
+
get candidates(): TaskMatchCandidate[];
|
|
95
|
+
get ambiguous(): boolean;
|
|
96
|
+
get matcher(): string | null;
|
|
97
|
+
}
|
|
98
|
+
declare class EvalSet extends BaseModel {
|
|
99
|
+
get id(): string | null;
|
|
100
|
+
get taskId(): string | null;
|
|
101
|
+
get name(): string | null;
|
|
102
|
+
get itemCount(): number | null;
|
|
103
|
+
get scoringStrategy(): string | null;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* One model's aggregate on an eval run. `modelId` is the per-task public alias;
|
|
107
|
+
* `kind` ('open' | 'frontier') is populated by the Slice-4 result schema.
|
|
108
|
+
*/
|
|
109
|
+
declare class EvalResult extends BaseModel {
|
|
110
|
+
get modelId(): string | null;
|
|
111
|
+
get kind(): string | null;
|
|
112
|
+
get qualityMean(): number | null;
|
|
113
|
+
get qualityCiLow(): number | null;
|
|
114
|
+
get qualityCiHigh(): number | null;
|
|
115
|
+
get meanCostMicroUsd(): number | null;
|
|
116
|
+
get nSucceeded(): number | null;
|
|
117
|
+
get errorCount(): number | null;
|
|
118
|
+
}
|
|
119
|
+
declare class LeaderboardEntry extends BaseModel {
|
|
120
|
+
get name(): string | null;
|
|
121
|
+
get kind(): string | null;
|
|
122
|
+
get quality(): number | null;
|
|
123
|
+
get costPerRequestMicroUsd(): number | null;
|
|
124
|
+
get contextK(): number | null;
|
|
125
|
+
get runMode(): string | null;
|
|
126
|
+
}
|
|
127
|
+
/** Models ranked for a task. `recommended` is the deployable pick; `frontier` the baseline. */
|
|
128
|
+
declare class Leaderboard extends BaseModel {
|
|
129
|
+
get taskId(): string | null;
|
|
130
|
+
get metric(): string | null;
|
|
131
|
+
get costUnit(): string | null;
|
|
132
|
+
get recommended(): string | null;
|
|
133
|
+
get models(): LeaderboardEntry[];
|
|
134
|
+
get frontier(): LeaderboardEntry | null;
|
|
135
|
+
}
|
|
136
|
+
/** A vendor frontier model you can evaluate against (from the eval pool). */
|
|
137
|
+
declare class FrontierModel extends BaseModel {
|
|
138
|
+
get id(): string | null;
|
|
139
|
+
get vendor(): string | null;
|
|
140
|
+
get vision(): boolean;
|
|
141
|
+
/** Only meaningful when a task was given: it's on that task's leaderboard. */
|
|
142
|
+
get benchmarked(): boolean;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Wraps the GET /v1/eval-runs/{id} envelope `{"run": {...}, "results": [...]}`.
|
|
146
|
+
* `cost` is the billed total as a floored fixed-2dp dollar string (§6);
|
|
147
|
+
* `costMicroUsd` is the raw integer.
|
|
148
|
+
*/
|
|
149
|
+
declare class EvalRun extends BaseModel {
|
|
150
|
+
private get run();
|
|
151
|
+
get id(): string | null;
|
|
152
|
+
get evalSetId(): string | null;
|
|
153
|
+
get status(): string | null;
|
|
154
|
+
get isTerminal(): boolean;
|
|
155
|
+
get candidateModels(): string[];
|
|
156
|
+
get errorDetail(): string | null;
|
|
157
|
+
/** Raw billed micro-USD integer. */
|
|
158
|
+
get costMicroUsd(): number;
|
|
159
|
+
/** Billed total, floored to whole cents, as a fixed-2dp dollar string ("1.23"). */
|
|
160
|
+
get cost(): string;
|
|
161
|
+
get results(): EvalResult[];
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* `client.chat.completions` — OpenAI-compatible chat completions.
|
|
166
|
+
*
|
|
167
|
+
* `model` is an endpoint id from `endpoints.deploy(...)` (or any model id the
|
|
168
|
+
* caller's org can reach). The call is metered: a successful completion debits
|
|
169
|
+
* the org's balance; a zero balance raises `InsufficientCreditsError` (402).
|
|
170
|
+
*/
|
|
171
|
+
|
|
172
|
+
/** An OpenAI-style chat message. `content` is a string or content-block array. */
|
|
173
|
+
interface ChatMessage {
|
|
174
|
+
role: string;
|
|
175
|
+
content: string | Array<Record<string, unknown>>;
|
|
176
|
+
[key: string]: unknown;
|
|
177
|
+
}
|
|
178
|
+
/** Params for `chat.completions.create`. Extra OpenAI params pass through. */
|
|
179
|
+
interface ChatCompletionCreateParams {
|
|
180
|
+
/** An endpoint id from `endpoints.deploy(...)`. */
|
|
181
|
+
model: string;
|
|
182
|
+
messages: ChatMessage[];
|
|
183
|
+
stream?: boolean;
|
|
184
|
+
/** temperature, max_tokens, top_p, … — forwarded verbatim. */
|
|
185
|
+
[key: string]: unknown;
|
|
186
|
+
}
|
|
187
|
+
declare class Completions {
|
|
188
|
+
private readonly client;
|
|
189
|
+
constructor(client: Transport);
|
|
190
|
+
/**
|
|
191
|
+
* Create a chat completion.
|
|
192
|
+
*
|
|
193
|
+
* `stream: false` (default) → `Promise<ChatCompletion>`.
|
|
194
|
+
* `stream: true` → `AsyncIterable<ChatCompletionChunk>`
|
|
195
|
+
* (`chunk.choices[0].delta.content` is the incremental text).
|
|
196
|
+
*/
|
|
197
|
+
create(params: ChatCompletionCreateParams & {
|
|
198
|
+
stream: true;
|
|
199
|
+
}): AsyncIterable<ChatCompletionChunk>;
|
|
200
|
+
create(params: ChatCompletionCreateParams & {
|
|
201
|
+
stream?: false;
|
|
202
|
+
}): Promise<ChatCompletion>;
|
|
203
|
+
}
|
|
204
|
+
declare class Chat {
|
|
205
|
+
readonly completions: Completions;
|
|
206
|
+
constructor(client: Transport);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* `client.models` — list the deployed models (endpoints) your org can call.
|
|
211
|
+
*
|
|
212
|
+
* OpenAI-compatible: only deployed, url-bearing endpoints appear. Each
|
|
213
|
+
* `Model.id` is an endpoint id usable as `chat.completions.create({ model })`.
|
|
214
|
+
*/
|
|
215
|
+
|
|
216
|
+
declare class Models {
|
|
217
|
+
private readonly client;
|
|
218
|
+
constructor(client: Transport);
|
|
219
|
+
list(): Promise<ModelList>;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* `client.endpoints` — deploy, operate, and measure deployed endpoints.
|
|
224
|
+
*
|
|
225
|
+
* `deploy({ task, model })` is ergonomic: Pareta picks the GPU/serving config
|
|
226
|
+
* (you never pass hardware) and `model` defaults to the task's recommended pick.
|
|
227
|
+
* The backend resolver behind POST /v1/endpoints evolved with the discovery
|
|
228
|
+
* work — verify the deploy body against staging when wiring real deploys.
|
|
229
|
+
*/
|
|
230
|
+
|
|
231
|
+
/** Params for `endpoints.deploy`. Extra keys pass through to the deploy body. */
|
|
232
|
+
interface DeployParams {
|
|
233
|
+
/** The task id to deploy a model for. */
|
|
234
|
+
task: string;
|
|
235
|
+
/** Model alias to deploy; defaults to "recommended" (the task's top pick). */
|
|
236
|
+
model?: string;
|
|
237
|
+
/** Optional endpoint name. */
|
|
238
|
+
name?: string;
|
|
239
|
+
/** If true, block through the deploy and resolve the live Endpoint. */
|
|
240
|
+
wait?: boolean;
|
|
241
|
+
[key: string]: unknown;
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* `endpoints.metrics(id).performance()` etc. Each returns the raw metric JSON
|
|
245
|
+
* (shapes vary by dimension; typed models arrive with the OpenAPI generation).
|
|
246
|
+
*/
|
|
247
|
+
declare class EndpointMetrics {
|
|
248
|
+
private readonly client;
|
|
249
|
+
private readonly id;
|
|
250
|
+
constructor(client: Transport, id: string);
|
|
251
|
+
performance(params?: Record<string, unknown>): Promise<unknown>;
|
|
252
|
+
uptime(params?: Record<string, unknown>): Promise<unknown>;
|
|
253
|
+
cost(params?: Record<string, unknown>): Promise<unknown>;
|
|
254
|
+
quality(params?: Record<string, unknown>): Promise<unknown>;
|
|
255
|
+
activity(params?: Record<string, unknown>): Promise<unknown>;
|
|
256
|
+
}
|
|
257
|
+
declare class Endpoints {
|
|
258
|
+
private readonly client;
|
|
259
|
+
constructor(client: Transport);
|
|
260
|
+
/**
|
|
261
|
+
* Deploy a model for a task. `wait: false` (default) → an `AsyncIterable` of
|
|
262
|
+
* progress events (`{event, data}`); the terminal event is `complete`
|
|
263
|
+
* (`data.endpoint`) or `error`. `wait: true` → resolves the live `Endpoint`
|
|
264
|
+
* (throws `ParetaError` on a deploy `error` event).
|
|
265
|
+
*/
|
|
266
|
+
deploy(params: DeployParams & {
|
|
267
|
+
wait: true;
|
|
268
|
+
}): Promise<Endpoint>;
|
|
269
|
+
deploy(params: DeployParams & {
|
|
270
|
+
wait?: false;
|
|
271
|
+
}): AsyncIterable<SSEEvent>;
|
|
272
|
+
private waitForDeploy;
|
|
273
|
+
list(): Promise<Endpoint[]>;
|
|
274
|
+
retrieve(endpointId: string): Promise<Endpoint>;
|
|
275
|
+
start(endpointId: string): Promise<unknown>;
|
|
276
|
+
stop(endpointId: string): Promise<unknown>;
|
|
277
|
+
delete(endpointId: string): Promise<void>;
|
|
278
|
+
metrics(endpointId: string): EndpointMetrics;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* `client.tasks` — browse the benchmark catalog + match free-text intent, and
|
|
283
|
+
* the per-task discovery surface (leaderboard / recommended).
|
|
284
|
+
*
|
|
285
|
+
* Unlike the Python SDK (where `leaderboard`/`recommended` exist only on the
|
|
286
|
+
* sync client), these are present uniformly here — JS has one client.
|
|
287
|
+
*/
|
|
288
|
+
|
|
289
|
+
declare class Tasks {
|
|
290
|
+
private readonly client;
|
|
291
|
+
constructor(client: Transport);
|
|
292
|
+
list(): Promise<Task[]>;
|
|
293
|
+
retrieve(taskId: string, opts?: {
|
|
294
|
+
examplesN?: number;
|
|
295
|
+
}): Promise<Task>;
|
|
296
|
+
/** Free-text intent → ranked candidate tasks (the Step-0 backend matcher). */
|
|
297
|
+
match(query: string, opts?: {
|
|
298
|
+
topK?: number;
|
|
299
|
+
}): Promise<TaskMatch>;
|
|
300
|
+
/** Models ranked by quality/cost for a task (+ recommended + frontier baseline). */
|
|
301
|
+
leaderboard(taskId: string): Promise<Leaderboard>;
|
|
302
|
+
/** The task's recommended deployable model — what deploy(model:"recommended") resolves to. */
|
|
303
|
+
recommended(taskId: string): Promise<string | null>;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* `client.evals` — eval sets + runs (bring-your-own-data evaluation).
|
|
308
|
+
*
|
|
309
|
+
* const set = await pa.evals.sets.create({ task, items: [...] });
|
|
310
|
+
* await pa.evals.sets.uploadDocument(set.id, file, { idx, fieldName }); // blob tasks
|
|
311
|
+
* const run = await pa.evals.runs.create({ evalSet: set.id, models: [...], wait: true });
|
|
312
|
+
* // or, in one call: runs.create({ task, items, models, wait: true })
|
|
313
|
+
*
|
|
314
|
+
* Runs are metered (the org balance is debited for compute); `run.cost` is the
|
|
315
|
+
* billed total in dollars (floored to cents). `frontier` accepts an explicit
|
|
316
|
+
* list of ids, or the "all"/"benchmarked"/"none" roster keywords (resolved via
|
|
317
|
+
* `frontierModels()`).
|
|
318
|
+
*/
|
|
319
|
+
|
|
320
|
+
/** "all" | "benchmarked" | "none" | an explicit list of frontier ids. */
|
|
321
|
+
type FrontierSpec = "all" | "benchmarked" | "none" | string[] | null;
|
|
322
|
+
/** A document for `uploadDocument`: a filesystem path (Node), Blob, or bytes. */
|
|
323
|
+
type FileInput = string | Blob | ArrayBuffer | Uint8Array;
|
|
324
|
+
declare class EvalSets {
|
|
325
|
+
private readonly client;
|
|
326
|
+
constructor(client: Transport);
|
|
327
|
+
create(params: {
|
|
328
|
+
task: string;
|
|
329
|
+
items: Array<Record<string, unknown>>;
|
|
330
|
+
name?: string;
|
|
331
|
+
}): Promise<EvalSet>;
|
|
332
|
+
list(): Promise<EvalSet[]>;
|
|
333
|
+
retrieve(evalSetId: string): Promise<EvalSet>;
|
|
334
|
+
delete(evalSetId: string): Promise<void>;
|
|
335
|
+
/**
|
|
336
|
+
* Attach a binary doc (PDF/image) to one row's blob field. Collapses the
|
|
337
|
+
* 3-call signed-URL flow (or the inline path for small files) into one call.
|
|
338
|
+
* `idx` is the 0-based row, `fieldName` the blob input field.
|
|
339
|
+
*/
|
|
340
|
+
uploadDocument(evalSetId: string, file: FileInput, opts: {
|
|
341
|
+
idx: number;
|
|
342
|
+
fieldName: string;
|
|
343
|
+
mime?: string;
|
|
344
|
+
}): Promise<unknown>;
|
|
345
|
+
}
|
|
346
|
+
interface EvalRunCreateParams {
|
|
347
|
+
evalSet?: string;
|
|
348
|
+
task?: string;
|
|
349
|
+
items?: Array<Record<string, unknown>>;
|
|
350
|
+
models: string[];
|
|
351
|
+
frontier?: FrontierSpec;
|
|
352
|
+
name?: string;
|
|
353
|
+
wait?: boolean;
|
|
354
|
+
pollInterval?: number;
|
|
355
|
+
timeout?: number;
|
|
356
|
+
}
|
|
357
|
+
declare class EvalRuns {
|
|
358
|
+
private readonly client;
|
|
359
|
+
private readonly sets;
|
|
360
|
+
constructor(client: Transport, sets: EvalSets);
|
|
361
|
+
private frontierIds;
|
|
362
|
+
create(params: EvalRunCreateParams): Promise<EvalRun>;
|
|
363
|
+
retrieve(runId: string): Promise<EvalRun>;
|
|
364
|
+
wait(runId: string, opts?: {
|
|
365
|
+
pollInterval?: number;
|
|
366
|
+
timeout?: number;
|
|
367
|
+
}): Promise<EvalRun>;
|
|
368
|
+
}
|
|
369
|
+
declare class Evals {
|
|
370
|
+
readonly sets: EvalSets;
|
|
371
|
+
readonly runs: EvalRuns;
|
|
372
|
+
constructor(client: Transport);
|
|
373
|
+
private readonly client;
|
|
374
|
+
/**
|
|
375
|
+
* The frontier (vendor) roster you can evaluate against. With `task`, each is
|
|
376
|
+
* annotated `benchmarked` + the roster is vision-filtered for document tasks.
|
|
377
|
+
*/
|
|
378
|
+
frontierModels(task?: string): Promise<FrontierModel[]>;
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
/**
|
|
382
|
+
* The `Pareta` client — one class (no sync/async split; JS is Promise-only).
|
|
383
|
+
* A faithful port of the Python `_client.py` transport: header construction,
|
|
384
|
+
* the retry policy, error mapping, and the `started`-flag streaming rule.
|
|
385
|
+
*/
|
|
386
|
+
|
|
387
|
+
type FetchFn = typeof globalThis.fetch;
|
|
388
|
+
/** A multipart file part (used by eval-set + blob uploads). */
|
|
389
|
+
interface FilePart {
|
|
390
|
+
filename: string;
|
|
391
|
+
content: Blob | ArrayBuffer | ArrayBufferView | string;
|
|
392
|
+
contentType?: string;
|
|
393
|
+
}
|
|
394
|
+
interface RequestOptions {
|
|
395
|
+
body?: unknown;
|
|
396
|
+
params?: Record<string, unknown> | undefined;
|
|
397
|
+
files?: Record<string, FilePart>;
|
|
398
|
+
data?: Record<string, string>;
|
|
399
|
+
cast?: (raw: unknown) => unknown;
|
|
400
|
+
}
|
|
401
|
+
interface StreamOptions {
|
|
402
|
+
body?: unknown;
|
|
403
|
+
params?: Record<string, unknown> | undefined;
|
|
404
|
+
cast?: (raw: unknown) => unknown;
|
|
405
|
+
events?: boolean;
|
|
406
|
+
}
|
|
407
|
+
/** What resource namespaces depend on (lets them avoid importing the class). */
|
|
408
|
+
interface Transport {
|
|
409
|
+
request<T = unknown>(method: string, path: string, opts?: RequestOptions): Promise<T>;
|
|
410
|
+
stream<T = unknown>(method: string, path: string, opts?: StreamOptions): AsyncGenerator<T>;
|
|
411
|
+
}
|
|
412
|
+
interface ParetaOptions {
|
|
413
|
+
/** `pareta_sk_` secret key. Falls back to PARETA_API_KEY via `fromEnv`. */
|
|
414
|
+
apiKey?: string;
|
|
415
|
+
/** API base URL. Default https://api.pareta.ai (trailing slashes stripped). */
|
|
416
|
+
baseURL?: string;
|
|
417
|
+
/** Overall per-request timeout in ms. Default 60000. */
|
|
418
|
+
timeout?: number;
|
|
419
|
+
/** Max retries for transient failures. Default 2. */
|
|
420
|
+
maxRetries?: number;
|
|
421
|
+
/** Injected fetch implementation (for tests / Node-without-global-fetch). */
|
|
422
|
+
fetch?: FetchFn;
|
|
423
|
+
}
|
|
424
|
+
declare class Pareta implements Transport {
|
|
425
|
+
readonly apiKey: string;
|
|
426
|
+
readonly baseURL: string;
|
|
427
|
+
readonly timeout: number;
|
|
428
|
+
readonly maxRetries: number;
|
|
429
|
+
private readonly fetchImpl;
|
|
430
|
+
readonly chat: Chat;
|
|
431
|
+
readonly models: Models;
|
|
432
|
+
readonly endpoints: Endpoints;
|
|
433
|
+
readonly tasks: Tasks;
|
|
434
|
+
readonly evals: Evals;
|
|
435
|
+
constructor(options?: ParetaOptions);
|
|
436
|
+
/** Build from PARETA_API_KEY (+ optional PARETA_BASE_URL); explicit opts win. */
|
|
437
|
+
static fromEnv(options?: ParetaOptions): Pareta;
|
|
438
|
+
private headers;
|
|
439
|
+
private shouldRetry;
|
|
440
|
+
/** Seconds to wait before retry `attempt` (0-indexed). Overridable in tests. */
|
|
441
|
+
protected _backoff(attempt: number, retryAfter: number | null): number;
|
|
442
|
+
/** Sleep `seconds`. Overridable in tests to skip real waits. */
|
|
443
|
+
protected _sleep(seconds: number): Promise<void>;
|
|
444
|
+
private retryAfterSeconds;
|
|
445
|
+
private buildURL;
|
|
446
|
+
private buildFormData;
|
|
447
|
+
private wrapFetchError;
|
|
448
|
+
private parseError;
|
|
449
|
+
request<T = unknown>(method: string, path: string, opts?: RequestOptions): Promise<T>;
|
|
450
|
+
/**
|
|
451
|
+
* Yield parsed SSE objects. Retries ONLY the initial connect/handshake — once
|
|
452
|
+
* bytes are flowing a mid-stream drop raises (re-issuing would re-run a
|
|
453
|
+
* metered generation / re-trigger a deploy). `events:true` → `{event,data}`.
|
|
454
|
+
*/
|
|
455
|
+
stream<T = unknown>(method: string, path: string, opts?: StreamOptions): AsyncGenerator<T>;
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
declare const VERSION = "0.1.0";
|
|
459
|
+
|
|
460
|
+
/**
|
|
461
|
+
* Typed error hierarchy for the Pareta SDK — a faithful port of the Python
|
|
462
|
+
* `_exceptions.py`. The backend is FastAPI, so error bodies are
|
|
463
|
+
* `{"detail": "<message>"}` with a standard HTTP status. We map status → a
|
|
464
|
+
* specific class so callers can `catch (e) { if (e instanceof
|
|
465
|
+
* InsufficientCreditsError) … }` instead of sniffing status codes.
|
|
466
|
+
*
|
|
467
|
+
* Status → exception mapping:
|
|
468
|
+
* 400 → BadRequestError
|
|
469
|
+
* 401 → AuthenticationError ("invalid API key")
|
|
470
|
+
* 402 → InsufficientCreditsError ("organization is out of credit…")
|
|
471
|
+
* 403 → PermissionDeniedError
|
|
472
|
+
* 404 → NotFoundError
|
|
473
|
+
* 409 → ConflictError (seed/legacy endpoint not deployed)
|
|
474
|
+
* 422 → BadRequestError (FastAPI validation; `detail` is an array)
|
|
475
|
+
* 429 → RateLimitError
|
|
476
|
+
* 503 → EndpointNotReadyError (stopped / cold / provider down)
|
|
477
|
+
* other 5xx → APIStatusError
|
|
478
|
+
*/
|
|
479
|
+
/** A single FastAPI validation error item (422 `detail` is an array of these). */
|
|
480
|
+
interface ValidationErrorItem {
|
|
481
|
+
loc?: (string | number)[];
|
|
482
|
+
msg?: string;
|
|
483
|
+
type?: string;
|
|
484
|
+
}
|
|
485
|
+
/** For 422 the server's `detail` is an ARRAY; for every other status a string. */
|
|
486
|
+
type ErrorDetail = string | ValidationErrorItem[] | null | undefined;
|
|
487
|
+
/** Base class for every error raised by the SDK. */
|
|
488
|
+
declare class ParetaError extends Error {
|
|
489
|
+
constructor(message: string, options?: {
|
|
490
|
+
cause?: unknown;
|
|
491
|
+
});
|
|
492
|
+
}
|
|
493
|
+
/** The request never reached the server (DNS, TCP, TLS, network). */
|
|
494
|
+
declare class APIConnectionError extends ParetaError {
|
|
495
|
+
constructor(message?: string, options?: {
|
|
496
|
+
cause?: unknown;
|
|
497
|
+
});
|
|
498
|
+
}
|
|
499
|
+
/** The request timed out before a response was received. */
|
|
500
|
+
declare class APITimeoutError extends APIConnectionError {
|
|
501
|
+
constructor(message?: string, options?: {
|
|
502
|
+
cause?: unknown;
|
|
503
|
+
});
|
|
504
|
+
}
|
|
505
|
+
interface APIStatusErrorInit {
|
|
506
|
+
status: number;
|
|
507
|
+
detail?: ErrorDetail;
|
|
508
|
+
requestId?: string | null;
|
|
509
|
+
response?: Response;
|
|
510
|
+
}
|
|
511
|
+
/** The server returned a non-2xx status. */
|
|
512
|
+
declare class APIStatusError extends ParetaError {
|
|
513
|
+
/** The HTTP status code. */
|
|
514
|
+
readonly status: number;
|
|
515
|
+
/** The server's `detail` (string, or an array of validation items for 422). */
|
|
516
|
+
readonly detail: ErrorDetail;
|
|
517
|
+
/** Value of the `x-request-id` response header, if present. */
|
|
518
|
+
readonly requestId: string | null;
|
|
519
|
+
/** The underlying `Response` (for advanced use). */
|
|
520
|
+
readonly response?: Response;
|
|
521
|
+
constructor(message: string, init: APIStatusErrorInit);
|
|
522
|
+
}
|
|
523
|
+
declare class BadRequestError extends APIStatusError {
|
|
524
|
+
constructor(message: string, init: APIStatusErrorInit);
|
|
525
|
+
}
|
|
526
|
+
declare class AuthenticationError extends APIStatusError {
|
|
527
|
+
constructor(message: string, init: APIStatusErrorInit);
|
|
528
|
+
}
|
|
529
|
+
declare class PermissionDeniedError extends APIStatusError {
|
|
530
|
+
constructor(message: string, init: APIStatusErrorInit);
|
|
531
|
+
}
|
|
532
|
+
declare class NotFoundError extends APIStatusError {
|
|
533
|
+
constructor(message: string, init: APIStatusErrorInit);
|
|
534
|
+
}
|
|
535
|
+
declare class ConflictError extends APIStatusError {
|
|
536
|
+
constructor(message: string, init: APIStatusErrorInit);
|
|
537
|
+
}
|
|
538
|
+
/** The org is out of credit. Top up in the dashboard (billing is browser-only). */
|
|
539
|
+
declare class InsufficientCreditsError extends APIStatusError {
|
|
540
|
+
constructor(message: string, init: APIStatusErrorInit);
|
|
541
|
+
}
|
|
542
|
+
declare class RateLimitError extends APIStatusError {
|
|
543
|
+
constructor(message: string, init: APIStatusErrorInit);
|
|
544
|
+
}
|
|
545
|
+
/** The target endpoint isn't serving yet (stopped, cold-starting, or provider down). */
|
|
546
|
+
declare class EndpointNotReadyError extends APIStatusError {
|
|
547
|
+
constructor(message: string, init: APIStatusErrorInit);
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
export { APIConnectionError, APIStatusError, APITimeoutError, AuthenticationError, BadRequestError, BaseModel, ChatCompletion, ChatCompletionChunk, type ChatCompletionCreateParams, type ChatMessage, Choice, ConflictError, type DeployParams, Endpoint, EndpointMetrics, EndpointNotReadyError, type ErrorDetail, EvalResult, EvalRun, type EvalRunCreateParams, EvalRuns, EvalSet, EvalSets, type FileInput, type FilePart, FrontierModel, type FrontierSpec, InsufficientCreditsError, Leaderboard, LeaderboardEntry, Message, Model, ModelList, NotFoundError, Pareta, ParetaError, type ParetaOptions, PermissionDeniedError, RateLimitError, type SSEEvent, Task, TaskMatch, TaskMatchCandidate, type Transport, Usage, VERSION, type ValidationErrorItem };
|