segmind 0.1.0 → 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/dist/index.d.cts CHANGED
@@ -64,9 +64,13 @@ interface ChatMessage {
64
64
  content: string | Array<Record<string, unknown>>;
65
65
  [key: string]: unknown;
66
66
  }
67
- /** Chat inputs: `messages` or `prompt` (at least one), plus any model params. */
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
+ */
68
72
  type ChatParams = Params & {
69
- messages?: ChatMessage[];
73
+ messages?: ChatMessage[] | Record<string, unknown>;
70
74
  prompt?: string;
71
75
  };
72
76
  type Raw = Record<string, unknown>;
@@ -101,8 +105,17 @@ interface HttpConfig {
101
105
  interface HttpRequest {
102
106
  method: HttpMethod;
103
107
  url: string;
108
+ /** Query parameters; `undefined` values are left out. */
109
+ query?: Record<string, string | number | boolean | undefined>;
104
110
  /** Sent as JSON. */
105
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;
106
119
  headers?: Record<string, string>;
107
120
  signal?: AbortSignal;
108
121
  /** Milliseconds for this attempt; defaults to the client's timeout. */
@@ -126,6 +139,132 @@ declare class HttpClient {
126
139
  private attempt;
127
140
  }
128
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
+
129
268
  declare const DEFAULT_WAIT_TIMEOUT_MS = 600000;
130
269
  declare const DEFAULT_WAIT_INTERVAL_MS = 1000;
131
270
  /**
@@ -164,6 +303,103 @@ declare class Job<T = RunResult> {
164
303
  private read;
165
304
  }
166
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
+
167
403
  declare const DEFAULT_BASE_URL = "https://api.segmind.com";
168
404
  declare const DEFAULT_SPOT_URL = "https://api.spotprod.segmind.com";
169
405
  declare const DEFAULT_CONSOLE_URL = "https://cloud.segmind.com/api";
@@ -172,7 +408,7 @@ interface ClientOptions {
172
408
  apiKey?: string;
173
409
  /** The inference API root, without `/v1`. Defaults to `SEGMIND_BASE_URL` or https://api.segmind.com. */
174
410
  baseURL?: string;
175
- /** The catalog and history API. Default https://api.spotprod.segmind.com. */
411
+ /** The catalog, history, webhook and upload API. Default https://api.spotprod.segmind.com. */
176
412
  spotURL?: string;
177
413
  /** The account API. Default https://cloud.segmind.com/api. */
178
414
  consoleURL?: string;
@@ -205,6 +441,14 @@ declare class Segmind {
205
441
  readonly consoleURL: string;
206
442
  readonly models: Models;
207
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;
208
452
  /** @internal */
209
453
  readonly http: HttpClient;
210
454
  constructor(options?: ClientOptions);
@@ -277,7 +521,7 @@ interface ImageUrlPart {
277
521
  url: string;
278
522
  };
279
523
  }
280
- type ImageInput = string | Blob | ArrayBuffer | Uint8Array;
524
+ type ImageInput = FileInput;
281
525
  /**
282
526
  * Builds an image part for a chat message.
283
527
  *
@@ -320,7 +564,7 @@ declare class APIConnectionError extends SegmindError {
320
564
  declare class InferenceFailed extends SegmindError {
321
565
  /** The status body that reported the failure. */
322
566
  readonly statusBody: Record<string, unknown>;
323
- constructor(requestId: string, statusBody: Record<string, unknown>);
567
+ constructor(requestId: string, statusBody: Record<string, unknown>, detail?: string);
324
568
  }
325
569
  /**
326
570
  * `wait()` ran past its timeout. The request may still finish on the server:
@@ -331,7 +575,7 @@ declare class InferenceTimeout extends SegmindError {
331
575
  constructor(requestId: string, elapsedMs: number);
332
576
  }
333
577
 
334
- declare const VERSION = "0.1.0";
578
+ declare const VERSION = "0.2.0";
335
579
 
336
580
  /** `new Segmind().run(...)` with the key from `SEGMIND_API_KEY`. */
337
581
  declare const run: (slug: string, params?: Params, options?: RunOptions) => Promise<RunResult>;
@@ -357,6 +601,14 @@ declare const accounts: {
357
601
  signal?: AbortSignal;
358
602
  }) => Promise<Record<string, unknown>>;
359
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'>;
360
612
 
361
- export { APIConnectionError, Accounts, ChatResponse, DEFAULT_BASE_URL, DEFAULT_CONSOLE_URL, DEFAULT_SPOT_URL, DEFAULT_WAIT_INTERVAL_MS, DEFAULT_WAIT_TIMEOUT_MS, InferenceFailed, InferenceTimeout, Job, Models, Segmind, SegmindError, VERSION, accounts, chat, chatSync, imageUrl, models, run, runSync, submit, submitChat };
362
- export type { CallOptions, ChatMessage, ChatParams, ClientOptions, ImageInput, ImageUrlPart, JobState, JobStatus, ModelInfo, ModelsListResponse, Params, RunOptions, RunResult, SubmitOptions, SubmitResponse, WaitOptions };
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 };
package/dist/index.d.ts CHANGED
@@ -64,9 +64,13 @@ interface ChatMessage {
64
64
  content: string | Array<Record<string, unknown>>;
65
65
  [key: string]: unknown;
66
66
  }
67
- /** Chat inputs: `messages` or `prompt` (at least one), plus any model params. */
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
+ */
68
72
  type ChatParams = Params & {
69
- messages?: ChatMessage[];
73
+ messages?: ChatMessage[] | Record<string, unknown>;
70
74
  prompt?: string;
71
75
  };
72
76
  type Raw = Record<string, unknown>;
@@ -101,8 +105,17 @@ interface HttpConfig {
101
105
  interface HttpRequest {
102
106
  method: HttpMethod;
103
107
  url: string;
108
+ /** Query parameters; `undefined` values are left out. */
109
+ query?: Record<string, string | number | boolean | undefined>;
104
110
  /** Sent as JSON. */
105
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;
106
119
  headers?: Record<string, string>;
107
120
  signal?: AbortSignal;
108
121
  /** Milliseconds for this attempt; defaults to the client's timeout. */
@@ -126,6 +139,132 @@ declare class HttpClient {
126
139
  private attempt;
127
140
  }
128
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
+
129
268
  declare const DEFAULT_WAIT_TIMEOUT_MS = 600000;
130
269
  declare const DEFAULT_WAIT_INTERVAL_MS = 1000;
131
270
  /**
@@ -164,6 +303,103 @@ declare class Job<T = RunResult> {
164
303
  private read;
165
304
  }
166
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
+
167
403
  declare const DEFAULT_BASE_URL = "https://api.segmind.com";
168
404
  declare const DEFAULT_SPOT_URL = "https://api.spotprod.segmind.com";
169
405
  declare const DEFAULT_CONSOLE_URL = "https://cloud.segmind.com/api";
@@ -172,7 +408,7 @@ interface ClientOptions {
172
408
  apiKey?: string;
173
409
  /** The inference API root, without `/v1`. Defaults to `SEGMIND_BASE_URL` or https://api.segmind.com. */
174
410
  baseURL?: string;
175
- /** The catalog and history API. Default https://api.spotprod.segmind.com. */
411
+ /** The catalog, history, webhook and upload API. Default https://api.spotprod.segmind.com. */
176
412
  spotURL?: string;
177
413
  /** The account API. Default https://cloud.segmind.com/api. */
178
414
  consoleURL?: string;
@@ -205,6 +441,14 @@ declare class Segmind {
205
441
  readonly consoleURL: string;
206
442
  readonly models: Models;
207
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;
208
452
  /** @internal */
209
453
  readonly http: HttpClient;
210
454
  constructor(options?: ClientOptions);
@@ -277,7 +521,7 @@ interface ImageUrlPart {
277
521
  url: string;
278
522
  };
279
523
  }
280
- type ImageInput = string | Blob | ArrayBuffer | Uint8Array;
524
+ type ImageInput = FileInput;
281
525
  /**
282
526
  * Builds an image part for a chat message.
283
527
  *
@@ -320,7 +564,7 @@ declare class APIConnectionError extends SegmindError {
320
564
  declare class InferenceFailed extends SegmindError {
321
565
  /** The status body that reported the failure. */
322
566
  readonly statusBody: Record<string, unknown>;
323
- constructor(requestId: string, statusBody: Record<string, unknown>);
567
+ constructor(requestId: string, statusBody: Record<string, unknown>, detail?: string);
324
568
  }
325
569
  /**
326
570
  * `wait()` ran past its timeout. The request may still finish on the server:
@@ -331,7 +575,7 @@ declare class InferenceTimeout extends SegmindError {
331
575
  constructor(requestId: string, elapsedMs: number);
332
576
  }
333
577
 
334
- declare const VERSION = "0.1.0";
578
+ declare const VERSION = "0.2.0";
335
579
 
336
580
  /** `new Segmind().run(...)` with the key from `SEGMIND_API_KEY`. */
337
581
  declare const run: (slug: string, params?: Params, options?: RunOptions) => Promise<RunResult>;
@@ -357,6 +601,14 @@ declare const accounts: {
357
601
  signal?: AbortSignal;
358
602
  }) => Promise<Record<string, unknown>>;
359
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'>;
360
612
 
361
- export { APIConnectionError, Accounts, ChatResponse, DEFAULT_BASE_URL, DEFAULT_CONSOLE_URL, DEFAULT_SPOT_URL, DEFAULT_WAIT_INTERVAL_MS, DEFAULT_WAIT_TIMEOUT_MS, InferenceFailed, InferenceTimeout, Job, Models, Segmind, SegmindError, VERSION, accounts, chat, chatSync, imageUrl, models, run, runSync, submit, submitChat };
362
- export type { CallOptions, ChatMessage, ChatParams, ClientOptions, ImageInput, ImageUrlPart, JobState, JobStatus, ModelInfo, ModelsListResponse, Params, RunOptions, RunResult, SubmitOptions, SubmitResponse, WaitOptions };
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 };