@picsart/ai-sdk 6.21.4 → 6.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -99,12 +99,12 @@ and keep needing `apiUrl` plus `fetch`/`apiKey` if you use them: `ai.drive` and
99
99
  | `submit(request)` | no | `generate()`, `submit()` — returns the generation id |
100
100
  | `poll(handle, options)` | no | `generate()`, `result()`, `subscribe()` — resolves when the job is terminal, calls `options.onProgress` on the way |
101
101
  | `status(handle, signal?)` | no | the edit-route probe behind `result(model, id)` on models that have one |
102
- | `options(workflow, payload)` | no | `getCredits()` — returns credits, or null |
102
+ | `options(workflow, payload)` | no | `getCredits()` / `options()` — returns credits, an `OptionsResult`, or null |
103
103
 
104
104
  Leave `submit`/`poll` out and the client runs **every** generation through
105
105
  `execute()`; the async lifecycle (`submit()` / `result()` / `subscribe()`) then
106
106
  rejects with a 400 `unsupported_transport` rather than pretending. Leave
107
- `options` out and `getCredits()` answers null.
107
+ `options` out and `getCredits()` / `options()` answer null.
108
108
 
109
109
  ```typescript
110
110
  import type { SdkTransport } from '@picsart/ai-sdk'
@@ -41,12 +41,13 @@ type PartialWorkflowResult<R> = {
41
41
  result: R;
42
42
  };
43
43
  interface WorkflowOptions {
44
- monetization?: {
45
- toolId: string;
46
- };
44
+ toolId?: string;
47
45
  usageAmount?: number;
48
46
  credits?: number;
49
47
  originalCredits?: number;
48
+ estimated?: boolean;
49
+ unit?: string;
50
+ price?: number;
50
51
  }
51
52
  type HistoryResponse<R> = PicsartResponse & {
52
53
  response: {
package/index.d.ts CHANGED
@@ -43,6 +43,26 @@ interface CreditUsage {
43
43
  /** The remaining balance. */
44
44
  balance?: number;
45
45
  }
46
+ /**
47
+ * What a model's `/options` endpoint answers for one request — today its price
48
+ * and how it was derived (mirrors `WorkflowOptions` from `@picsart/workflows-client`).
49
+ */
50
+ interface OptionsResult {
51
+ /** Monetization tool the request is billed under. */
52
+ toolId?: string;
53
+ /** Billable quantity, in `unit`s (e.g. seconds of video, tokens). */
54
+ usageAmount?: number;
55
+ /** Credits the request would be charged. */
56
+ credits: number;
57
+ /** Credits before any discount was applied. */
58
+ originalCredits?: number;
59
+ /** True when `credits` is a best guess rather than the exact charge — e.g. token-priced models, billed on actual usage. */
60
+ estimated?: boolean;
61
+ /** What `usageAmount` counts, e.g. "second" or "token". */
62
+ unit?: string;
63
+ /** Rate per `unit`. */
64
+ price?: number;
65
+ }
46
66
  interface WorkflowPollOptions {
47
67
  intervalMs?: number;
48
68
  maxAttempts?: number;
@@ -93,8 +113,11 @@ interface SdkTransport<TPayload = Record<string, unknown>> {
93
113
  poll?(handle: WorkflowJobHandle, options?: TransportPollOptions): Promise<TransportResult>;
94
114
  /** Read a submitted job's current state in one request — no waiting. */
95
115
  status?(handle: WorkflowJobHandle, signal?: AbortSignal): Promise<TransportResult>;
96
- /** Credits this request would cost, or null when pricing is unavailable. */
97
- options?(workflow: string, payload: Record<string, unknown>): Promise<number | null>;
116
+ /**
117
+ * Credits this request would cost, or null when pricing is unavailable.
118
+ * Answer a bare number, or the full {@link OptionsResult} response.
119
+ */
120
+ options?(workflow: string, payload: Record<string, unknown>): Promise<number | OptionsResult | null>;
98
121
  }
99
122
 
100
123
  /**
@@ -3204,6 +3227,8 @@ interface AiClient {
3204
3227
  generateText<M extends TextModelId>(model: M, params: TextModelInputById[M], options?: GenerateOptions): Promise<GenerateTextResult>;
3205
3228
  /** Get exact credit cost for a model with specific parameters. */
3206
3229
  getCredits<M extends TypedModelId>(model: M, params: ModelInputById[M]): Promise<number | null>;
3230
+ /** What the model's /options endpoint answers for these params — credits, how they were derived, and anything else it reports. */
3231
+ options<M extends TypedModelId>(model: M, params: ModelInputById[M]): Promise<OptionsResult | null>;
3207
3232
  /** Submit a generation job and get its generation id back. Media models only. */
3208
3233
  submit<M extends MediaModelId>(model: M, params: ModelInputById[M], options?: GenerateOptions): Promise<string>;
3209
3234
  /** Poll a submitted job until it completes and return the parsed result. Media models only. */
@@ -3656,4 +3681,4 @@ declare const getModel: (id: string) => ModelDefinition | undefined;
3656
3681
  */
3657
3682
  declare const findModel: (ref: string) => ModelDefinition | undefined;
3658
3683
 
3659
- 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 DriveDraftInfo, 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 GenerationProvenance, 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 SeedanceDraftTask, 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, expectedOutputFormat, findModel, getModel, getModelsByMode, getVoiceById, inferResourceType, isVisibleForReleases, parseGeneration, releaseOf, resolveExtension, toAvatarOption, toVoiceOption };
3684
+ 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 DriveDraftInfo, 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 GenerationProvenance, 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 OptionsResult, 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 SeedanceDraftTask, 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, expectedOutputFormat, findModel, getModel, getModelsByMode, getVoiceById, inferResourceType, isVisibleForReleases, parseGeneration, releaseOf, resolveExtension, toAvatarOption, toVoiceOption };
package/index.js CHANGED
@@ -12247,7 +12247,8 @@ function buildTransport(wc) {
12247
12247
  async options(workflow, payload) {
12248
12248
  try {
12249
12249
  const res = await wc.options(workflow, payload);
12250
- return typeof res?.credits === "number" ? res.credits : null;
12250
+ if (typeof res?.credits !== "number") return null;
12251
+ return { ...res, credits: res.credits };
12251
12252
  } catch {
12252
12253
  return null;
12253
12254
  }
@@ -13235,6 +13236,14 @@ function createClient(config) {
13235
13236
  }
13236
13237
  };
13237
13238
  }
13239
+ async function fetchOptions(model, params2) {
13240
+ if (!transport.options) return null;
13241
+ const resolved = resolveModel(model);
13242
+ const { workflow, payload } = prepareRequest(resolved, params2);
13243
+ const res = await transport.options(workflow, payload);
13244
+ if (typeof res === "number") return { credits: res };
13245
+ return res && typeof res.credits === "number" ? res : null;
13246
+ }
13238
13247
  async function resolveJobHandle(model, generationId, signal) {
13239
13248
  const primary = { workflow: model.workflow, id: generationId };
13240
13249
  if (!model.editWorkflow || !transport.status) return primary;
@@ -13294,10 +13303,14 @@ function createClient(config) {
13294
13303
  * Returns null if pricing is unavailable.
13295
13304
  */
13296
13305
  async getCredits(model, params2) {
13297
- if (!transport.options) return null;
13298
- const resolved = resolveModel(model);
13299
- const { workflow, payload } = prepareRequest(resolved, params2);
13300
- return await transport.options(workflow, payload) ?? null;
13306
+ return (await fetchOptions(model, params2))?.credits ?? null;
13307
+ },
13308
+ /**
13309
+ * Same /options call as getCredits(), returning the whole response:
13310
+ * credits plus billable amount, unit, rate, and whether they are estimated.
13311
+ */
13312
+ async options(model, params2) {
13313
+ return fetchOptions(model, params2);
13301
13314
  },
13302
13315
  /** Build the vendor-specific payload for a model without submitting. */
13303
13316
  buildPayload(model, params2) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@picsart/ai-sdk",
3
- "version": "6.21.4",
3
+ "version": "6.22.0",
4
4
  "type": "module",
5
5
  "description": "Type-safe SDK for 100+ AI models — image, video, audio, and text generation with Picsart",
6
6
  "license": "MIT",