@picsart/ai-sdk 5.40.0 → 6.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/index.d.ts CHANGED
@@ -12,7 +12,6 @@ interface WorkflowJobHandle {
12
12
  workflow: string;
13
13
  id: string;
14
14
  }
15
- type WorkflowStatus = 'ACCEPTED' | 'IN_PROGRESS' | 'COMPLETED' | 'FAILED' | 'CANCELED' | 'UNKNOWN';
16
15
  interface WorkflowProgress {
17
16
  percent?: number;
18
17
  estimatedSecondsLeft?: number;
@@ -44,45 +43,59 @@ interface CreditUsage {
44
43
  /** The remaining balance. */
45
44
  balance?: number;
46
45
  }
47
- interface WorkflowStatusResult<TResult = unknown> {
48
- handle: WorkflowJobHandle;
49
- status: WorkflowStatus;
46
+ interface WorkflowPollOptions {
47
+ intervalMs?: number;
48
+ maxAttempts?: number;
49
+ signal?: AbortSignal;
50
+ }
51
+ /**
52
+ * What a transport hands back from `execute` / `poll` / `status`: the task
53
+ * result the SDK parses, the platform's credit usage, and — when the
54
+ * transport has an envelope distinct from the result — the raw payload
55
+ * (text models read it as a fallback).
56
+ */
57
+ interface TransportResult<TResult = unknown> {
50
58
  result?: TResult;
51
- error?: string;
52
- /** Platform error `reason` on a failed task, when the response carried one. */
53
- reason?: string;
54
- /** Numeric status on the error payload, when the response carried one. */
55
- statusCode?: number;
56
- progress?: WorkflowProgress;
57
- /** Credit usage reported by the platform, when present on the response. */
58
59
  usage?: CreditUsage;
59
- raw: unknown;
60
+ /** Raw payload as the transport received it. Defaults to `result`. */
61
+ raw?: unknown;
62
+ }
63
+ /** Poll controls plus the progress sink `ai.subscribe()` drains. */
64
+ interface TransportPollOptions extends WorkflowPollOptions {
65
+ onProgress?: (progress: WorkflowProgress) => void;
60
66
  }
61
67
  /**
62
- * The transport contract for talking to the workflows backend.
68
+ * The transport contract for talking to the generation backend — the one seam
69
+ * every SDK request passes through. `createClient({ apiUrl, apiKey })` builds
70
+ * the default implementation over @picsart/workflows-client;
71
+ * `createClient({ transport })` replaces it wholesale (a different gateway, a
72
+ * signed proxy, a test double).
63
73
  *
64
- * `execute` (one-shot synchronous generation) is the only required method.
65
- * `submit` + `status` are the async submit-and-poll pair — optional, so an
66
- * execute-only transport can omit them. `options` is the SDK-level
67
- * credit-estimation call. When a transport omits `submit`, the client routes
68
- * all generation through `execute`; calling the async lifecycle methods
69
- * (submit/status/result/subscribe) on such a client throws.
74
+ * `execute` (one-shot synchronous run) is the only required method — it serves
75
+ * `syncExecute` models and every catalog task. `submit` + `poll` are the async
76
+ * submit-and-wait pair: when either is missing, the client routes ALL
77
+ * generation through `execute`, and the async lifecycle (`submit()` /
78
+ * `result()` / `subscribe()`) rejects with `unsupported_transport`. `status` is
79
+ * a single non-blocking read, used to probe which route a bare generation id
80
+ * was submitted on; `options` is the credit-estimation call behind
81
+ * `getCredits()`. Omitted optional methods degrade the matching feature rather
82
+ * than breaking the client.
83
+ *
84
+ * Failures should be thrown as {@link ApiError} — anything else reaches the
85
+ * caller as a 502 `generation_failed`. An `AbortError` is never wrapped.
70
86
  */
71
87
  interface SdkTransport<TPayload = Record<string, unknown>> {
72
- execute(request: WorkflowSubmitRequest<TPayload>): Promise<unknown>;
73
- submit?(request: WorkflowSubmitRequest<TPayload>): Promise<WorkflowJobHandle>;
74
- status?(handle: WorkflowJobHandle, signal?: AbortSignal): Promise<unknown>;
88
+ /** One-shot synchronous run: submit and return the finished result. */
89
+ execute(request: WorkflowSubmitRequest<TPayload>): Promise<TransportResult>;
90
+ /** Start an async job and return its generation id. */
91
+ submit?(request: WorkflowSubmitRequest<TPayload>): Promise<string>;
92
+ /** Wait for a submitted job to reach a terminal state, reporting progress. */
93
+ poll?(handle: WorkflowJobHandle, options?: TransportPollOptions): Promise<TransportResult>;
94
+ /** Read a submitted job's current state in one request — no waiting. */
95
+ status?(handle: WorkflowJobHandle, signal?: AbortSignal): Promise<TransportResult>;
96
+ /** Credits this request would cost, or null when pricing is unavailable. */
75
97
  options?(workflow: string, payload: Record<string, unknown>): Promise<number | null>;
76
98
  }
77
- interface WorkflowPollOptions {
78
- intervalMs?: number;
79
- maxAttempts?: number;
80
- signal?: AbortSignal;
81
- }
82
- interface WorkflowRunOptions extends WorkflowPollOptions {
83
- mode?: 'async' | 'sync';
84
- }
85
- type WorkflowSubscribeOptions = WorkflowPollOptions;
86
99
 
87
100
  /**
88
101
  * Per-model compile-time input contracts generated from specs/vendors catalog.
@@ -848,11 +861,6 @@ type ModelInputById = {
848
861
  prompt: string;
849
862
  imageUrls?: string[];
850
863
  };
851
- "minimax-02-hd": {
852
- language?: string;
853
- accent?: string;
854
- prompt: string;
855
- };
856
864
  "minimax-h3": {
857
865
  prompt: string;
858
866
  startFrame?: string;
@@ -1864,6 +1872,8 @@ type ApiSchemas = WorkflowTypes;
1864
1872
  * The `ai.apis` surface — direct, low-level access to the Picsart model APIs.
1865
1873
  * Known API names (keys of {@link ApiSchemas}) get typed params + result;
1866
1874
  * unknown names take an open payload and return an unknown result.
1875
+ *
1876
+ * Failures arrive as {@link ApiError}, the same as the generation surface.
1867
1877
  */
1868
1878
  interface ApisClient {
1869
1879
  /** Run an API by name (mirrors WorkflowsClient.run()). */
@@ -2071,8 +2081,6 @@ interface ModelParamsAccessor {
2071
2081
  hasFileInput(): boolean;
2072
2082
  getDefault(key: string): unknown;
2073
2083
  getDefaults(): Record<string, unknown>;
2074
- /** @deprecated Use `enum(key)` instead — returns full `EnumEntry` with `.options`, `.default`, etc. */
2075
- getEnumOptions(key: string): (string | number)[] | null;
2076
2084
  toSchema(): ModelParamSchema;
2077
2085
  transferValues(prev: Record<string, unknown>): Record<string, unknown>;
2078
2086
  }
@@ -2108,7 +2116,7 @@ interface CreditTier {
2108
2116
  }
2109
2117
  /** Top-level model accessor with grouped sub-accessors. */
2110
2118
  /** Result of validating generation input against a model's params. */
2111
- interface ValidationResult$1 {
2119
+ interface ValidationResult {
2112
2120
  valid: boolean;
2113
2121
  errors?: string[];
2114
2122
  }
@@ -2121,7 +2129,7 @@ interface ModelDescriptor {
2121
2129
  meta(): ModelMeta;
2122
2130
  /** Validate generation input against this model's params. Returns
2123
2131
  * `{ valid: true }` or `{ valid: false, errors }` — never throws. */
2124
- validate(input: unknown): ValidationResult$1;
2132
+ validate(input: unknown): ValidationResult;
2125
2133
  /** Get the credit range for this model, plus the per-tier breakdown in
2126
2134
  * `.tiers`. Pass context to narrow by resolution/audio. Returns the per-unit
2127
2135
  * range — callers with time-based parameters should scale by the value
@@ -2137,15 +2145,15 @@ interface ModelDescriptor {
2137
2145
  };
2138
2146
  }
2139
2147
  /** Filter criteria for `catalog.find()`. */
2140
- interface ModelFilter$1 {
2148
+ interface ModelFilter {
2141
2149
  output?: GenerationMode;
2142
2150
  provider?: string;
2143
2151
  /**
2144
2152
  * Release tiers to include. Omitted ⇒ the default visible set
2145
2153
  * (`['production', 'general-availability']`). List the tiers you want
2146
2154
  * explicitly to opt into `preview` — e.g. `['preview']` for stage-only
2147
- * models, or all three to include everything. `disabled`/`deprecated`
2148
- * models stay hidden regardless.
2155
+ * models, or all three to include everything. `deprecated` models stay
2156
+ * hidden regardless.
2149
2157
  */
2150
2158
  release?: ReleaseTag[];
2151
2159
  }
@@ -2331,17 +2339,12 @@ interface ModelDefinition {
2331
2339
  badge?: BadgeType[];
2332
2340
  /** ISO YYYY-MM-DD date the model was added. The 'new' badge is derived from this — see core/badges.ts. */
2333
2341
  addedAt?: string;
2334
- /**
2335
- * Marks a model as operationally unavailable — backend not deployed,
2336
- * pricing unconfirmed, catalog/runtime mismatch, etc. Expected to flip
2337
- * back on once the gate clears. Hidden from default catalog lookups.
2338
- */
2339
- disabled?: boolean;
2340
2342
  /**
2341
2343
  * Marks a model as retired — superseded by a newer model or otherwise no
2342
2344
  * longer offered. Will not come back. Catalog row stays so workflow IDs
2343
2345
  * and toolIds remain resolvable for historical jobs and pricing. Hidden
2344
- * from default catalog lookups, same as `disabled`.
2346
+ * from default catalog lookups. (Operationally-gated models use
2347
+ * `release: 'preview'` instead.)
2345
2348
  */
2346
2349
  deprecated?: boolean;
2347
2350
  release?: ReleaseTag;
@@ -2414,8 +2417,6 @@ interface CatalogResult {
2414
2417
  /** `null` when the list is complete. */
2415
2418
  nextCursor: string | null;
2416
2419
  }
2417
- /** @deprecated No longer drives behavior — catalogs are addressed by param key. */
2418
- type CatalogKind = 'voices' | 'avatars';
2419
2420
  /** Binds a param's options to a platform catalog task. */
2420
2421
  interface CatalogSource {
2421
2422
  /** Catalog workflow name, e.g. `heygen/v1/catalog/voices`. */
@@ -2482,6 +2483,78 @@ interface CatalogsOptions {
2482
2483
  preload?: boolean;
2483
2484
  }
2484
2485
 
2486
+ /**
2487
+ * Per-item vendor metadata promoted from the response. Every key is
2488
+ * best-effort: present when the vendor reports it, absent otherwise.
2489
+ */
2490
+ interface GenerateResultItemMetadata {
2491
+ /** Explore image id (recraft explore models) — pass back as `sourceImageId`
2492
+ * to iterate on this image. */
2493
+ exploreImageId?: string;
2494
+ /** Voice preview id (ElevenLabs voice design/remix) — pass to the vendor's
2495
+ * create-voice-from-preview step to persist the voice. */
2496
+ generatedVoiceId?: string;
2497
+ /** URL of the generated video's last frame, when the model was asked for it
2498
+ * (`returnLastFrame`, seedance) — the seed for frame-chaining flows. */
2499
+ lastFrameUrl?: string;
2500
+ }
2501
+
2502
+ /**
2503
+ * Failure codes the SDK synthesizes when the platform supplies no `reason`.
2504
+ * An API-supplied `reason` passes through unchanged, so the open `string`
2505
+ * member keeps arbitrary platform reasons assignable while preserving
2506
+ * autocomplete on the known set.
2507
+ */
2508
+ type ApiErrorCode = 'unknown_model' | 'wrong_model_mode' | 'validation_error' | 'unsupported_transport' | 'timeout' | 'aborted' | 'canceled' | 'generation_failed' | 'invalid_response' | 'bad_request' | 'unauthorized' | 'payment_required' | 'forbidden' | 'not_found' | 'rate_limited' | 'server_error' | (string & {});
2509
+ /** Everything but the message needed to build a {@link ApiError}. */
2510
+ interface ApiErrorInit {
2511
+ /**
2512
+ * HTTP status of the failing response. When no HTTP exchange took place the
2513
+ * SDK synthesizes the semantically matching code: 400 for input the SDK
2514
+ * itself rejects, 408 for a poll deadline, 499 for an abort or cancel, 502
2515
+ * for a response it cannot make sense of.
2516
+ */
2517
+ status: number;
2518
+ /** Platform `reason` when present, otherwise an SDK-synthesized code. */
2519
+ code: ApiErrorCode;
2520
+ }
2521
+ /**
2522
+ * The single error type the SDK throws — the generation surface
2523
+ * (`generate()`, `generateText()`, `submit()`, `result()`), `ai.catalogs`,
2524
+ * and `ai.apis` alike.
2525
+ *
2526
+ * Unrelated to the `Api*` types (`ApiResponse`, `ApiRunOptions`, …), which
2527
+ * describe the low-level `ai.apis` surface — though that surface throws this
2528
+ * error too. ApiError is the only error type the SDK exposes.
2529
+ *
2530
+ * ```ts
2531
+ * try {
2532
+ * await ai.generate(Models.Flux2Pro, { prompt: 'a cat' });
2533
+ * } catch (err) {
2534
+ * if (err instanceof ApiError) {
2535
+ * if (err.status === 402) return topUpCredits();
2536
+ * if (err.status === 429 || err.status >= 500) return retry();
2537
+ * if (err.code === 'validation_error') return showFormError(err.message);
2538
+ * }
2539
+ * throw err;
2540
+ * }
2541
+ * ```
2542
+ *
2543
+ * Aborts raised by `fetch` itself are never wrapped — a caller checking
2544
+ * `err.name === 'AbortError'` on a `DOMException` keeps working.
2545
+ */
2546
+ declare class ApiError extends Error {
2547
+ /** HTTP status, or the synthesized equivalent for non-HTTP failures. */
2548
+ readonly status: number;
2549
+ /** Platform `reason`, or an SDK-synthesized code. Always equal to {@link reason}. */
2550
+ readonly code: ApiErrorCode;
2551
+ /** Alias of {@link code}, named after the platform's own error field. */
2552
+ readonly reason: ApiErrorCode;
2553
+ constructor(message: string, init: ApiErrorInit);
2554
+ }
2555
+
2556
+ /** Worker-reported progress on a generation.progress event. */
2557
+ type GenerationProgress = WorkflowProgress;
2485
2558
  /** A fetch-like function that handles authentication (headers, cookies, etc.). */
2486
2559
  type AuthenticatedFetch = (url: string, init?: RequestInit) => Promise<Response>;
2487
2560
  /** Drive configuration — enables auto-saving generations to Picsart Drive. */
@@ -2503,16 +2576,30 @@ interface AppIdentity {
2503
2576
  id: string;
2504
2577
  type: AppType;
2505
2578
  }
2579
+ /** Settings that apply whichever transport serves the client. */
2580
+ interface ClientConfigBase {
2581
+ /** Enable Drive integration — auto-save generations to a Drive folder. */
2582
+ drive?: DriveConfig;
2583
+ /**
2584
+ * Input-transformation defaults applied to every generation. A per-call
2585
+ * `options.inputsTransformation` overrides this field by field.
2586
+ */
2587
+ inputsTransformation?: PayloadInputsTransformationOptions;
2588
+ /**
2589
+ * Voice/avatar catalog behavior. `{ preload: true }` loads the first page
2590
+ * of every catalog-bound param in the background at client creation.
2591
+ */
2592
+ catalogs?: CatalogsOptions;
2593
+ }
2506
2594
  /**
2507
- * Simple client config — pass the API base URL plus one auth source, and the
2508
- * SDK handles the rest. The SDK knows the Picsart API endpoints and response
2509
- * shapes internally.
2595
+ * The usual config: the API base URL plus one auth source, and the SDK builds
2596
+ * its own transport over @picsart/workflows-client.
2510
2597
  *
2511
2598
  * Provide exactly one of:
2512
2599
  * - `fetch` — your own authenticated fetch (you add headers/cookies), or
2513
2600
  * - `apiKey` — the SDK builds a fetch that sends `Authorization: Bearer <apiKey>`.
2514
2601
  */
2515
- interface ClientConfig {
2602
+ interface HttpClientConfig extends ClientConfigBase {
2516
2603
  /**
2517
2604
  * Authenticated fetch function. The SDK calls this for all HTTP requests.
2518
2605
  * Provide this or `apiKey`. Takes precedence over `apiKey` when both are set.
@@ -2526,34 +2613,54 @@ interface ClientConfig {
2526
2613
  apiKey?: string;
2527
2614
  /** API base URL (e.g. 'https://api.picsart.com'). */
2528
2615
  apiUrl: string;
2529
- /** Enable Drive integration — auto-save generations to a Drive folder. */
2530
- drive?: DriveConfig;
2531
- /**
2532
- * Input-transformation defaults applied to every generation. A per-call
2533
- * `options.inputsTransformation` overrides this field by field.
2534
- */
2535
- inputsTransformation?: PayloadInputsTransformationOptions;
2536
- /**
2537
- * Voice/avatar catalog behavior. `{ preload: true }` loads the first page
2538
- * of every catalog-bound param in the background at client creation.
2539
- */
2540
- catalogs?: CatalogsOptions;
2616
+ transport?: undefined;
2541
2617
  }
2618
+ /**
2619
+ * Config for a caller-supplied {@link SdkTransport} — you own the wire, so
2620
+ * `apiUrl` and the auth source are yours to bake into the transport and are
2621
+ * not required here (the SDK never passes them to it).
2622
+ *
2623
+ * Two surfaces still speak the workflows protocol directly and therefore keep
2624
+ * needing `apiUrl` plus `fetch`/`apiKey` when you use them: `ai.drive`, and
2625
+ * `ai.apis`. Everything else — generate, the async lifecycle, `getCredits`,
2626
+ * `ai.catalogs` — goes through the transport.
2627
+ */
2628
+ interface TransportClientConfig extends ClientConfigBase {
2629
+ /** Transport the client runs on, in place of the built-in one. */
2630
+ transport: SdkTransport;
2631
+ /** Only needed for `ai.drive` / `ai.apis`. */
2632
+ apiUrl?: string;
2633
+ /** Only needed for `ai.drive` / `ai.apis`. */
2634
+ fetch?: AuthenticatedFetch;
2635
+ /** Only needed for `ai.drive` / `ai.apis`. */
2636
+ apiKey?: string;
2637
+ }
2638
+ /**
2639
+ * Client config — either the built-in transport's shape or a custom
2640
+ * transport's. The two halves are deliberately unexported: they carry the same
2641
+ * fields and differ only in which are required, so `ClientConfig` is the single
2642
+ * name to annotate with.
2643
+ */
2644
+ type ClientConfig = HttpClientConfig | TransportClientConfig;
2645
+
2542
2646
  interface GenerateResultItem {
2543
2647
  url: string;
2544
- metadata?: Record<string, unknown>;
2648
+ metadata?: GenerateResultItemMetadata;
2545
2649
  }
2650
+ /** Result of a media generation. */
2546
2651
  interface GenerateResult {
2547
- /** Primary result URL (convenience shortcut for results[0].url). */
2652
+ /** Primary result URL (convenience shortcut for items[0].url). */
2548
2653
  url: string;
2549
- /** All result items — single item for normal models, multiple for explore/multi-result models. */
2654
+ /** All result items — one for normal models, multiple for explore/multi-result models. */
2655
+ items: GenerateResultItem[];
2656
+ /** @deprecated Use {@link items} — same array; removed in the next major. */
2550
2657
  results: GenerateResultItem[];
2551
- /** Model ID that produced this result. */
2552
- model: string;
2553
- /** Job handle for status tracking. */
2554
- handle: WorkflowJobHandle;
2555
- /** Raw parsed output for advanced consumers. */
2556
- raw: unknown;
2658
+ /**
2659
+ * The generation id — pass to result()/subscribe() together with the model
2660
+ * id. Absent for syncExecute models: their generation completes inline in
2661
+ * one request, so there is no job to poll or recover.
2662
+ */
2663
+ generationId?: string;
2557
2664
  /** Credit usage reported by the platform — same structure as the pluggable APIs' GenAITaskResponse. */
2558
2665
  usage?: CreditUsage;
2559
2666
  /** Present when Drive is enabled and the file was saved. */
@@ -2565,13 +2672,43 @@ interface GenerateTextResult {
2565
2672
  text: string;
2566
2673
  /** Model ID that produced this result. */
2567
2674
  model: string;
2568
- /** Job handle for status tracking. */
2569
- handle: WorkflowJobHandle;
2570
2675
  /** Raw parsed output — carries vendor token usage, finish reason, thinking trace, etc. */
2571
2676
  raw: unknown;
2572
2677
  /** Credit usage reported by the platform — same structure as the pluggable APIs' GenAITaskResponse. */
2573
2678
  usage?: CreditUsage;
2574
2679
  }
2680
+
2681
+ /**
2682
+ * Named constants for the {@link GenerationEvent} discriminant — sugar over
2683
+ * the string literals for consumers who prefer `GenerationEventType.Completed`
2684
+ * to `'generation.completed'`. Both compare fine: the event `type` field stays
2685
+ * a literal union, so raw strings keep working (and keep autocompleting).
2686
+ */
2687
+ declare const GenerationEventType: {
2688
+ readonly Progress: "generation.progress";
2689
+ readonly Completed: "generation.completed";
2690
+ readonly Failed: "generation.failed";
2691
+ };
2692
+ type GenerationEventType = (typeof GenerationEventType)[keyof typeof GenerationEventType];
2693
+ /**
2694
+ * One `ai.subscribe()` update.
2695
+ * - `generation.progress` — a non-terminal poll; `progress` is present when
2696
+ * the worker reports it (percent, ETA).
2697
+ * - `generation.completed` — terminal; carries the parsed
2698
+ * {@link GenerateResult} in `result`, no follow-up `ai.result()` needed.
2699
+ * - `generation.failed` — terminal (worker FAILED or the job was canceled);
2700
+ * carries the same {@link ApiError} that `ai.result()` would have thrown.
2701
+ */
2702
+ type GenerationEvent = {
2703
+ type: 'generation.progress';
2704
+ progress?: GenerationProgress;
2705
+ } | {
2706
+ type: 'generation.completed';
2707
+ result: GenerateResult;
2708
+ } | {
2709
+ type: 'generation.failed';
2710
+ error: ApiError;
2711
+ };
2575
2712
  /** Input-transformation settings injected into the workflow payload as
2576
2713
  * `options.inputs_transformation` (GenAIOptions, alongside `drive`). */
2577
2714
  interface PayloadInputsTransformationOptions {
@@ -2584,6 +2721,14 @@ interface PayloadInputsTransformationOptions {
2584
2721
  */
2585
2722
  downscaleOversizedImages?: boolean;
2586
2723
  }
2724
+ /** Polling controls for result()/subscribe() on an already-submitted job. */
2725
+ interface GenerationOptions {
2726
+ /** Poll interval in ms. Overrides the model's `pollOptions` and the mode default. */
2727
+ intervalMs?: number;
2728
+ /** Max poll attempts before timing out. Overrides the model's `pollOptions` and the mode default. */
2729
+ maxAttempts?: number;
2730
+ signal?: AbortSignal;
2731
+ }
2587
2732
  /** Options for individual generate() / submit() calls. */
2588
2733
  interface GenerateOptions {
2589
2734
  signal?: AbortSignal;
@@ -2622,18 +2767,20 @@ interface AiClient {
2622
2767
  generateText<M extends TextModelId>(model: M, params: TextModelInputById[M], options?: GenerateOptions): Promise<GenerateTextResult>;
2623
2768
  /** Get exact credit cost for a model with specific parameters. */
2624
2769
  getCredits<M extends TypedModelId>(model: M, params: ModelInputById[M]): Promise<number | null>;
2625
- /** Submit a generation job and get a handle back. Media models only. */
2626
- submit<M extends MediaModelId>(model: M, params: ModelInputById[M], options?: GenerateOptions): Promise<WorkflowJobHandle>;
2627
- /** Check the current status of a submitted job. */
2628
- status(handle: WorkflowJobHandle, signal?: AbortSignal): Promise<WorkflowStatusResult<unknown>>;
2770
+ /** Submit a generation job and get its generation id back. Media models only. */
2771
+ submit<M extends MediaModelId>(model: M, params: ModelInputById[M], options?: GenerateOptions): Promise<string>;
2629
2772
  /** Poll a submitted job until it completes and return the parsed result. Media models only. */
2630
- result(handle: WorkflowJobHandle, model: MediaModelId, options?: WorkflowPollOptions): Promise<GenerateResult>;
2631
- /** Subscribe to live status updates for a submitted job. */
2632
- subscribe(handle: WorkflowJobHandle, options?: WorkflowSubscribeOptions): AsyncGenerator<WorkflowStatusResult<unknown>, WorkflowStatusResult<unknown>, void>;
2773
+ result(model: MediaModelId, generationId: string, options?: GenerationOptions): Promise<GenerateResult>;
2774
+ /**
2775
+ * Subscribe to live updates for a submitted job. Yields one
2776
+ * {@link GenerationEvent} per poll; the terminal `generation.completed`
2777
+ * event carries the parsed result in `event.result`, and failures/cancels
2778
+ * arrive as `generation.failed` events (with the {@link ApiError}), not as
2779
+ * exceptions.
2780
+ */
2781
+ subscribe(model: MediaModelId, generationId: string, options?: GenerationOptions): AsyncGenerator<GenerationEvent, void, void>;
2633
2782
  /** Build the vendor-specific payload for a model without submitting. */
2634
2783
  buildPayload<M extends TypedModelId>(model: M, params: ModelInputById[M]): Record<string, unknown>;
2635
- /** @deprecated Use `apis.run()` instead. Run a raw workflow (not tied to a model). */
2636
- runWorkflow<TResult = unknown>(workflow: string, payload: Record<string, unknown>, options?: WorkflowRunOptions): Promise<TResult>;
2637
2784
  /**
2638
2785
  * Direct, low-level access to the Picsart model APIs — run any API by name.
2639
2786
  * See {@link ApisClient}.
@@ -2663,22 +2810,15 @@ interface AiClient {
2663
2810
  * drive: { folder: 'AI Playground' },
2664
2811
  * });
2665
2812
  * ```
2813
+ *
2814
+ * @example With your own transport — the SDK stops talking to the workflows
2815
+ * API entirely, so `apiUrl` and the auth source are the transport's business:
2816
+ * ```ts
2817
+ * const ai = createClient({ transport: myTransport });
2818
+ * ```
2666
2819
  */
2667
- declare function createClient(config: ClientConfig | SdkTransport): AiClient;
2668
-
2669
- /**
2670
- * Typed Models constants and namespace.
2671
- * Regenerate with: npm run build:model-constants
2672
- */
2820
+ declare function createClient(config: ClientConfig): AiClient;
2673
2821
 
2674
- interface ValidationResult {
2675
- valid: boolean;
2676
- errors?: string[];
2677
- }
2678
- interface ModelFilter {
2679
- mode?: GenerationMode;
2680
- provider?: string;
2681
- }
2682
2822
  declare const Models: {
2683
2823
  readonly AsyncFlashV1: "async-flash-v1";
2684
2824
  readonly BytedanceOmnihumanV15: "bytedance-omnihuman-v1.5";
@@ -2795,7 +2935,6 @@ declare const Models: {
2795
2935
  readonly Lyria3Clip: "lyria-3-clip";
2796
2936
  readonly Lyria3Pro: "lyria-3-pro";
2797
2937
  readonly Lyria35: "lyria-3.5";
2798
- readonly Minimax02Hd: "minimax-02-hd";
2799
2938
  readonly MinimaxH3: "minimax-h3";
2800
2939
  readonly MinimaxH3Max: "minimax-h3-max";
2801
2940
  readonly MinimaxH3MaxCameraControls: "minimax-h3-max-camera-controls";
@@ -2905,21 +3044,6 @@ declare const Models: {
2905
3044
  readonly Wan27VideoEdit: "wan-2.7-video-edit";
2906
3045
  readonly Wan30Video: "wan-3.0-video";
2907
3046
  readonly Wan30VideoPrime: "wan-3.0-video-prime";
2908
- /** @deprecated Use the `catalog` accessor (`catalog.all()` / `catalog.find({ output, provider })`) instead. */
2909
- readonly list: (filter?: ModelFilter) => ModelDefinition[];
2910
- /** @deprecated Use `Model(id).validate(input)` instead. */
2911
- readonly validate: (model: string, input: unknown) => ValidationResult;
2912
- /** @deprecated Use `Model(id).params().toSchema()` instead. */
2913
- readonly toSchema: (id: string) => ModelParamSchema;
2914
- /** @deprecated Use `Model(id).params().file(key)` instead. */
2915
- readonly getFileParam: (id: string, key: string) => {
2916
- required: boolean;
2917
- max: number;
2918
- label?: string;
2919
- accept?: string;
2920
- } | null;
2921
- /** @deprecated Use `Model(id).params().hasParam(key)` instead. */
2922
- readonly hasParam: (id: string, key: string) => boolean;
2923
3047
  };
2924
3048
 
2925
3049
  /**
@@ -2929,61 +3053,6 @@ declare const Models: {
2929
3053
  */
2930
3054
 
2931
3055
  declare function getVoiceById(id: string): VoiceOption | undefined;
2932
- /** @deprecated Load the model's catalog instead (`ai.catalogs.voices(modelId)`) — loaded voices are searched automatically. */
2933
- declare function getVoiceById(id: string, extra: VoiceOption[] | undefined): VoiceOption | undefined;
2934
-
2935
- /**
2936
- * Failure codes the SDK synthesizes when the platform supplies no `reason`.
2937
- * An API-supplied `reason` passes through unchanged, so the open `string`
2938
- * member keeps arbitrary platform reasons assignable while preserving
2939
- * autocomplete on the known set.
2940
- */
2941
- type ApiErrorCode = 'unknown_model' | 'wrong_model_mode' | 'validation_error' | 'unsupported_transport' | 'timeout' | 'aborted' | 'canceled' | 'generation_failed' | 'invalid_response' | 'bad_request' | 'unauthorized' | 'payment_required' | 'forbidden' | 'not_found' | 'rate_limited' | 'server_error' | (string & {});
2942
- /** Everything but the message needed to build a {@link ApiError}. */
2943
- interface ApiErrorInit {
2944
- /**
2945
- * HTTP status of the failing response. When no HTTP exchange took place the
2946
- * SDK synthesizes the semantically matching code: 400 for input the SDK
2947
- * itself rejects, 408 for a poll deadline, 499 for an abort or cancel, 502
2948
- * for a response it cannot make sense of.
2949
- */
2950
- status: number;
2951
- /** Platform `reason` when present, otherwise an SDK-synthesized code. */
2952
- code: ApiErrorCode;
2953
- }
2954
- /**
2955
- * The single error type thrown by the SDK's generation surface —
2956
- * `generate()`, `generateText()`, `submit()`, and `result()`.
2957
- *
2958
- * Unrelated to the `Api*` types (`ApiResponse`, `ApiRunOptions`, …), which
2959
- * describe the low-level `ai.apis` surface. `ai.apis.run()` throws the
2960
- * workflows client's own errors, not this.
2961
- *
2962
- * ```ts
2963
- * try {
2964
- * await ai.generate(Models.Flux2Pro, { prompt: 'a cat' });
2965
- * } catch (err) {
2966
- * if (err instanceof ApiError) {
2967
- * if (err.status === 402) return topUpCredits();
2968
- * if (err.status === 429 || err.status >= 500) return retry();
2969
- * if (err.code === 'validation_error') return showFormError(err.message);
2970
- * }
2971
- * throw err;
2972
- * }
2973
- * ```
2974
- *
2975
- * Aborts raised by `fetch` itself are never wrapped — a caller checking
2976
- * `err.name === 'AbortError'` on a `DOMException` keeps working.
2977
- */
2978
- declare class ApiError extends Error {
2979
- /** HTTP status, or the synthesized equivalent for non-HTTP failures. */
2980
- readonly status: number;
2981
- /** Platform `reason`, or an SDK-synthesized code. Always equal to {@link reason}. */
2982
- readonly code: ApiErrorCode;
2983
- /** Alias of {@link code}, named after the platform's own error field. */
2984
- readonly reason: ApiErrorCode;
2985
- constructor(message: string, init: ApiErrorInit);
2986
- }
2987
3056
 
2988
3057
  /**
2989
3058
  * Pricing internals — owns the ModelPricingClient, the per-model cache, and
@@ -3027,7 +3096,7 @@ type ModelFunction = (id: string) => ModelDescriptor;
3027
3096
  declare function _all(filter?: {
3028
3097
  release?: readonly ReleaseTag[];
3029
3098
  }): ModelDescriptor[];
3030
- declare function _find(filter: ModelFilter$1): ModelDescriptor[];
3099
+ declare function _find(filter: ModelFilter): ModelDescriptor[];
3031
3100
  declare function _search(query: string, filter?: {
3032
3101
  release?: readonly ReleaseTag[];
3033
3102
  }): ModelDescriptor[];
@@ -3072,15 +3141,21 @@ declare function encodeDeepLinkPayload(modelId: string, context: Partial<Generat
3072
3141
  */
3073
3142
  declare function decodeDeepLinkPayload(encoded: string): DeepLinkResult | null;
3074
3143
 
3075
- /** All models from all vendors. */
3144
+ /**
3145
+ * All models from all vendors.
3146
+ * @deprecated Use `catalog.all()` — the descriptor accessors are the supported
3147
+ * surface; this raw array will be removed in the next major.
3148
+ */
3076
3149
  declare const ALL_MODELS: ModelDefinition[];
3077
3150
  /**
3078
3151
  * Models for a generation mode. By default returns only default-visible models
3079
- * (production / general-availability — preview, disabled and deprecated are
3080
- * hidden). `includeDisabled = true` returns every model of the mode, bypassing
3081
- * all gates. For release-tier filtering use `catalog.find({ output, release })`.
3152
+ * (production / general-availability — preview and deprecated are hidden).
3153
+ * `includeHidden = true` returns every model of the mode, bypassing all gates.
3154
+ * For release-tier filtering use `catalog.find({ output, release })`.
3155
+ * @deprecated Use `catalog.all().filter(m => m.mode === mode)` (or
3156
+ * `catalog.find({ output })`) — removed in the next major.
3082
3157
  */
3083
- declare const getModelsByMode: (mode: ModelDefinition["mode"], includeDisabled?: boolean) => ModelDefinition[];
3158
+ declare const getModelsByMode: (mode: ModelDefinition["mode"], includeHidden?: boolean) => ModelDefinition[];
3084
3159
 
3085
3160
  /**
3086
3161
  * Release tags shown by default in discovery. `preview` is stage-only and
@@ -3093,24 +3168,22 @@ declare const releaseOf: (m: ModelDefinition) => ReleaseTag;
3093
3168
  * Whether `m` is visible for the requested `releases` (default: the production
3094
3169
  * + general-availability set).
3095
3170
  *
3096
- * `disabled` and `deprecated` are hard hides layered on top of `release`: a
3097
- * model carrying either is never visible, regardless of its release tag or the
3098
- * requested set. (`disabled` is being phased out in favour of
3099
- * `release: 'preview'`, but is still honoured during the migration.)
3171
+ * `deprecated` is a hard hide layered on top of `release`: a deprecated model
3172
+ * is never visible, regardless of its release tag or the requested set.
3100
3173
  */
3101
3174
  declare function isVisibleForReleases(m: ModelDefinition, releases?: readonly ReleaseTag[]): boolean;
3102
3175
 
3103
- /** Look up a model by its ID or vendor modelId. */
3176
+ /**
3177
+ * Look up a model by its ID or vendor modelId.
3178
+ * @deprecated Use the `Model(id)` accessor (or `catalog.find(id)`) — this
3179
+ * raw-definition lookup will be removed in the next major.
3180
+ */
3104
3181
  declare const getModel: (id: string) => ModelDefinition | undefined;
3105
- /** Find a model by ID, workflow name, or display name (case-insensitive). */
3106
- declare const findModel: (ref: string) => ModelDefinition | undefined;
3107
-
3108
3182
  /**
3109
- * Effect scenes that require two input images (e.g. hugs, kisses, swaps).
3110
- * @deprecated Read `meta.imageSlots` on the `kling/v1/catalog/templates`
3111
- * catalog items instead this frozen copy is no longer maintained and will be
3112
- * removed in the next major.
3183
+ * Find a model by ID, workflow name, or display name (case-insensitive).
3184
+ * @deprecated Use `catalog.find(ref)` / `catalog.search(query)` — this
3185
+ * raw-definition lookup will be removed in the next major.
3113
3186
  */
3114
- declare const KLING_DUAL_IMAGE_EFFECTS: ReadonlySet<string>;
3187
+ declare const findModel: (ref: string) => ModelDefinition | undefined;
3115
3188
 
3116
- export { ALL_MODELS, type AiClient, ApiError, type ApiErrorCode, type ApiErrorInit, type ApiResponse, type ApiRunOptions, type ApiSchemas, type ApisClient, type AppIdentity, type AppType, type AuthenticatedFetch, type AvatarOption, type BooleanDescriptor, type BooleanEntry, type CatalogDescriptor, type CatalogEntry, type CatalogItem, type CatalogKind, type CatalogPage, type CatalogPageOptions, type CatalogPreview, type CatalogQuery, type CatalogResult, type CatalogSource, type CatalogsClient, type CatalogsOptions, type ClientConfig, type CreditRange, type CreditRangeContext, type CreditTier, type CreditUsage, DEFAULT_VISIBLE_RELEASES, type DeepLinkResult, type DriveAttributes, type DriveClient, type DriveConfig, type DriveFile, type DriveFileDetails, type DriveFolder, type DriveMediaItem, type DriveSaveResult, type EntryMeta, type EnumDescriptor, type EnumEntry, type EnumOption, type FileDescriptor, type FileEntry, type FlatParamEntry, type GenerateOptions, type GenerateResult, type GenerateResultItem, type GenerateTextResult, type GenerationContext, type GenerationFile, type GenerationMode, KLING_DUAL_IMAGE_EFFECTS, type ListOptions, type MediaModelId, type MediaTypeFilter, Model, type ModelDefinition, type ModelDescriptor, type ModelFilter$1 as ModelFilter, type ModelInput, type ModelInputById, type ModelMeta, type ModelParams, type ModelParamsAccessor, Models, type ObjectDescriptor, type ObjectEntry, type ParamDescriptor, type ParamEntry, type ParamOption, type PayloadDriveFolderOptions, type PayloadDriveOptions, type PayloadInputsTransformationOptions, type PricingOptions, type ProviderInfo, type RangeDescriptor, type RangeEntry, type ReleaseTag, type SaveParams, type SdkPayload, type SdkTransport, type TextDescriptor, type TextEntry, type TextModelId, type TextModelInputById, type ToolUsage, type TypedModelId, type UserReaction, type ValidationResult$1 as ValidationResult, type VoiceOption, type WorkflowJobHandle, buildFilename, buildGenerationAttributes, catalog, createClient, decodeDeepLinkPayload, encodeDeepLinkPayload, findModel, getModel, getModelsByMode, getVoiceById, inferResourceType, isVisibleForReleases, parseGeneration, releaseOf, toAvatarOption, toVoiceOption };
3189
+ export { ALL_MODELS, type AiClient, ApiError, type ApiErrorCode, type ApiErrorInit, type ApiResponse, type ApiRunOptions, type ApiSchemas, type ApisClient, type AppIdentity, type AppType, type AuthenticatedFetch, type AvatarOption, type BooleanDescriptor, type BooleanEntry, type CatalogDescriptor, type CatalogEntry, type CatalogItem, type CatalogPage, type CatalogPageOptions, type CatalogPreview, type CatalogQuery, type CatalogResult, type CatalogSource, type CatalogsClient, type CatalogsOptions, type ClientConfig, type CreditRange, type CreditRangeContext, type CreditTier, type CreditUsage, DEFAULT_VISIBLE_RELEASES, type DeepLinkResult, type DriveAttributes, type DriveClient, type DriveConfig, type DriveFile, type DriveFileDetails, type DriveFolder, type DriveMediaItem, type DriveSaveResult, type EntryMeta, type EnumDescriptor, type EnumEntry, type EnumOption, type FileDescriptor, type FileEntry, type FlatParamEntry, type GenerateOptions, type GenerateResult, type GenerateResultItem, type GenerateResultItemMetadata, type GenerateTextResult, type GenerationContext, type GenerationEvent, GenerationEventType, type GenerationFile, type GenerationMode, type GenerationOptions, type GenerationProgress, type ListOptions, type MediaModelId, type MediaTypeFilter, Model, type ModelDefinition, type ModelDescriptor, type ModelFilter, type ModelInput, type ModelInputById, type ModelMeta, type ModelParams, type ModelParamsAccessor, Models, type ObjectDescriptor, type ObjectEntry, type ParamDescriptor, type ParamEntry, type ParamOption, type PayloadDriveFolderOptions, type PayloadDriveOptions, type PayloadInputsTransformationOptions, type PricingOptions, type ProviderInfo, type RangeDescriptor, type RangeEntry, type ReleaseTag, type SaveParams, type SdkPayload, type SdkTransport, type TextDescriptor, type TextEntry, type TextModelId, type TextModelInputById, type ToolUsage, type TransportPollOptions, type TransportResult, type TypedModelId, type UserReaction, type ValidationResult, type VoiceOption, type WorkflowJobHandle, type WorkflowSubmitRequest, buildFilename, buildGenerationAttributes, catalog, createClient, decodeDeepLinkPayload, encodeDeepLinkPayload, findModel, getModel, getModelsByMode, getVoiceById, inferResourceType, isVisibleForReleases, parseGeneration, releaseOf, toAvatarOption, toVoiceOption };