segmind 0.2.4 → 0.4.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 +57 -4
- package/dist/index.cjs +243 -50
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +284 -84
- package/dist/index.d.ts +284 -84
- package/dist/index.js +243 -50
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,59 @@
|
|
|
1
|
+
type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
2
|
+
/** Returns the signed-in user's token, or null when there is none. Called before every request. */
|
|
3
|
+
type TokenProvider = () => string | null | undefined | Promise<string | null | undefined>;
|
|
4
|
+
/** Milliseconds between status checks: fixed, or worked out from the milliseconds elapsed so far. */
|
|
5
|
+
type PollInterval = number | ((elapsedMs: number) => number);
|
|
6
|
+
interface HttpConfig {
|
|
7
|
+
apiKey: string | undefined;
|
|
8
|
+
tokenProvider?: TokenProvider;
|
|
9
|
+
onUnauthorized?: () => void | Promise<void>;
|
|
10
|
+
fetch: typeof fetch;
|
|
11
|
+
timeout: number;
|
|
12
|
+
maxRetries: number;
|
|
13
|
+
headers: Record<string, string>;
|
|
14
|
+
}
|
|
15
|
+
interface HttpRequest {
|
|
16
|
+
method: HttpMethod;
|
|
17
|
+
url: string;
|
|
18
|
+
/** Query parameters; `undefined` values are left out. */
|
|
19
|
+
query?: Record<string, string | number | boolean | undefined>;
|
|
20
|
+
/** Sent as JSON. */
|
|
21
|
+
body?: unknown;
|
|
22
|
+
/** Sent as is, instead of a JSON `body`. */
|
|
23
|
+
rawBody?: Uint8Array | Blob;
|
|
24
|
+
/**
|
|
25
|
+
* Send only `headers`: no API key, no `X-Initiator`, no default headers. For
|
|
26
|
+
* presigned URLs on other hosts, which must never see the key.
|
|
27
|
+
*/
|
|
28
|
+
bare?: boolean;
|
|
29
|
+
headers?: Record<string, string>;
|
|
30
|
+
signal?: AbortSignal;
|
|
31
|
+
/** Milliseconds for this attempt; defaults to the client's timeout. */
|
|
32
|
+
timeout?: number;
|
|
33
|
+
/**
|
|
34
|
+
* Retry connection errors and retryable statuses. Only for requests that
|
|
35
|
+
* cannot bill twice: reads, polls, and v2 submits that carry an
|
|
36
|
+
* `X-Request-ID` (the gateway answers a repeat with 409, not a second job).
|
|
37
|
+
*/
|
|
38
|
+
retry?: boolean;
|
|
39
|
+
}
|
|
40
|
+
declare class HttpClient {
|
|
41
|
+
readonly config: HttpConfig;
|
|
42
|
+
/** The hook call in flight, so that requests failing together share one refresh. */
|
|
43
|
+
private unauthorized;
|
|
44
|
+
constructor(config: HttpConfig);
|
|
45
|
+
/** The response whatever its status, after retries when `retry` is set. */
|
|
46
|
+
fetchRaw(req: HttpRequest): Promise<Response>;
|
|
47
|
+
/** The response, or a `SegmindError` for any status outside 2xx. */
|
|
48
|
+
request(req: HttpRequest): Promise<Response>;
|
|
49
|
+
/** The parsed JSON body of a 2xx response. */
|
|
50
|
+
json<T>(req: HttpRequest): Promise<T>;
|
|
51
|
+
private sessionToken;
|
|
52
|
+
/** Tells the app its token was refused. True when it now has a different one to try. */
|
|
53
|
+
private reauthenticate;
|
|
54
|
+
private attempt;
|
|
55
|
+
}
|
|
56
|
+
|
|
1
57
|
/** Model inputs, forwarded to the model exactly as given. */
|
|
2
58
|
type Params = Record<string, unknown>;
|
|
3
59
|
/** A v2 request's state. */
|
|
@@ -34,13 +90,26 @@ interface SubmitResponse {
|
|
|
34
90
|
poll_url?: string;
|
|
35
91
|
[key: string]: unknown;
|
|
36
92
|
}
|
|
37
|
-
|
|
93
|
+
/**
|
|
94
|
+
* Which surface a request is recorded under in usage history. Known values are
|
|
95
|
+
* listed, but any string is accepted: the platform records one it does not know
|
|
96
|
+
* as `OTHERS`, and values are case-sensitive. Give the bare name: the gateway
|
|
97
|
+
* adds the `-V2` itself on queued requests.
|
|
98
|
+
*/
|
|
99
|
+
type Initiator = 'API' | 'WEBPROD' | 'WEBSTAGE' | 'WORKFLOWS' | 'MCP' | 'AGENT' | 'PIXIE' | 'SDK-JS' | (string & {});
|
|
100
|
+
interface InitiatorOptions {
|
|
101
|
+
/** Overrides the client's `initiator` for this request. */
|
|
102
|
+
initiator?: Initiator;
|
|
103
|
+
/** Overrides the client's `initiatorId`: what the request belongs to, such as a workflow id. */
|
|
104
|
+
initiatorId?: string;
|
|
105
|
+
}
|
|
106
|
+
interface CallOptions extends InitiatorOptions {
|
|
38
107
|
/** Cancels the call. */
|
|
39
108
|
signal?: AbortSignal;
|
|
40
109
|
/** Milliseconds per HTTP request; defaults to the client's `timeout`. */
|
|
41
110
|
timeout?: number;
|
|
42
111
|
}
|
|
43
|
-
interface SubmitOptions {
|
|
112
|
+
interface SubmitOptions extends InitiatorOptions {
|
|
44
113
|
signal?: AbortSignal;
|
|
45
114
|
/**
|
|
46
115
|
* Idempotency key sent as `X-Request-ID` ([A-Za-z0-9_-]{8,128}). Submitting
|
|
@@ -53,8 +122,13 @@ interface WaitOptions {
|
|
|
53
122
|
signal?: AbortSignal;
|
|
54
123
|
/** Give up after this many milliseconds. Default 600 000 (10 minutes). */
|
|
55
124
|
timeout?: number;
|
|
56
|
-
/**
|
|
57
|
-
|
|
125
|
+
/**
|
|
126
|
+
* Milliseconds between status checks, or a function of the milliseconds
|
|
127
|
+
* elapsed since `wait()` began, for a schedule. Default 1000.
|
|
128
|
+
*/
|
|
129
|
+
interval?: PollInterval;
|
|
130
|
+
/** Called with every status read, including the final one. */
|
|
131
|
+
onStatus?: (status: JobStatus) => void;
|
|
58
132
|
}
|
|
59
133
|
type RunOptions = SubmitOptions & WaitOptions;
|
|
60
134
|
|
|
@@ -94,51 +168,6 @@ declare class ChatResponse {
|
|
|
94
168
|
get toolCalls(): unknown[];
|
|
95
169
|
}
|
|
96
170
|
|
|
97
|
-
type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
98
|
-
interface HttpConfig {
|
|
99
|
-
apiKey: string | undefined;
|
|
100
|
-
fetch: typeof fetch;
|
|
101
|
-
timeout: number;
|
|
102
|
-
maxRetries: number;
|
|
103
|
-
headers: Record<string, string>;
|
|
104
|
-
}
|
|
105
|
-
interface HttpRequest {
|
|
106
|
-
method: HttpMethod;
|
|
107
|
-
url: string;
|
|
108
|
-
/** Query parameters; `undefined` values are left out. */
|
|
109
|
-
query?: Record<string, string | number | boolean | undefined>;
|
|
110
|
-
/** Sent as JSON. */
|
|
111
|
-
body?: unknown;
|
|
112
|
-
/** Sent as is, instead of a JSON `body`. */
|
|
113
|
-
rawBody?: Uint8Array | Blob;
|
|
114
|
-
/**
|
|
115
|
-
* Send only `headers`: no API key, no `X-Initiator`, no default headers. For
|
|
116
|
-
* presigned URLs on other hosts, which must never see the key.
|
|
117
|
-
*/
|
|
118
|
-
bare?: boolean;
|
|
119
|
-
headers?: Record<string, string>;
|
|
120
|
-
signal?: AbortSignal;
|
|
121
|
-
/** Milliseconds for this attempt; defaults to the client's timeout. */
|
|
122
|
-
timeout?: number;
|
|
123
|
-
/**
|
|
124
|
-
* Retry connection errors and retryable statuses. Only for requests that
|
|
125
|
-
* cannot bill twice: reads, polls, and v2 submits that carry an
|
|
126
|
-
* `X-Request-ID` (the gateway answers a repeat with 409, not a second job).
|
|
127
|
-
*/
|
|
128
|
-
retry?: boolean;
|
|
129
|
-
}
|
|
130
|
-
declare class HttpClient {
|
|
131
|
-
readonly config: HttpConfig;
|
|
132
|
-
constructor(config: HttpConfig);
|
|
133
|
-
/** The response whatever its status, after retries when `retry` is set. */
|
|
134
|
-
fetchRaw(req: HttpRequest): Promise<Response>;
|
|
135
|
-
/** The response, or a `SegmindError` for any status outside 2xx. */
|
|
136
|
-
request(req: HttpRequest): Promise<Response>;
|
|
137
|
-
/** The parsed JSON body of a 2xx response. */
|
|
138
|
-
json<T>(req: HttpRequest): Promise<T>;
|
|
139
|
-
private attempt;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
171
|
/** A file to send: a path (Node only), a `Blob` or `File`, or raw bytes. */
|
|
143
172
|
type FileInput = string | Blob | ArrayBuffer | Uint8Array;
|
|
144
173
|
|
|
@@ -222,6 +251,13 @@ interface RequestRecord {
|
|
|
222
251
|
latency_ms?: number | null;
|
|
223
252
|
model_created?: string;
|
|
224
253
|
error?: string | null;
|
|
254
|
+
/** What sent the request, such as `API`, `API_V2`, `SDK_JS_V2` or `WEBPROD_V2`. */
|
|
255
|
+
initiator?: string | null;
|
|
256
|
+
/** The last 6 characters of the API key that made the request; null when no key did. */
|
|
257
|
+
key_mask?: string | null;
|
|
258
|
+
user_id?: string | null;
|
|
259
|
+
/** Inside a team, whose request it was. Empty when the lookup failed. */
|
|
260
|
+
user_email?: string | null;
|
|
225
261
|
[key: string]: unknown;
|
|
226
262
|
}
|
|
227
263
|
interface GenerationsListOptions {
|
|
@@ -246,6 +282,17 @@ interface HistoryOptions {
|
|
|
246
282
|
/** Substring match on the model slug. */
|
|
247
283
|
modelName?: string;
|
|
248
284
|
status?: 'COMPLETED' | 'FAILED' | 'PENDING';
|
|
285
|
+
/**
|
|
286
|
+
* Only requests from these sources; a list matches any of them. Either
|
|
287
|
+
* spelling works, `API_V2` or `API-V2`. An unknown source is refused (400).
|
|
288
|
+
*/
|
|
289
|
+
initiator?: string | string[];
|
|
290
|
+
/**
|
|
291
|
+
* Only one key's requests, by the last 6 characters of the key, lowercase:
|
|
292
|
+
* the `key_mask` on each row. The full key is never sent, because a URL ends
|
|
293
|
+
* up in access logs.
|
|
294
|
+
*/
|
|
295
|
+
keySuffix?: string;
|
|
249
296
|
/** Inside a team, any member's user id; otherwise only your own. */
|
|
250
297
|
userId?: string;
|
|
251
298
|
/** Same as `userId`, by email. Pass one or the other. */
|
|
@@ -287,22 +334,22 @@ declare const DEFAULT_WAIT_INTERVAL_MS = 1000;
|
|
|
287
334
|
*/
|
|
288
335
|
declare class Job<T = RunResult> {
|
|
289
336
|
private readonly http;
|
|
290
|
-
/** The body the submit returned. */
|
|
337
|
+
/** The body the submit returned. A job rebuilt with `segmind.job()` has only its id and URLs. */
|
|
291
338
|
readonly submitResponse: SubmitResponse;
|
|
292
339
|
private readonly transform;
|
|
293
340
|
readonly requestId: string;
|
|
294
341
|
readonly statusUrl: string;
|
|
295
342
|
readonly responseUrl: string;
|
|
296
343
|
constructor(http: HttpClient,
|
|
297
|
-
/** The body the submit returned. */
|
|
344
|
+
/** The body the submit returned. A job rebuilt with `segmind.job()` has only its id and URLs. */
|
|
298
345
|
submitResponse: SubmitResponse, transform?: (body: RunResult) => T);
|
|
299
346
|
/** The current state, without waiting. */
|
|
300
347
|
status(options?: {
|
|
301
348
|
signal?: AbortSignal;
|
|
302
349
|
}): Promise<JobStatus>;
|
|
303
350
|
/**
|
|
304
|
-
* The finished result. Throws `InferenceFailed` when the request failed
|
|
305
|
-
* a `SegmindError` when it has not finished yet (use `wait()` for that).
|
|
351
|
+
* The finished result. Throws `InferenceFailed` when the request failed
|
|
352
|
+
* (`InsufficientCredits` when that was for lack of credits), and a `SegmindError` when it has not finished yet (use `wait()` for that).
|
|
306
353
|
*/
|
|
307
354
|
result(options?: {
|
|
308
355
|
signal?: AbortSignal;
|
|
@@ -317,7 +364,7 @@ declare class Job<T = RunResult> {
|
|
|
317
364
|
private read;
|
|
318
365
|
}
|
|
319
366
|
|
|
320
|
-
interface PixelflowSubmitOptions {
|
|
367
|
+
interface PixelflowSubmitOptions extends InitiatorOptions {
|
|
321
368
|
/**
|
|
322
369
|
* `v2` (default) runs on the current workflow engine, which also loads
|
|
323
370
|
* older graphs. `v1` is the legacy engine.
|
|
@@ -328,8 +375,13 @@ interface PixelflowSubmitOptions {
|
|
|
328
375
|
interface PixelflowWaitOptions {
|
|
329
376
|
/** Give up after this many milliseconds. Default 600 000. */
|
|
330
377
|
timeout?: number;
|
|
331
|
-
/**
|
|
332
|
-
|
|
378
|
+
/**
|
|
379
|
+
* Milliseconds between status checks, or a function of the milliseconds
|
|
380
|
+
* elapsed since `wait()` began, for a schedule. Default 2000.
|
|
381
|
+
*/
|
|
382
|
+
interval?: PollInterval;
|
|
383
|
+
/** Called with every status read, including the final one. */
|
|
384
|
+
onStatus?: (status: PixelflowStatus) => void;
|
|
333
385
|
signal?: AbortSignal;
|
|
334
386
|
}
|
|
335
387
|
interface PixelflowStatus {
|
|
@@ -369,7 +421,7 @@ declare class PixelflowJob {
|
|
|
369
421
|
}): Promise<PixelflowStatus>;
|
|
370
422
|
/**
|
|
371
423
|
* Polls until the run finishes. Throws `InferenceFailed` (its `detail` names
|
|
372
|
-
* the failing node) or `InferenceTimeout`; the run may still finish after a
|
|
424
|
+
* the failing node), `InsufficientCredits` or `InferenceTimeout`; the run may still finish after a
|
|
373
425
|
* timeout, so `wait()` can be called again.
|
|
374
426
|
*/
|
|
375
427
|
wait(options?: PixelflowWaitOptions): Promise<PixelflowStatus>;
|
|
@@ -382,7 +434,7 @@ declare class PixelflowJob {
|
|
|
382
434
|
type WebhookEventType = 'PIXELFLOW' | 'WORKFLOW' | 'INFERENCE' | 'FINETUNE' | (string & {});
|
|
383
435
|
/** A webhook registration, as the API returns it. */
|
|
384
436
|
interface Webhook {
|
|
385
|
-
/** Pass to `update`, `delete` and `
|
|
437
|
+
/** Pass to `update`, `delete`, `logs` and `test`. */
|
|
386
438
|
id: string;
|
|
387
439
|
user_id: string;
|
|
388
440
|
webhook_url: string;
|
|
@@ -393,6 +445,22 @@ interface Webhook {
|
|
|
393
445
|
created_ts: string;
|
|
394
446
|
[key: string]: unknown;
|
|
395
447
|
}
|
|
448
|
+
/** One delivery to a registration, as `logs` lists it. */
|
|
449
|
+
interface WebhookDelivery {
|
|
450
|
+
/** Pass to `resend`. */
|
|
451
|
+
id: string;
|
|
452
|
+
webhook_url: string;
|
|
453
|
+
request_id: string;
|
|
454
|
+
event_type: string;
|
|
455
|
+
payload: unknown;
|
|
456
|
+
/** Your endpoint's HTTP status; null when it never answered. */
|
|
457
|
+
status_code: number | null;
|
|
458
|
+
/** The start of your endpoint's reply. */
|
|
459
|
+
response_body: string | null;
|
|
460
|
+
success: boolean;
|
|
461
|
+
created_ts: string;
|
|
462
|
+
[key: string]: unknown;
|
|
463
|
+
}
|
|
396
464
|
/** Your webhook registrations. One active registration per set of event types. */
|
|
397
465
|
declare class Webhooks {
|
|
398
466
|
private readonly client;
|
|
@@ -422,10 +490,30 @@ declare class Webhooks {
|
|
|
422
490
|
delete(webhookId: string, options?: {
|
|
423
491
|
signal?: AbortSignal;
|
|
424
492
|
}): Promise<Record<string, unknown>>;
|
|
425
|
-
/**
|
|
493
|
+
/** Every delivery made to one registration. */
|
|
426
494
|
logs(webhookId: string, options?: {
|
|
427
495
|
signal?: AbortSignal;
|
|
428
|
-
}): Promise<
|
|
496
|
+
}): Promise<WebhookDelivery[]>;
|
|
497
|
+
/**
|
|
498
|
+
* Sends a `WEBHOOK_TEST` delivery to an active registration. It goes out in
|
|
499
|
+
* the background after this returns, so read `logs` to see how your endpoint
|
|
500
|
+
* answered. Not retried: each attempt is another delivery.
|
|
501
|
+
*/
|
|
502
|
+
test(webhookId: string, options?: {
|
|
503
|
+
signal?: AbortSignal;
|
|
504
|
+
}): Promise<{
|
|
505
|
+
message: string;
|
|
506
|
+
}>;
|
|
507
|
+
/**
|
|
508
|
+
* Sends a past delivery's payload again, by its `id` from `logs`. Refused
|
|
509
|
+
* (406) when the registration is no longer active. Not retried: each
|
|
510
|
+
* attempt is another delivery.
|
|
511
|
+
*/
|
|
512
|
+
resend(deliveryId: string, options?: {
|
|
513
|
+
signal?: AbortSignal;
|
|
514
|
+
}): Promise<{
|
|
515
|
+
message: string;
|
|
516
|
+
}>;
|
|
429
517
|
private call;
|
|
430
518
|
}
|
|
431
519
|
|
|
@@ -433,11 +521,29 @@ declare const DEFAULT_BASE_URL = "https://api.segmind.com";
|
|
|
433
521
|
declare const DEFAULT_SPOT_URL = "https://api.spotprod.segmind.com";
|
|
434
522
|
declare const DEFAULT_CONSOLE_URL = "https://cloud.segmind.com/api";
|
|
435
523
|
interface ClientOptions {
|
|
436
|
-
/** Your Segmind API key. Defaults to `SEGMIND_API_KEY` from the environment. */
|
|
524
|
+
/** Your Segmind API key. Defaults to `SEGMIND_API_KEY` from the environment, unless `tokenProvider` is set. */
|
|
437
525
|
apiKey?: string;
|
|
526
|
+
/**
|
|
527
|
+
* Authenticates as a signed-in Segmind user instead of with an API key, sending
|
|
528
|
+
* `Authorization: Bearer <token>`. Called before every request, so a rotated
|
|
529
|
+
* token is picked up mid-poll. Allowed in browsers, because the token is the
|
|
530
|
+
* user's own session. When it returns nothing, requests go out unauthenticated.
|
|
531
|
+
*/
|
|
532
|
+
tokenProvider?: TokenProvider;
|
|
533
|
+
/**
|
|
534
|
+
* Called when a request made with `tokenProvider` gets a 401: refresh the
|
|
535
|
+
* session here. If `tokenProvider` then returns a different token, the request
|
|
536
|
+
* is sent once more; otherwise the 401 is thrown. Requests failing at the same
|
|
537
|
+
* time share one call.
|
|
538
|
+
*/
|
|
539
|
+
onUnauthorized?: () => void | Promise<void>;
|
|
540
|
+
/** Recorded as the source of these requests in usage history. Default `SDK-JS`. */
|
|
541
|
+
initiator?: Initiator;
|
|
542
|
+
/** Recorded with `initiator`: what the requests belong to, such as a workflow id. */
|
|
543
|
+
initiatorId?: string;
|
|
438
544
|
/** The inference API root, without `/v1`. Defaults to `SEGMIND_BASE_URL` or https://api.segmind.com. */
|
|
439
545
|
baseURL?: string;
|
|
440
|
-
/** The
|
|
546
|
+
/** The history, webhook and upload API. Default https://api.spotprod.segmind.com. */
|
|
441
547
|
spotURL?: string;
|
|
442
548
|
/** The account API. Default https://cloud.segmind.com/api. */
|
|
443
549
|
consoleURL?: string;
|
|
@@ -501,6 +607,13 @@ declare class Segmind {
|
|
|
501
607
|
* the existing request rather than a second one.
|
|
502
608
|
*/
|
|
503
609
|
submit(slug: string, params?: Params, options?: SubmitOptions): Promise<Job>;
|
|
610
|
+
/**
|
|
611
|
+
* A job submitted earlier, from its id alone, for picking one up after a
|
|
612
|
+
* reload or in another process. Makes no request. The result is kept for about
|
|
613
|
+
* an hour, and only for the user who submitted it: anything else reads as a
|
|
614
|
+
* `SegmindError` with status 404.
|
|
615
|
+
*/
|
|
616
|
+
job(requestId: string): Job;
|
|
504
617
|
/** Chat with an LLM through the v2 queue. Returns a provider-neutral reply. */
|
|
505
618
|
chat(slug: string, params: ChatParams, options?: RunOptions): Promise<ChatResponse>;
|
|
506
619
|
/** Chat with one blocking `POST /v1/{slug}`. */
|
|
@@ -509,32 +622,96 @@ declare class Segmind {
|
|
|
509
622
|
submitChat(slug: string, params: ChatParams, options?: SubmitOptions): Promise<Job<ChatResponse>>;
|
|
510
623
|
private submitJob;
|
|
511
624
|
}
|
|
512
|
-
|
|
625
|
+
type ModelInput = 'text' | 'image' | 'video' | 'audio';
|
|
626
|
+
type ModelOutput = ModelInput | '3d' | 'embedding' | 'data';
|
|
627
|
+
type ModelSort = 'popular' | 'newest' | 'name' | 'cheapest' | 'fastest' | 'relevance';
|
|
628
|
+
/** One catalog entry, as `GET /models` returns it. */
|
|
513
629
|
interface ModelInfo {
|
|
514
630
|
slug: string;
|
|
515
|
-
|
|
516
|
-
type?: string;
|
|
631
|
+
name: string;
|
|
517
632
|
description?: string;
|
|
518
|
-
|
|
519
|
-
|
|
633
|
+
/** For example `textToImage` or `imageToVideo`. */
|
|
634
|
+
category?: string;
|
|
635
|
+
modality?: string;
|
|
636
|
+
input?: ModelInput;
|
|
637
|
+
output?: ModelOutput;
|
|
638
|
+
provider?: string;
|
|
639
|
+
thumbnail_url?: string;
|
|
520
640
|
is_new?: boolean;
|
|
521
641
|
coming_soon?: boolean;
|
|
522
|
-
|
|
642
|
+
/** 0–100, across the whole catalog. */
|
|
643
|
+
popularity_score?: number;
|
|
644
|
+
/** 0–100, within the model's category. */
|
|
645
|
+
category_percentile?: number;
|
|
646
|
+
/** Observed average spend per request in USD, not the list price. */
|
|
647
|
+
average_cost?: number | null;
|
|
648
|
+
latency_seconds?: number | null;
|
|
649
|
+
created_at?: string;
|
|
650
|
+
operations?: string[];
|
|
651
|
+
features?: string[];
|
|
523
652
|
[key: string]: unknown;
|
|
524
653
|
}
|
|
525
|
-
/**
|
|
526
|
-
interface
|
|
527
|
-
|
|
654
|
+
/** Filters and paging for `models.list()`. Every filter is optional. */
|
|
655
|
+
interface ModelListParams {
|
|
656
|
+
/** Free-text search; sorts by relevance unless `sort` is given. */
|
|
657
|
+
q?: string;
|
|
658
|
+
/** Default `popular`, or `relevance` when `q` is set. */
|
|
659
|
+
sort?: ModelSort;
|
|
660
|
+
category?: string;
|
|
661
|
+
modality?: string;
|
|
662
|
+
/** Models that take any of these inputs. */
|
|
663
|
+
input?: ModelInput | ModelInput[];
|
|
664
|
+
/** Models that produce any of these outputs. */
|
|
665
|
+
output?: ModelOutput | ModelOutput[];
|
|
666
|
+
provider?: string;
|
|
667
|
+
/** Look up these slugs, up to 100. Unlisted models resolve too. */
|
|
668
|
+
slugs?: string[];
|
|
669
|
+
operations?: string | string[];
|
|
670
|
+
features?: string | string[];
|
|
671
|
+
minPopularity?: number;
|
|
672
|
+
minCategoryPercentile?: number;
|
|
673
|
+
minCost?: number;
|
|
674
|
+
maxCost?: number;
|
|
675
|
+
maxLatency?: number;
|
|
676
|
+
isNew?: boolean;
|
|
677
|
+
/** `YYYY-MM-DD`. */
|
|
678
|
+
createdAfter?: string;
|
|
679
|
+
includeComingSoon?: boolean;
|
|
680
|
+
/** Also return filter counts under `facets`. */
|
|
681
|
+
facets?: boolean;
|
|
682
|
+
/** 1–100, default 50. */
|
|
683
|
+
limit?: number;
|
|
684
|
+
offset?: number;
|
|
685
|
+
}
|
|
686
|
+
/** One page of the catalog. */
|
|
687
|
+
interface ModelsPage {
|
|
688
|
+
models: ModelInfo[];
|
|
689
|
+
total: number;
|
|
690
|
+
limit: number;
|
|
691
|
+
offset: number;
|
|
692
|
+
has_more: boolean;
|
|
693
|
+
facets?: Record<string, unknown>;
|
|
528
694
|
[key: string]: unknown;
|
|
529
695
|
}
|
|
530
|
-
/** The model catalog
|
|
696
|
+
/** The model catalog, served by the gateway at `GET /models`. */
|
|
531
697
|
declare class Models {
|
|
532
698
|
private readonly client;
|
|
533
699
|
constructor(client: Segmind);
|
|
534
|
-
/**
|
|
535
|
-
list(options?: {
|
|
700
|
+
/** One page of the catalog. Pass `offset` from the previous page while `has_more` is true. */
|
|
701
|
+
list(params?: ModelListParams, options?: {
|
|
702
|
+
signal?: AbortSignal;
|
|
703
|
+
}): Promise<ModelsPage>;
|
|
704
|
+
/** Every model matching `params`, reading page after page. */
|
|
705
|
+
listAll(params?: Omit<ModelListParams, 'limit' | 'offset' | 'facets'>, options?: {
|
|
536
706
|
signal?: AbortSignal;
|
|
537
|
-
}): Promise<
|
|
707
|
+
}): Promise<ModelInfo[]>;
|
|
708
|
+
}
|
|
709
|
+
/** The balance of the account or team making the request. */
|
|
710
|
+
interface AccountCredits {
|
|
711
|
+
/** The stored balance. Credits held by requests still running are not taken off. */
|
|
712
|
+
credits: number;
|
|
713
|
+
freeCredits: number;
|
|
714
|
+
[key: string]: unknown;
|
|
538
715
|
}
|
|
539
716
|
/** The account the API key belongs to. */
|
|
540
717
|
declare class Accounts {
|
|
@@ -544,6 +721,10 @@ declare class Accounts {
|
|
|
544
721
|
current(options?: {
|
|
545
722
|
signal?: AbortSignal;
|
|
546
723
|
}): Promise<Record<string, unknown>>;
|
|
724
|
+
/** The current credit balance. */
|
|
725
|
+
credits(options?: {
|
|
726
|
+
signal?: AbortSignal;
|
|
727
|
+
}): Promise<AccountCredits>;
|
|
547
728
|
}
|
|
548
729
|
|
|
549
730
|
/** An OpenAI-style image part, for the `content` list of a chat message. */
|
|
@@ -592,6 +773,24 @@ declare class SegmindError extends Error {
|
|
|
592
773
|
/** The request never got a response: DNS, TLS, connection reset, or the client's timeout. */
|
|
593
774
|
declare class APIConnectionError extends SegmindError {
|
|
594
775
|
}
|
|
776
|
+
/**
|
|
777
|
+
* The account cannot pay for the request. The gateway reports this at submit, or
|
|
778
|
+
* as a failed job when the balance is positive but below the model's cost, so
|
|
779
|
+
* this one class covers both. `detail` holds the server's message.
|
|
780
|
+
*/
|
|
781
|
+
declare class InsufficientCredits extends SegmindError {
|
|
782
|
+
}
|
|
783
|
+
/**
|
|
784
|
+
* Too many requests, after the SDK's own retries for calls that are safe to
|
|
785
|
+
* repeat. `retryAfterMs` is set when the server sent `Retry-After` and the
|
|
786
|
+
* runtime could read it: a browser only sees the header if the server exposes it.
|
|
787
|
+
*/
|
|
788
|
+
declare class RateLimited extends SegmindError {
|
|
789
|
+
readonly retryAfterMs: number | undefined;
|
|
790
|
+
constructor(message: string, options?: SegmindErrorOptions & {
|
|
791
|
+
retryAfterMs?: number;
|
|
792
|
+
});
|
|
793
|
+
}
|
|
595
794
|
/** A v2 request reached `FAILED`. The server's error text is in `detail`. */
|
|
596
795
|
declare class InferenceFailed extends SegmindError {
|
|
597
796
|
/** The status body that reported the failure. */
|
|
@@ -607,7 +806,7 @@ declare class InferenceTimeout extends SegmindError {
|
|
|
607
806
|
constructor(requestId: string, elapsedMs: number);
|
|
608
807
|
}
|
|
609
808
|
|
|
610
|
-
declare const VERSION = "0.
|
|
809
|
+
declare const VERSION = "0.4.0";
|
|
611
810
|
|
|
612
811
|
/** `new Segmind().run(...)` with the key from `SEGMIND_API_KEY`. */
|
|
613
812
|
declare const run: (slug: string, params?: Params, options?: RunOptions) => Promise<RunResult>;
|
|
@@ -615,6 +814,8 @@ declare const run: (slug: string, params?: Params, options?: RunOptions) => Prom
|
|
|
615
814
|
declare const runSync: (slug: string, params?: Params, options?: CallOptions) => Promise<Response>;
|
|
616
815
|
/** `new Segmind().submit(...)` with the key from `SEGMIND_API_KEY`. */
|
|
617
816
|
declare const submit: (slug: string, params?: Params, options?: SubmitOptions) => Promise<Job>;
|
|
817
|
+
/** `new Segmind().job(...)` with the key from `SEGMIND_API_KEY`. */
|
|
818
|
+
declare const job: (requestId: string) => Job;
|
|
618
819
|
/** `new Segmind().chat(...)` with the key from `SEGMIND_API_KEY`. */
|
|
619
820
|
declare const chat: (slug: string, params: ChatParams, options?: RunOptions) => Promise<ChatResponse>;
|
|
620
821
|
/** `new Segmind().chatSync(...)` with the key from `SEGMIND_API_KEY`. */
|
|
@@ -622,25 +823,24 @@ declare const chatSync: (slug: string, params: ChatParams, options?: CallOptions
|
|
|
622
823
|
/** `new Segmind().submitChat(...)` with the key from `SEGMIND_API_KEY`. */
|
|
623
824
|
declare const submitChat: (slug: string, params: ChatParams, options?: SubmitOptions) => Promise<Job<ChatResponse>>;
|
|
624
825
|
/** `new Segmind().models` with the key from `SEGMIND_API_KEY`. */
|
|
625
|
-
declare const models:
|
|
626
|
-
list: (options?: {
|
|
627
|
-
signal?: AbortSignal;
|
|
628
|
-
}) => Promise<ModelsListResponse>;
|
|
629
|
-
};
|
|
826
|
+
declare const models: Pick<Models, 'list' | 'listAll'>;
|
|
630
827
|
/** `new Segmind().accounts` with the key from `SEGMIND_API_KEY`. */
|
|
631
828
|
declare const accounts: {
|
|
632
829
|
current: (options?: {
|
|
633
830
|
signal?: AbortSignal;
|
|
634
831
|
}) => Promise<Record<string, unknown>>;
|
|
832
|
+
credits: (options?: {
|
|
833
|
+
signal?: AbortSignal;
|
|
834
|
+
}) => Promise<AccountCredits>;
|
|
635
835
|
};
|
|
636
836
|
/** `new Segmind().files` with the key from `SEGMIND_API_KEY`. */
|
|
637
837
|
declare const files: Pick<Files, 'upload'>;
|
|
638
838
|
/** `new Segmind().generations` with the key from `SEGMIND_API_KEY`. */
|
|
639
839
|
declare const generations: Pick<Generations, 'list' | 'recent' | 'history' | 'get'>;
|
|
640
840
|
/** `new Segmind().webhooks` with the key from `SEGMIND_API_KEY`. */
|
|
641
|
-
declare const webhooks: Pick<Webhooks, 'get' | 'add' | 'update' | 'delete' | 'logs'>;
|
|
841
|
+
declare const webhooks: Pick<Webhooks, 'get' | 'add' | 'update' | 'delete' | 'logs' | 'test' | 'resend'>;
|
|
642
842
|
/** `new Segmind().pixelflows` with the key from `SEGMIND_API_KEY`. */
|
|
643
843
|
declare const pixelflows: Pick<PixelFlows, 'run' | 'submit' | 'getStatus' | 'poll'>;
|
|
644
844
|
|
|
645
|
-
export { APIConnectionError, Accounts, ChatResponse, DEFAULT_BASE_URL, DEFAULT_CONSOLE_URL, DEFAULT_SPOT_URL, DEFAULT_WAIT_INTERVAL_MS, DEFAULT_WAIT_TIMEOUT_MS, Files, Generations, InferenceFailed, InferenceTimeout, Job, Models, PixelFlows, PixelflowJob, Segmind, SegmindError, VERSION, Webhooks, accounts, chat, chatSync, files, generations, imageUrl, models, pixelflows, run, runSync, submit, submitChat, webhooks };
|
|
646
|
-
export type { CallOptions, ChatMessage, ChatParams, ClientOptions, FileInput, Generation, GenerationsListOptions, HistoryOptions, ImageInput, ImageUrlPart, JobState, JobStatus, ModelInfo,
|
|
845
|
+
export { APIConnectionError, Accounts, ChatResponse, DEFAULT_BASE_URL, DEFAULT_CONSOLE_URL, DEFAULT_SPOT_URL, DEFAULT_WAIT_INTERVAL_MS, DEFAULT_WAIT_TIMEOUT_MS, Files, Generations, InferenceFailed, InferenceTimeout, InsufficientCredits, Job, Models, PixelFlows, PixelflowJob, RateLimited, Segmind, SegmindError, VERSION, Webhooks, accounts, chat, chatSync, files, generations, imageUrl, job, models, pixelflows, run, runSync, submit, submitChat, webhooks };
|
|
846
|
+
export type { AccountCredits, CallOptions, ChatMessage, ChatParams, ClientOptions, FileInput, Generation, GenerationsListOptions, HistoryOptions, ImageInput, ImageUrlPart, Initiator, InitiatorOptions, JobState, JobStatus, ModelInfo, ModelInput, ModelListParams, ModelOutput, ModelSort, ModelsPage, Page, Params, PixelflowStatus, PixelflowSubmitOptions, PixelflowWaitOptions, PollInterval, RequestRecord, RunOptions, RunResult, SubmitOptions, SubmitResponse, TokenProvider, UploadOptions, UploadedFile, WaitOptions, Webhook, WebhookDelivery, WebhookEventType };
|