@picsart/ai-sdk 6.21.4 → 6.22.1

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
  /**
@@ -755,7 +778,8 @@ type ModelInputById = {
755
778
  prompt: string;
756
779
  imageUrls?: string[];
757
780
  mask?: string;
758
- size?: "auto" | "source" | "2048x2048" | "1440x2880" | "2880x1440" | "1664x2496" | "2496x1664" | "1792x2240" | "2240x1792" | "1440x2560" | "2560x1440" | "1600x2560" | "2560x1600" | "1728x2304" | "2304x1728" | "1296x3168" | "3168x1296" | "1152x2944" | "2944x1152" | "1248x3328" | "3328x1248" | "1280x3072" | "3072x1280" | "1024x3072" | "3072x1024" | "1024x1024" | "896x1120" | "1120x896" | "864x1152" | "1152x864" | "832x1248" | "1248x832" | "800x1280" | "1280x800" | "720x1280" | "1280x720" | "720x1440" | "1440x720" | "512x1536" | "1536x512";
781
+ aspectRatio?: "auto" | "source" | "1:1" | "16:9" | "9:16" | "4:3" | "3:4" | "3:2" | "2:3" | "5:4" | "4:5" | "8:5" | "5:8" | "2:1" | "1:2" | "3:1" | "1:3";
782
+ resolution?: "1K" | "2K";
759
783
  magicPrompt?: "auto" | "on" | "off";
760
784
  quality?: "very_low" | "low" | "medium" | "high";
761
785
  count?: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8;
@@ -3204,6 +3228,8 @@ interface AiClient {
3204
3228
  generateText<M extends TextModelId>(model: M, params: TextModelInputById[M], options?: GenerateOptions): Promise<GenerateTextResult>;
3205
3229
  /** Get exact credit cost for a model with specific parameters. */
3206
3230
  getCredits<M extends TypedModelId>(model: M, params: ModelInputById[M]): Promise<number | null>;
3231
+ /** What the model's /options endpoint answers for these params — credits, how they were derived, and anything else it reports. */
3232
+ options<M extends TypedModelId>(model: M, params: ModelInputById[M]): Promise<OptionsResult | null>;
3207
3233
  /** Submit a generation job and get its generation id back. Media models only. */
3208
3234
  submit<M extends MediaModelId>(model: M, params: ModelInputById[M], options?: GenerateOptions): Promise<string>;
3209
3235
  /** Poll a submitted job until it completes and return the parsed result. Media models only. */
@@ -3656,4 +3682,4 @@ declare const getModel: (id: string) => ModelDefinition | undefined;
3656
3682
  */
3657
3683
  declare const findModel: (ref: string) => ModelDefinition | undefined;
3658
3684
 
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 };
3685
+ 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
@@ -8019,45 +8019,24 @@ var IDEOGRAM_45_IMAGE_BOUNDS = {
8019
8019
  minAspectRatio: 1 / 6,
8020
8020
  maxAspectRatio: 6
8021
8021
  };
8022
- var IDEOGRAM_45_T2I_SIZES = [
8023
- "2048x2048",
8024
- "1440x2880",
8025
- "2880x1440",
8026
- "1664x2496",
8027
- "2496x1664",
8028
- "1792x2240",
8029
- "2240x1792",
8030
- "1440x2560",
8031
- "2560x1440",
8032
- "1600x2560",
8033
- "2560x1600",
8034
- "1728x2304",
8035
- "2304x1728",
8036
- "1296x3168",
8037
- "3168x1296",
8038
- "1152x2944",
8039
- "2944x1152",
8040
- "1248x3328",
8041
- "3328x1248",
8042
- "1280x3072",
8043
- "3072x1280",
8044
- "1024x3072",
8045
- "3072x1024",
8046
- "1024x1024",
8047
- "896x1120",
8048
- "1120x896",
8049
- "864x1152",
8050
- "1152x864",
8051
- "832x1248",
8052
- "1248x832",
8053
- "800x1280",
8054
- "1280x800",
8055
- "720x1280",
8056
- "1280x720",
8057
- "720x1440",
8058
- "1440x720",
8059
- "512x1536",
8060
- "1536x512"
8022
+ var IDEOGRAM_45_ASPECT_RATIOS = [
8023
+ "auto",
8024
+ "source",
8025
+ "1:1",
8026
+ "16:9",
8027
+ "9:16",
8028
+ "4:3",
8029
+ "3:4",
8030
+ "3:2",
8031
+ "2:3",
8032
+ "5:4",
8033
+ "4:5",
8034
+ "8:5",
8035
+ "5:8",
8036
+ "2:1",
8037
+ "1:2",
8038
+ "3:1",
8039
+ "1:3"
8061
8040
  ];
8062
8041
  var ideogram45MaskParam = p.file("mask", "image", {
8063
8042
  label: "Mask",
@@ -8083,15 +8062,22 @@ var IDEOGRAM_45_COUNTS = [1, 2, 3, 4, 5, 6, 7, 8];
8083
8062
  var IDEOGRAM_45_QUALITIES = ["very_low", "low", "medium", "high"];
8084
8063
  var ideogram45Constraints = [
8085
8064
  { when: { imageUrls: { exists: false } }, then: {
8086
- size: { allowed: ["auto", ...IDEOGRAM_45_T2I_SIZES] },
8065
+ aspectRatio: {
8066
+ allowed: IDEOGRAM_45_ASPECT_RATIOS.filter((ar) => ar !== "source"),
8067
+ reason: '"Source" keeps the size of a source image.'
8068
+ },
8087
8069
  mask: { disabled: true, reason: "A mask needs a source image." },
8088
8070
  quality: { allowed: ["low", "medium", "high"], reason: "Very low quality needs a source image." }
8089
8071
  } },
8090
- { when: { imageUrls: { exists: true } }, then: {
8091
- size: { allowed: ["auto", "source"], reason: 'With input images the size is "auto" or the source image size.' }
8092
- } },
8093
8072
  { when: { mask: { exists: true } }, then: {
8094
- size: { disabled: true, reason: "A masked edit keeps the source image size." }
8073
+ aspectRatio: { disabled: true, reason: "A masked edit keeps the source image size." },
8074
+ resolution: { disabled: true, reason: "A masked edit keeps the source image size." }
8075
+ } },
8076
+ { when: { aspectRatio: { is: "auto" } }, then: {
8077
+ resolution: { disabled: true, reason: "Auto picks a 2K size." }
8078
+ } },
8079
+ { when: { aspectRatio: { is: "source" } }, then: {
8080
+ resolution: { disabled: true, reason: "The output keeps the source image size." }
8095
8081
  } }
8096
8082
  ];
8097
8083
  var { MODELS: MODELS26 } = defineModels("ideogram", [
@@ -8112,7 +8098,8 @@ var { MODELS: MODELS26 } = defineModels("ideogram", [
8112
8098
  // With a mask the vendor allows at most 4 images.
8113
8099
  ...params.imageInput(5, "Images", false, "reference", IDEOGRAM_45_IMAGE_BOUNDS),
8114
8100
  ...ideogram45MaskParam,
8115
- ...p.size(["auto", "source", ...IDEOGRAM_45_T2I_SIZES], "auto"),
8101
+ ...params.aspectRatio(IDEOGRAM_45_ASPECT_RATIOS, "auto"),
8102
+ ...params.resolution(["1K", "2K"], "2K"),
8116
8103
  ...ideogram45MagicPromptParam,
8117
8104
  ...p.quality(IDEOGRAM_45_QUALITIES, "high"),
8118
8105
  ...params.count(IDEOGRAM_45_COUNTS, 1),
@@ -8347,22 +8334,23 @@ function assertMaskedImageLimit(model, count, max, what) {
8347
8334
  function invalid2(message) {
8348
8335
  return new ApiError(message, { status: 400, code: "validation_error" });
8349
8336
  }
8350
- function ideogram45Size(size, hasImages, hasMask) {
8351
- if (!size || hasMask) return void 0;
8352
- if (hasImages) return size === "auto" || size === "source" ? size : void 0;
8353
- return size === "source" ? void 0 : size;
8337
+ function ideogram45Shape(input, hasImages, hasMask) {
8338
+ const aspectRatio = input.aspectRatio;
8339
+ if (!aspectRatio || hasMask) return {};
8340
+ if (aspectRatio === "source" && !hasImages) return {};
8341
+ if (aspectRatio === "auto" || aspectRatio === "source") return { aspect_ratio: aspectRatio };
8342
+ return { aspect_ratio: aspectRatio, ...input.resolution ? { resolution: input.resolution } : {} };
8354
8343
  }
8355
8344
  var buildIdeogram45Payload = (input) => {
8356
8345
  const images = input.imageUrls?.length ? input.imageUrls : void 0;
8357
8346
  const mask = images && input.mask ? input.mask : void 0;
8358
8347
  if (mask) assertMaskedImageLimit("Ideogram 4.5", images.length, GENERATE_MAX_IMAGES_WITH_MASK, "images");
8359
- const size = ideogram45Size(input.size, !!images, !!mask);
8360
8348
  if (input.quality === "very_low" && !images) throw invalid2("Ideogram 4.5: very_low quality needs a source image.");
8361
8349
  return {
8362
8350
  prompt: input.prompt,
8363
8351
  ...images ? { images } : {},
8364
8352
  ...mask ? { mask } : {},
8365
- ...size ? { size } : {},
8353
+ ...ideogram45Shape(input, !!images, !!mask),
8366
8354
  ...input.magicPrompt ? { magic_prompt: input.magicPrompt } : {},
8367
8355
  // Vendor default: medium with source images, high without.
8368
8356
  quality: input.quality ?? (images ? "medium" : "high"),
@@ -12247,7 +12235,8 @@ function buildTransport(wc) {
12247
12235
  async options(workflow, payload) {
12248
12236
  try {
12249
12237
  const res = await wc.options(workflow, payload);
12250
- return typeof res?.credits === "number" ? res.credits : null;
12238
+ if (typeof res?.credits !== "number") return null;
12239
+ return { ...res, credits: res.credits };
12251
12240
  } catch {
12252
12241
  return null;
12253
12242
  }
@@ -13235,6 +13224,14 @@ function createClient(config) {
13235
13224
  }
13236
13225
  };
13237
13226
  }
13227
+ async function fetchOptions(model, params2) {
13228
+ if (!transport.options) return null;
13229
+ const resolved = resolveModel(model);
13230
+ const { workflow, payload } = prepareRequest(resolved, params2);
13231
+ const res = await transport.options(workflow, payload);
13232
+ if (typeof res === "number") return { credits: res };
13233
+ return res && typeof res.credits === "number" ? res : null;
13234
+ }
13238
13235
  async function resolveJobHandle(model, generationId, signal) {
13239
13236
  const primary = { workflow: model.workflow, id: generationId };
13240
13237
  if (!model.editWorkflow || !transport.status) return primary;
@@ -13294,10 +13291,14 @@ function createClient(config) {
13294
13291
  * Returns null if pricing is unavailable.
13295
13292
  */
13296
13293
  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;
13294
+ return (await fetchOptions(model, params2))?.credits ?? null;
13295
+ },
13296
+ /**
13297
+ * Same /options call as getCredits(), returning the whole response:
13298
+ * credits plus billable amount, unit, rate, and whether they are estimated.
13299
+ */
13300
+ async options(model, params2) {
13301
+ return fetchOptions(model, params2);
13301
13302
  },
13302
13303
  /** Build the vendor-specific payload for a model without submitting. */
13303
13304
  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.1",
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",