segmind 0.0.1 → 0.2.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 +201 -0
- package/README.md +160 -3
- package/dist/index.cjs +1045 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +614 -0
- package/dist/index.d.ts +614 -0
- package/dist/index.js +1012 -0
- package/dist/index.js.map +1 -0
- package/package.json +41 -6
- package/index.js +0 -4
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,614 @@
|
|
|
1
|
+
/** Model inputs, forwarded to the model exactly as given. */
|
|
2
|
+
type Params = Record<string, unknown>;
|
|
3
|
+
/** A v2 request's state. */
|
|
4
|
+
type JobState = 'QUEUED' | 'PROCESSING' | 'COMPLETED' | 'FAILED';
|
|
5
|
+
/**
|
|
6
|
+
* The body of a finished v2 request. Every model returns `status`, `output`
|
|
7
|
+
* and `metrics`; the rest is model-specific, so do not assume a fixed key set.
|
|
8
|
+
*/
|
|
9
|
+
interface RunResult {
|
|
10
|
+
status?: JobState | string;
|
|
11
|
+
output?: unknown;
|
|
12
|
+
request_id?: string;
|
|
13
|
+
metrics?: Record<string, unknown>;
|
|
14
|
+
[key: string]: unknown;
|
|
15
|
+
}
|
|
16
|
+
/** `GET /v2/requests/{id}/status`. */
|
|
17
|
+
interface JobStatus {
|
|
18
|
+
status: JobState | string;
|
|
19
|
+
request_id?: string;
|
|
20
|
+
status_url?: string;
|
|
21
|
+
response_url?: string;
|
|
22
|
+
metrics?: Record<string, unknown>;
|
|
23
|
+
model?: string;
|
|
24
|
+
error?: string;
|
|
25
|
+
retry_count?: number;
|
|
26
|
+
[key: string]: unknown;
|
|
27
|
+
}
|
|
28
|
+
/** `POST /v2/{slug}` (also the body of a 409 for a repeated `X-Request-ID`). */
|
|
29
|
+
interface SubmitResponse {
|
|
30
|
+
request_id: string;
|
|
31
|
+
status: JobState | string;
|
|
32
|
+
status_url: string;
|
|
33
|
+
response_url: string;
|
|
34
|
+
poll_url?: string;
|
|
35
|
+
[key: string]: unknown;
|
|
36
|
+
}
|
|
37
|
+
interface CallOptions {
|
|
38
|
+
/** Cancels the call. */
|
|
39
|
+
signal?: AbortSignal;
|
|
40
|
+
/** Milliseconds per HTTP request; defaults to the client's `timeout`. */
|
|
41
|
+
timeout?: number;
|
|
42
|
+
}
|
|
43
|
+
interface SubmitOptions {
|
|
44
|
+
signal?: AbortSignal;
|
|
45
|
+
/**
|
|
46
|
+
* Idempotency key sent as `X-Request-ID` ([A-Za-z0-9_-]{8,128}). Submitting
|
|
47
|
+
* again with the same id returns the existing request instead of a new one.
|
|
48
|
+
* Generated when omitted.
|
|
49
|
+
*/
|
|
50
|
+
requestId?: string;
|
|
51
|
+
}
|
|
52
|
+
interface WaitOptions {
|
|
53
|
+
signal?: AbortSignal;
|
|
54
|
+
/** Give up after this many milliseconds. Default 600 000 (10 minutes). */
|
|
55
|
+
timeout?: number;
|
|
56
|
+
/** Milliseconds between status checks. Default 1000. */
|
|
57
|
+
interval?: number;
|
|
58
|
+
}
|
|
59
|
+
type RunOptions = SubmitOptions & WaitOptions;
|
|
60
|
+
|
|
61
|
+
/** An OpenAI-style chat message; content may be text or a list of parts. */
|
|
62
|
+
interface ChatMessage {
|
|
63
|
+
role: 'system' | 'developer' | 'user' | 'assistant' | 'tool' | (string & {});
|
|
64
|
+
content: string | Array<Record<string, unknown>>;
|
|
65
|
+
[key: string]: unknown;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Chat inputs: `messages` or `prompt` (at least one), plus any model params.
|
|
69
|
+
* `messages` is a list for OpenAI- and Anthropic-style models; Gemini models
|
|
70
|
+
* take their own object (`{ system_instruction, contents }`), sent unchanged.
|
|
71
|
+
*/
|
|
72
|
+
type ChatParams = Params & {
|
|
73
|
+
messages?: ChatMessage[] | Record<string, unknown>;
|
|
74
|
+
prompt?: string;
|
|
75
|
+
};
|
|
76
|
+
type Raw = Record<string, unknown>;
|
|
77
|
+
/**
|
|
78
|
+
* One reply from any chat model. The gateway returns each provider's own JSON
|
|
79
|
+
* (OpenAI, Anthropic or Gemini shape); this reads the common fields from all
|
|
80
|
+
* three. `raw` is always the provider's body, untouched.
|
|
81
|
+
*/
|
|
82
|
+
declare class ChatResponse {
|
|
83
|
+
readonly raw: Raw;
|
|
84
|
+
constructor(raw: Raw);
|
|
85
|
+
/** The assistant's text. Throws when the body holds none (inspect `raw`). */
|
|
86
|
+
get text(): string;
|
|
87
|
+
/** `text` parsed as JSON, for JSON mode and structured outputs. */
|
|
88
|
+
json<T = unknown>(): T;
|
|
89
|
+
/** The provider's token usage (`usage` or Gemini's `usageMetadata`). */
|
|
90
|
+
get usage(): Record<string, unknown> | undefined;
|
|
91
|
+
/** Why generation stopped (`finish_reason`, `stop_reason` or `finishReason`). */
|
|
92
|
+
get finishReason(): string | undefined;
|
|
93
|
+
/** Tool calls in the OpenAI shape, when the model made any. */
|
|
94
|
+
get toolCalls(): unknown[];
|
|
95
|
+
}
|
|
96
|
+
|
|
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
|
+
/** A file to send: a path (Node only), a `Blob` or `File`, or raw bytes. */
|
|
143
|
+
type FileInput = string | Blob | ArrayBuffer | Uint8Array;
|
|
144
|
+
|
|
145
|
+
interface UploadOptions {
|
|
146
|
+
/** The file's name, with an extension: the server types the file from it. */
|
|
147
|
+
filename?: string;
|
|
148
|
+
/** The file's type, when neither the name nor the bytes tell. */
|
|
149
|
+
mimeType?: string;
|
|
150
|
+
signal?: AbortSignal;
|
|
151
|
+
}
|
|
152
|
+
interface UploadedFile {
|
|
153
|
+
/** Public URL to pass as a model input. */
|
|
154
|
+
url: string;
|
|
155
|
+
filename: string;
|
|
156
|
+
size: number;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Uploads files to pass as model inputs. Each file goes straight to storage on
|
|
160
|
+
* a presigned URL, so large videos never travel as base64 JSON. The URLs are
|
|
161
|
+
* public and temporary: the files are kept for at least two days.
|
|
162
|
+
*/
|
|
163
|
+
declare class Files {
|
|
164
|
+
private readonly client;
|
|
165
|
+
constructor(client: Segmind);
|
|
166
|
+
/** Uploads one file and returns its URL. */
|
|
167
|
+
upload(file: FileInput, options?: UploadOptions): Promise<UploadedFile>;
|
|
168
|
+
/** Uploads several files, in order. */
|
|
169
|
+
upload(files: FileInput[], options?: Omit<UploadOptions, 'filename'>): Promise<UploadedFile[]>;
|
|
170
|
+
private uploadOne;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/** One page of a paginated list. */
|
|
174
|
+
interface Page<T> {
|
|
175
|
+
total_records: number;
|
|
176
|
+
total_pages: number;
|
|
177
|
+
current_page: number;
|
|
178
|
+
per_page: number;
|
|
179
|
+
has_next: boolean;
|
|
180
|
+
has_previous: boolean;
|
|
181
|
+
data: T[];
|
|
182
|
+
[key: string]: unknown;
|
|
183
|
+
}
|
|
184
|
+
/** A generated output, with the request behind it. */
|
|
185
|
+
interface Generation {
|
|
186
|
+
request_id: string;
|
|
187
|
+
model_name: string;
|
|
188
|
+
generation_url: string;
|
|
189
|
+
created_at: string;
|
|
190
|
+
status?: string | null;
|
|
191
|
+
/** Cost in USD. */
|
|
192
|
+
credits_deduction?: number | null;
|
|
193
|
+
latency_ms?: number | null;
|
|
194
|
+
prompt?: string | null;
|
|
195
|
+
parameters?: Record<string, unknown> | null;
|
|
196
|
+
[key: string]: unknown;
|
|
197
|
+
}
|
|
198
|
+
/** A request, failed and in-flight ones included. */
|
|
199
|
+
interface RequestRecord {
|
|
200
|
+
request_id: string;
|
|
201
|
+
model_name: string;
|
|
202
|
+
model_status: string;
|
|
203
|
+
/** Cost in USD. */
|
|
204
|
+
credits_deduction: number | null;
|
|
205
|
+
/** The inputs as sent, as a JSON string. */
|
|
206
|
+
request_body?: string | null;
|
|
207
|
+
generation_url?: string | null;
|
|
208
|
+
latency_ms?: number | null;
|
|
209
|
+
model_created?: string;
|
|
210
|
+
error?: string | null;
|
|
211
|
+
[key: string]: unknown;
|
|
212
|
+
}
|
|
213
|
+
interface GenerationsListOptions {
|
|
214
|
+
page?: number;
|
|
215
|
+
modelName?: string;
|
|
216
|
+
/** YYYY-MM-DD. */
|
|
217
|
+
startDate?: string;
|
|
218
|
+
/** YYYY-MM-DD. */
|
|
219
|
+
endDate?: string;
|
|
220
|
+
/** Inside a team, any member's user id; otherwise only your own. */
|
|
221
|
+
userId?: string;
|
|
222
|
+
signal?: AbortSignal;
|
|
223
|
+
}
|
|
224
|
+
interface HistoryOptions {
|
|
225
|
+
page?: number;
|
|
226
|
+
/** 1–100. Default 20. */
|
|
227
|
+
perPage?: number;
|
|
228
|
+
/** YYYY-MM-DD. Default 7 days ago. */
|
|
229
|
+
fromDate?: string;
|
|
230
|
+
/** YYYY-MM-DD, inclusive. Default today. At most 31 days after `fromDate`. */
|
|
231
|
+
toDate?: string;
|
|
232
|
+
/** Substring match on the model slug. */
|
|
233
|
+
modelName?: string;
|
|
234
|
+
status?: 'COMPLETED' | 'FAILED' | 'PENDING';
|
|
235
|
+
/** Inside a team, any member's user id; otherwise only your own. */
|
|
236
|
+
userId?: string;
|
|
237
|
+
/** Same as `userId`, by email. Pass one or the other. */
|
|
238
|
+
userEmail?: string;
|
|
239
|
+
sortBy?: 'model_created' | 'model_name' | 'credits_deduction';
|
|
240
|
+
sortOrder?: 'asc' | 'desc';
|
|
241
|
+
signal?: AbortSignal;
|
|
242
|
+
}
|
|
243
|
+
/** Your generations and request history. */
|
|
244
|
+
declare class Generations {
|
|
245
|
+
private readonly client;
|
|
246
|
+
constructor(client: Segmind);
|
|
247
|
+
/** Generated outputs, newest first. */
|
|
248
|
+
list(options?: GenerationsListOptions): Promise<Page<Generation>>;
|
|
249
|
+
/** The newest generations for one model. */
|
|
250
|
+
recent(modelName: string, options?: {
|
|
251
|
+
signal?: AbortSignal;
|
|
252
|
+
}): Promise<{
|
|
253
|
+
data: Array<Pick<Generation, 'request_id' | 'generation_url' | 'created_at' | 'status'>>;
|
|
254
|
+
}>;
|
|
255
|
+
/**
|
|
256
|
+
* Requests with their cost, inputs and outcome, failures included. A request
|
|
257
|
+
* with several outputs appears once per output, each carrying its full cost:
|
|
258
|
+
* de-duplicate on `request_id` before summing.
|
|
259
|
+
*/
|
|
260
|
+
history(options?: HistoryOptions): Promise<Page<RequestRecord>>;
|
|
261
|
+
/** One of your own requests, of any age. A teammate's request id is not found. */
|
|
262
|
+
get(requestId: string, options?: {
|
|
263
|
+
signal?: AbortSignal;
|
|
264
|
+
}): Promise<RequestRecord>;
|
|
265
|
+
private read;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
declare const DEFAULT_WAIT_TIMEOUT_MS = 600000;
|
|
269
|
+
declare const DEFAULT_WAIT_INTERVAL_MS = 1000;
|
|
270
|
+
/**
|
|
271
|
+
* A submitted v2 request. `wait()` polls until it finishes; `status()` and
|
|
272
|
+
* `result()` read it once.
|
|
273
|
+
*/
|
|
274
|
+
declare class Job<T = RunResult> {
|
|
275
|
+
private readonly http;
|
|
276
|
+
/** The body the submit returned. */
|
|
277
|
+
readonly submitResponse: SubmitResponse;
|
|
278
|
+
private readonly transform;
|
|
279
|
+
readonly requestId: string;
|
|
280
|
+
readonly statusUrl: string;
|
|
281
|
+
readonly responseUrl: string;
|
|
282
|
+
constructor(http: HttpClient,
|
|
283
|
+
/** The body the submit returned. */
|
|
284
|
+
submitResponse: SubmitResponse, transform?: (body: RunResult) => T);
|
|
285
|
+
/** The current state, without waiting. */
|
|
286
|
+
status(options?: {
|
|
287
|
+
signal?: AbortSignal;
|
|
288
|
+
}): Promise<JobStatus>;
|
|
289
|
+
/**
|
|
290
|
+
* The finished result. Throws `InferenceFailed` when the request failed, and
|
|
291
|
+
* a `SegmindError` when it has not finished yet (use `wait()` for that).
|
|
292
|
+
*/
|
|
293
|
+
result(options?: {
|
|
294
|
+
signal?: AbortSignal;
|
|
295
|
+
}): Promise<T>;
|
|
296
|
+
/** Polls until the request finishes, then returns its result. */
|
|
297
|
+
wait(options?: WaitOptions): Promise<T>;
|
|
298
|
+
/**
|
|
299
|
+
* The gateway serves a FAILED request's body with HTTP 422 on both the status
|
|
300
|
+
* and result URLs. A body that names a terminal state is the answer whatever
|
|
301
|
+
* its status code; anything else outside 2xx is a real error.
|
|
302
|
+
*/
|
|
303
|
+
private read;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
interface PixelflowSubmitOptions {
|
|
307
|
+
/**
|
|
308
|
+
* `v2` (default) runs on the current workflow engine, which also loads
|
|
309
|
+
* older graphs. `v1` is the legacy engine.
|
|
310
|
+
*/
|
|
311
|
+
engine?: 'v1' | 'v2';
|
|
312
|
+
signal?: AbortSignal;
|
|
313
|
+
}
|
|
314
|
+
interface PixelflowWaitOptions {
|
|
315
|
+
/** Give up after this many milliseconds. Default 600 000. */
|
|
316
|
+
timeout?: number;
|
|
317
|
+
/** Milliseconds between status checks. Default 2000. */
|
|
318
|
+
interval?: number;
|
|
319
|
+
signal?: AbortSignal;
|
|
320
|
+
}
|
|
321
|
+
interface PixelflowStatus {
|
|
322
|
+
/** `QUEUED`, `PROCESSING`, `COMPLETED` or `FAILED`, upper-cased. */
|
|
323
|
+
status: string;
|
|
324
|
+
/** The finished outputs by keyname, unwrapped to their URL or value. `{}` until done. */
|
|
325
|
+
outputs: Record<string, unknown>;
|
|
326
|
+
/** The engine's own body, with `output` decoded from its JSON string. */
|
|
327
|
+
raw: Record<string, unknown>;
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* Published PixelFlow workflows, run through the gateway. `slug` is the
|
|
331
|
+
* workflow's API slug from its API tab. Inputs are a flat object keyed by each
|
|
332
|
+
* input's keyname: `{ Text_Prompt: 'a red fox' }`.
|
|
333
|
+
*/
|
|
334
|
+
declare class PixelFlows {
|
|
335
|
+
private readonly client;
|
|
336
|
+
constructor(client: Segmind);
|
|
337
|
+
/** Runs a workflow and waits for its outputs. */
|
|
338
|
+
run(slug: string, inputs?: Record<string, unknown>, options?: PixelflowSubmitOptions & PixelflowWaitOptions): Promise<PixelflowStatus>;
|
|
339
|
+
/** Starts a workflow and returns a job to wait on. Never retried: a run bills. */
|
|
340
|
+
submit(slug: string, inputs?: Record<string, unknown>, options?: PixelflowSubmitOptions): Promise<PixelflowJob>;
|
|
341
|
+
/** A run's current state, without waiting. */
|
|
342
|
+
getStatus(requestId: string, options?: {
|
|
343
|
+
signal?: AbortSignal;
|
|
344
|
+
}): Promise<PixelflowStatus>;
|
|
345
|
+
/** Waits for a run started earlier, by its request id. */
|
|
346
|
+
poll(requestId: string, options?: PixelflowWaitOptions): Promise<PixelflowStatus>;
|
|
347
|
+
}
|
|
348
|
+
/** A started workflow run. */
|
|
349
|
+
declare class PixelflowJob {
|
|
350
|
+
private readonly pixelflows;
|
|
351
|
+
readonly requestId: string;
|
|
352
|
+
constructor(pixelflows: PixelFlows, requestId: string);
|
|
353
|
+
status(options?: {
|
|
354
|
+
signal?: AbortSignal;
|
|
355
|
+
}): Promise<PixelflowStatus>;
|
|
356
|
+
/**
|
|
357
|
+
* Polls until the run finishes. Throws `InferenceFailed` (its `detail` names
|
|
358
|
+
* the failing node) or `InferenceTimeout`; the run may still finish after a
|
|
359
|
+
* timeout, so `wait()` can be called again.
|
|
360
|
+
*/
|
|
361
|
+
wait(options?: PixelflowWaitOptions): Promise<PixelflowStatus>;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
/** A webhook registration, as the API returns it. Only the common fields are typed. */
|
|
365
|
+
interface Webhook {
|
|
366
|
+
webhook_id?: string;
|
|
367
|
+
webhook_url?: string;
|
|
368
|
+
event?: {
|
|
369
|
+
types?: string[];
|
|
370
|
+
};
|
|
371
|
+
[key: string]: unknown;
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* Your webhook registrations. Event types are the console's names, such as
|
|
375
|
+
* `PIXELFLOW` and `PIXELFLOW_API_RUN`.
|
|
376
|
+
*/
|
|
377
|
+
declare class Webhooks {
|
|
378
|
+
private readonly client;
|
|
379
|
+
constructor(client: Segmind);
|
|
380
|
+
/** Every registration; `[]` when you have none. */
|
|
381
|
+
get(options?: {
|
|
382
|
+
signal?: AbortSignal;
|
|
383
|
+
}): Promise<Webhook[]>;
|
|
384
|
+
/** Registers an endpoint for the given event types. */
|
|
385
|
+
add(webhookUrl: string, eventTypes: string[], options?: {
|
|
386
|
+
signal?: AbortSignal;
|
|
387
|
+
}): Promise<Record<string, unknown>>;
|
|
388
|
+
/** Changes a registration's URL and event types. */
|
|
389
|
+
update(webhookId: string, webhookUrl: string, eventTypes: string[], options?: {
|
|
390
|
+
signal?: AbortSignal;
|
|
391
|
+
}): Promise<Record<string, unknown>>;
|
|
392
|
+
/** Deactivates a registration. */
|
|
393
|
+
delete(webhookId: string, options?: {
|
|
394
|
+
signal?: AbortSignal;
|
|
395
|
+
}): Promise<Record<string, unknown>>;
|
|
396
|
+
/** Delivery history for one registration. */
|
|
397
|
+
logs(webhookId: string, options?: {
|
|
398
|
+
signal?: AbortSignal;
|
|
399
|
+
}): Promise<Record<string, unknown>>;
|
|
400
|
+
private call;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
declare const DEFAULT_BASE_URL = "https://api.segmind.com";
|
|
404
|
+
declare const DEFAULT_SPOT_URL = "https://api.spotprod.segmind.com";
|
|
405
|
+
declare const DEFAULT_CONSOLE_URL = "https://cloud.segmind.com/api";
|
|
406
|
+
interface ClientOptions {
|
|
407
|
+
/** Your Segmind API key. Defaults to `SEGMIND_API_KEY` from the environment. */
|
|
408
|
+
apiKey?: string;
|
|
409
|
+
/** The inference API root, without `/v1`. Defaults to `SEGMIND_BASE_URL` or https://api.segmind.com. */
|
|
410
|
+
baseURL?: string;
|
|
411
|
+
/** The catalog, history, webhook and upload API. Default https://api.spotprod.segmind.com. */
|
|
412
|
+
spotURL?: string;
|
|
413
|
+
/** The account API. Default https://cloud.segmind.com/api. */
|
|
414
|
+
consoleURL?: string;
|
|
415
|
+
/** Milliseconds per HTTP request. Default 600 000. */
|
|
416
|
+
timeout?: number;
|
|
417
|
+
/** Retries for requests that cannot bill twice. Default 2. */
|
|
418
|
+
maxRetries?: number;
|
|
419
|
+
/** A `fetch` implementation. Defaults to the global one. */
|
|
420
|
+
fetch?: typeof fetch;
|
|
421
|
+
/** Headers added to every request. */
|
|
422
|
+
defaultHeaders?: Record<string, string>;
|
|
423
|
+
/**
|
|
424
|
+
* Allow an API key in a browser or React Native app. Anyone who can open the
|
|
425
|
+
* app can read the key and spend your credits. Prefer calling your own
|
|
426
|
+
* backend, or realtime session tokens.
|
|
427
|
+
*/
|
|
428
|
+
dangerouslyAllowBrowser?: boolean;
|
|
429
|
+
}
|
|
430
|
+
/**
|
|
431
|
+
* The Segmind API client.
|
|
432
|
+
*
|
|
433
|
+
* ```ts
|
|
434
|
+
* const segmind = new Segmind(); // reads SEGMIND_API_KEY
|
|
435
|
+
* const result = await segmind.run('seedream-4.5', { prompt: 'A sunset over mountains' });
|
|
436
|
+
* ```
|
|
437
|
+
*/
|
|
438
|
+
declare class Segmind {
|
|
439
|
+
readonly baseURL: string;
|
|
440
|
+
readonly spotURL: string;
|
|
441
|
+
readonly consoleURL: string;
|
|
442
|
+
readonly models: Models;
|
|
443
|
+
readonly accounts: Accounts;
|
|
444
|
+
/** Upload files to pass as model inputs. */
|
|
445
|
+
readonly files: Files;
|
|
446
|
+
/** Your generations and request history. */
|
|
447
|
+
readonly generations: Generations;
|
|
448
|
+
/** Your webhook registrations. */
|
|
449
|
+
readonly webhooks: Webhooks;
|
|
450
|
+
/** Run published PixelFlow workflows. */
|
|
451
|
+
readonly pixelflows: PixelFlows;
|
|
452
|
+
/** @internal */
|
|
453
|
+
readonly http: HttpClient;
|
|
454
|
+
constructor(options?: ClientOptions);
|
|
455
|
+
/**
|
|
456
|
+
* Runs a model and returns its result: submits to the v2 queue, then polls
|
|
457
|
+
* until it finishes. `params` go to the model unchanged.
|
|
458
|
+
*/
|
|
459
|
+
run(slug: string, params?: Params, options?: RunOptions): Promise<RunResult>;
|
|
460
|
+
/**
|
|
461
|
+
* One blocking `POST /v1/{slug}`. Returns the fetch `Response`: call
|
|
462
|
+
* `.arrayBuffer()` for media or `.json()` for JSON models. Never retried,
|
|
463
|
+
* because the call bills.
|
|
464
|
+
*/
|
|
465
|
+
runSync(slug: string, params?: Params, options?: CallOptions): Promise<Response>;
|
|
466
|
+
/**
|
|
467
|
+
* Submits to the v2 queue and returns a `Job` to wait on. Safe to retry: the
|
|
468
|
+
* submit carries an `X-Request-ID`, and the gateway answers a repeat with
|
|
469
|
+
* the existing request rather than a second one.
|
|
470
|
+
*/
|
|
471
|
+
submit(slug: string, params?: Params, options?: SubmitOptions): Promise<Job>;
|
|
472
|
+
/** Chat with an LLM through the v2 queue. Returns a provider-neutral reply. */
|
|
473
|
+
chat(slug: string, params: ChatParams, options?: RunOptions): Promise<ChatResponse>;
|
|
474
|
+
/** Chat with one blocking `POST /v1/{slug}`. */
|
|
475
|
+
chatSync(slug: string, params: ChatParams, options?: CallOptions): Promise<ChatResponse>;
|
|
476
|
+
/** Submits a chat to the v2 queue and returns a `Job` whose result is a `ChatResponse`. */
|
|
477
|
+
submitChat(slug: string, params: ChatParams, options?: SubmitOptions): Promise<Job<ChatResponse>>;
|
|
478
|
+
private submitJob;
|
|
479
|
+
}
|
|
480
|
+
/** One catalog entry. Only the commonly used fields are typed. */
|
|
481
|
+
interface ModelInfo {
|
|
482
|
+
slug: string;
|
|
483
|
+
title?: string;
|
|
484
|
+
type?: string;
|
|
485
|
+
description?: string;
|
|
486
|
+
is_visible?: boolean;
|
|
487
|
+
is_depreciated?: boolean;
|
|
488
|
+
is_new?: boolean;
|
|
489
|
+
coming_soon?: boolean;
|
|
490
|
+
parameters_schema?: Record<string, unknown>;
|
|
491
|
+
[key: string]: unknown;
|
|
492
|
+
}
|
|
493
|
+
/** The catalog response, as the API returns it. */
|
|
494
|
+
interface ModelsListResponse {
|
|
495
|
+
'Inference Model Information List': ModelInfo[];
|
|
496
|
+
[key: string]: unknown;
|
|
497
|
+
}
|
|
498
|
+
/** The model catalog. */
|
|
499
|
+
declare class Models {
|
|
500
|
+
private readonly client;
|
|
501
|
+
constructor(client: Segmind);
|
|
502
|
+
/** Every model in the catalog, under the key `Inference Model Information List`. */
|
|
503
|
+
list(options?: {
|
|
504
|
+
signal?: AbortSignal;
|
|
505
|
+
}): Promise<ModelsListResponse>;
|
|
506
|
+
}
|
|
507
|
+
/** The account the API key belongs to. */
|
|
508
|
+
declare class Accounts {
|
|
509
|
+
private readonly client;
|
|
510
|
+
constructor(client: Segmind);
|
|
511
|
+
/** Account details for the API key. */
|
|
512
|
+
current(options?: {
|
|
513
|
+
signal?: AbortSignal;
|
|
514
|
+
}): Promise<Record<string, unknown>>;
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
/** An OpenAI-style image part, for the `content` list of a chat message. */
|
|
518
|
+
interface ImageUrlPart {
|
|
519
|
+
type: 'image_url';
|
|
520
|
+
image_url: {
|
|
521
|
+
url: string;
|
|
522
|
+
};
|
|
523
|
+
}
|
|
524
|
+
type ImageInput = FileInput;
|
|
525
|
+
/**
|
|
526
|
+
* Builds an image part for a chat message.
|
|
527
|
+
*
|
|
528
|
+
* - An `http(s)://` or `data:` URL passes through.
|
|
529
|
+
* - A file path (Node only) is read and inlined as a base64 `data:` URI.
|
|
530
|
+
* - A `Blob`, `ArrayBuffer` or `Uint8Array` is inlined; pass `mimeType` when
|
|
531
|
+
* it cannot be told from the blob or the bytes.
|
|
532
|
+
*
|
|
533
|
+
* Inlining is the safer route: the gateway cannot fetch URLs on every host.
|
|
534
|
+
*/
|
|
535
|
+
declare function imageUrl(input: ImageInput, options?: {
|
|
536
|
+
mimeType?: string;
|
|
537
|
+
}): Promise<ImageUrlPart>;
|
|
538
|
+
|
|
539
|
+
interface SegmindErrorOptions {
|
|
540
|
+
status?: number;
|
|
541
|
+
detail?: string;
|
|
542
|
+
requestId?: string;
|
|
543
|
+
body?: unknown;
|
|
544
|
+
cause?: unknown;
|
|
545
|
+
}
|
|
546
|
+
/** Base class of every error the SDK throws (except an `AbortSignal`'s own reason). */
|
|
547
|
+
declare class SegmindError extends Error {
|
|
548
|
+
/** HTTP status, when the error came from a response. */
|
|
549
|
+
readonly status: number | undefined;
|
|
550
|
+
/** The server's error text (`error` in the response body), when it sent one. */
|
|
551
|
+
readonly detail: string | undefined;
|
|
552
|
+
/** The v2 request id the error belongs to, when there is one. */
|
|
553
|
+
readonly requestId: string | undefined;
|
|
554
|
+
/** The parsed response body, or its text when it was not JSON. */
|
|
555
|
+
readonly body: unknown;
|
|
556
|
+
constructor(message: string, options?: SegmindErrorOptions);
|
|
557
|
+
/** Reads the response body and builds the error. Consumes the body. */
|
|
558
|
+
static fromResponse(response: Response, requestId?: string): Promise<SegmindError>;
|
|
559
|
+
}
|
|
560
|
+
/** The request never got a response: DNS, TLS, connection reset, or the client's timeout. */
|
|
561
|
+
declare class APIConnectionError extends SegmindError {
|
|
562
|
+
}
|
|
563
|
+
/** A v2 request reached `FAILED`. The server's error text is in `detail`. */
|
|
564
|
+
declare class InferenceFailed extends SegmindError {
|
|
565
|
+
/** The status body that reported the failure. */
|
|
566
|
+
readonly statusBody: Record<string, unknown>;
|
|
567
|
+
constructor(requestId: string, statusBody: Record<string, unknown>, detail?: string);
|
|
568
|
+
}
|
|
569
|
+
/**
|
|
570
|
+
* `wait()` ran past its timeout. The request may still finish on the server:
|
|
571
|
+
* `job.status()` or a new `wait()` picks it up again.
|
|
572
|
+
*/
|
|
573
|
+
declare class InferenceTimeout extends SegmindError {
|
|
574
|
+
readonly elapsedMs: number;
|
|
575
|
+
constructor(requestId: string, elapsedMs: number);
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
declare const VERSION = "0.2.0";
|
|
579
|
+
|
|
580
|
+
/** `new Segmind().run(...)` with the key from `SEGMIND_API_KEY`. */
|
|
581
|
+
declare const run: (slug: string, params?: Params, options?: RunOptions) => Promise<RunResult>;
|
|
582
|
+
/** `new Segmind().runSync(...)` with the key from `SEGMIND_API_KEY`. */
|
|
583
|
+
declare const runSync: (slug: string, params?: Params, options?: CallOptions) => Promise<Response>;
|
|
584
|
+
/** `new Segmind().submit(...)` with the key from `SEGMIND_API_KEY`. */
|
|
585
|
+
declare const submit: (slug: string, params?: Params, options?: SubmitOptions) => Promise<Job>;
|
|
586
|
+
/** `new Segmind().chat(...)` with the key from `SEGMIND_API_KEY`. */
|
|
587
|
+
declare const chat: (slug: string, params: ChatParams, options?: RunOptions) => Promise<ChatResponse>;
|
|
588
|
+
/** `new Segmind().chatSync(...)` with the key from `SEGMIND_API_KEY`. */
|
|
589
|
+
declare const chatSync: (slug: string, params: ChatParams, options?: CallOptions) => Promise<ChatResponse>;
|
|
590
|
+
/** `new Segmind().submitChat(...)` with the key from `SEGMIND_API_KEY`. */
|
|
591
|
+
declare const submitChat: (slug: string, params: ChatParams, options?: SubmitOptions) => Promise<Job<ChatResponse>>;
|
|
592
|
+
/** `new Segmind().models` with the key from `SEGMIND_API_KEY`. */
|
|
593
|
+
declare const models: {
|
|
594
|
+
list: (options?: {
|
|
595
|
+
signal?: AbortSignal;
|
|
596
|
+
}) => Promise<ModelsListResponse>;
|
|
597
|
+
};
|
|
598
|
+
/** `new Segmind().accounts` with the key from `SEGMIND_API_KEY`. */
|
|
599
|
+
declare const accounts: {
|
|
600
|
+
current: (options?: {
|
|
601
|
+
signal?: AbortSignal;
|
|
602
|
+
}) => Promise<Record<string, unknown>>;
|
|
603
|
+
};
|
|
604
|
+
/** `new Segmind().files` with the key from `SEGMIND_API_KEY`. */
|
|
605
|
+
declare const files: Pick<Files, 'upload'>;
|
|
606
|
+
/** `new Segmind().generations` with the key from `SEGMIND_API_KEY`. */
|
|
607
|
+
declare const generations: Pick<Generations, 'list' | 'recent' | 'history' | 'get'>;
|
|
608
|
+
/** `new Segmind().webhooks` with the key from `SEGMIND_API_KEY`. */
|
|
609
|
+
declare const webhooks: Pick<Webhooks, 'get' | 'add' | 'update' | 'delete' | 'logs'>;
|
|
610
|
+
/** `new Segmind().pixelflows` with the key from `SEGMIND_API_KEY`. */
|
|
611
|
+
declare const pixelflows: Pick<PixelFlows, 'run' | 'submit' | 'getStatus' | 'poll'>;
|
|
612
|
+
|
|
613
|
+
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 };
|
|
614
|
+
export type { CallOptions, ChatMessage, ChatParams, ClientOptions, FileInput, Generation, GenerationsListOptions, HistoryOptions, ImageInput, ImageUrlPart, JobState, JobStatus, ModelInfo, ModelsListResponse, Page, Params, PixelflowStatus, PixelflowSubmitOptions, PixelflowWaitOptions, RequestRecord, RunOptions, RunResult, SubmitOptions, SubmitResponse, UploadOptions, UploadedFile, WaitOptions, Webhook };
|