@picsart/ai-sdk 7.25.0 → 7.27.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
@@ -205,6 +205,33 @@ uploads remain ordinary uploads: without generation context the SDK cannot infer
205
205
  model, prompt or settings. Existing Drive files are not backfilled. The backend preserves SDK-supplied metadata; it cannot reconstruct SDK input
206
206
  names or catalog model IDs from an arbitrary vendor request.
207
207
 
208
+ ## Service Tier
209
+
210
+ `serviceTier` chooses how a generation is served. It is sent to the platform as
211
+ `options.service_tier` on every generation route — `generate()`, `generateText()`,
212
+ `run()` and `submit()` — and on the price calls.
213
+
214
+ | Tier | Price | Limits |
215
+ |------|-------|--------|
216
+ | `auto` (default) | The user's discount, when one applies | The discount's: a number of generations at a time (a `429` when all are in use) and a wait before a generation starts after heavy use |
217
+ | `priority` | The regular price — the discount is not used | None |
218
+
219
+ ```typescript
220
+ // Per call
221
+ await ai.generate(modelId, { prompt }, { serviceTier: 'priority' });
222
+
223
+ // Or as the client default — a per-call `serviceTier` overrides it
224
+ const ai = createClient({ apiKey, apiUrl, serviceTier: 'priority' });
225
+ ```
226
+
227
+ Quote with the tier you will generate with, or the quote is not the price charged:
228
+
229
+ ```typescript
230
+ const credits = await ai.getCredits(modelId, { prompt }, { serviceTier: 'priority' });
231
+ ```
232
+
233
+ Left unset, the option is not sent and the platform applies `auto`.
234
+
208
235
  ## Text Generation (LLMs)
209
236
 
210
237
  Claude, GPT, Gemini, Kimi, Grok and MiniMax text models are called with `generateText()`. Single-shot:
@@ -408,6 +435,7 @@ Key exports (see `src/index.ts` for the full list):
408
435
  | `ClientConfig` | type | `{ apiKey?, fetch?, apiUrl, drive?, transport? }` — one of `apiKey` / `fetch` required unless `transport` is set |
409
436
  | `AuthenticatedFetch` | type | `(url, init?) => Promise<Response>` — for the custom-`fetch` path |
410
437
  | `SdkTransport` | type | The transport contract — see [Custom Transport](#custom-transport) |
438
+ | `ServiceTier` | type | `'auto' \| 'priority'` — see [Service Tier](#service-tier) |
411
439
  | `GenerationOptions` | type | Poll controls for `result()`/`subscribe()` — `{ intervalMs?, maxAttempts?, signal? }` |
412
440
  | `ApiError` | class | Unified error: `{ status, code, reason, message }` — see [Error Handling](#error-handling) |
413
441
 
@@ -69,6 +69,7 @@ export type ModelInputById = {
69
69
  "gemini-3.8-flash-lite-tts": { language?: string; accent?: string; prompt?: string; voiceId?: string; style?: string; parts?: Array<{ text: string; speaker?: string; style?: string }>; multiSpeakerVoiceConfigs?: Array<{ speaker: string; voiceName: string }>; };
70
70
  "gemini-3.8-flash-tts": { language?: string; accent?: string; prompt?: string; voiceId?: string; style?: string; parts?: Array<{ text: string; speaker?: string; style?: string }>; multiSpeakerVoiceConfigs?: Array<{ speaker: string; voiceName: string }>; };
71
71
  "gemini-4-argon": { prompt: string; imageUrls?: string[]; videoUrl?: string; thinking?: "off" | "low" | "high"; };
72
+ "gemini-4-carbon": { prompt: string; imageUrls?: string[]; videoUrl?: string; thinking?: "off" | "low" | "medium" | "high"; };
72
73
  "gemini-nano-banana-2.1": { prompt: string; aspectRatio?: "1:1" | "16:9" | "9:16" | "3:4" | "4:3" | "2:3" | "21:9" | "auto"; resolution?: "1K" | "2K" | "4K"; count?: 1 | 2 | 4 | 6 | 8 | 10; seed?: number; thinkingLevel?: "minimal" | "medium" | "high"; imageUrls?: string[]; };
73
74
  "gemini-omni-1.1-flash-preview": { prompt: string; aspectRatio?: "16:9" | "9:16"; resolution?: "360p" | "720p" | "1080p" | "4k"; duration?: 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10; startFrame?: string; endFrame?: string; imageUrls?: string[]; videoUrl?: string; videoUrls?: string[]; };
74
75
  "gemini-omni-1.2-flash": { prompt: string; aspectRatio?: "16:9" | "9:16"; resolution?: "360p" | "720p" | "1080p" | "4k"; duration?: 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15; startFrame?: string; endFrame?: string; imageUrls?: string[]; videoUrl?: string; videoUrls?: string[]; task?: "edit" | "extend"; };
@@ -283,7 +284,7 @@ export type TypedModelId = keyof ModelInputById;
283
284
  export type ModelInput<M extends TypedModelId> = ModelInputById[M];
284
285
 
285
286
  /** IDs of text-generation (LLM) models — narrows generateText(). */
286
- export type TextModelId = "claude-fable-5" | "claude-fable-5-1" | "claude-fable-5-2" | "claude-haiku-4-5" | "claude-haiku-5-5" | "claude-opus-4-8" | "claude-opus-5" | "claude-opus-5-5" | "claude-sonnet-4-5" | "claude-sonnet-4-6" | "claude-sonnet-5" | "eleven-speech-to-text" | "gemini-2.5-flash" | "gemini-3-pro" | "gemini-3.5-flash-lite" | "gemini-3.6-flash" | "gemini-3.7-flash" | "gemini-3.8-flash" | "gemini-4-argon" | "gpt-4.1-mini" | "gpt-4.1-nano" | "gpt-4o" | "gpt-4o-mini" | "gpt-5" | "gpt-5-mini" | "gpt-5.1" | "gpt-5.2" | "gpt-5.5" | "gpt-5.6-luna" | "gpt-5.6-sol" | "gpt-5.6-terra" | "gpt-6-astra" | "gpt-6-luna" | "gpt-6-sol" | "gpt-6.1-sol" | "gpt-6.1-terra" | "grok-4.7" | "kimi-k3" | "kimi-k3.1-pro" | "kimi-k3.1-pro-highspeed" | "minimax-h3-context-ir" | "minimax-m3" | "minimax-m3.1-flash";
287
+ export type TextModelId = "claude-fable-5" | "claude-fable-5-1" | "claude-fable-5-2" | "claude-haiku-4-5" | "claude-haiku-5-5" | "claude-opus-4-8" | "claude-opus-5" | "claude-opus-5-5" | "claude-sonnet-4-5" | "claude-sonnet-4-6" | "claude-sonnet-5" | "eleven-speech-to-text" | "gemini-2.5-flash" | "gemini-3-pro" | "gemini-3.5-flash-lite" | "gemini-3.6-flash" | "gemini-3.7-flash" | "gemini-3.8-flash" | "gemini-4-argon" | "gemini-4-carbon" | "gpt-4.1-mini" | "gpt-4.1-nano" | "gpt-4o" | "gpt-4o-mini" | "gpt-5" | "gpt-5-mini" | "gpt-5.1" | "gpt-5.2" | "gpt-5.5" | "gpt-5.6-luna" | "gpt-5.6-sol" | "gpt-5.6-terra" | "gpt-6-astra" | "gpt-6-luna" | "gpt-6-sol" | "gpt-6.1-sol" | "gpt-6.1-terra" | "grok-4.7" | "kimi-k3" | "kimi-k3.1-pro" | "kimi-k3.1-pro-highspeed" | "minimax-h3-context-ir" | "minimax-m3" | "minimax-m3.1-flash";
287
288
  export type TextModelInputById = Pick<ModelInputById, TextModelId>;
288
289
 
289
290
  /** IDs of structured-output (json-mode) models — narrows run()'s result type. */
package/index.d.ts CHANGED
@@ -1165,6 +1165,12 @@ interface ClientConfigBase {
1165
1165
  * `options.inputsTransformation` overrides this field by field.
1166
1166
  */
1167
1167
  inputsTransformation?: PayloadInputsTransformationOptions;
1168
+ /**
1169
+ * Service tier applied to every generation and price quote. A per-call
1170
+ * `options.serviceTier` overrides it. Unset means the platform default
1171
+ * (`auto`).
1172
+ */
1173
+ serviceTier?: ServiceTier;
1168
1174
  /**
1169
1175
  * Voice/avatar catalog behavior. `{ preload: true }` loads the first page
1170
1176
  * of every catalog-bound param in the background at client creation.
@@ -1303,6 +1309,26 @@ type GenerationEvent = {
1303
1309
  type: 'generation.failed';
1304
1310
  error: ApiError;
1305
1311
  };
1312
+ /**
1313
+ * How a generation is served, sent as `options.service_tier`:
1314
+ *
1315
+ * - `auto` — the platform default. The user's discount is used when one
1316
+ * applies, along with the limits it carries: a number of generations at a
1317
+ * time (a 429 when they are all in use) and a wait before a generation
1318
+ * starts after heavy use.
1319
+ * - `priority` — the regular price, with no concurrency limit and no wait.
1320
+ * The discount is not used.
1321
+ */
1322
+ type ServiceTier = 'auto' | 'priority';
1323
+ /** Options for the price calls — `getCredits()` / `options()`. */
1324
+ interface PriceOptions {
1325
+ /**
1326
+ * Service tier to quote — overrides the client-level `serviceTier`. Pass the
1327
+ * tier the generation will be sent with, so the quote is the price it is
1328
+ * charged: `priority` quotes the regular price, not the discounted one.
1329
+ */
1330
+ serviceTier?: ServiceTier;
1331
+ }
1306
1332
  /** Input-transformation settings injected into the workflow payload as
1307
1333
  * `options.inputs_transformation` (GenAIOptions, alongside `drive`). */
1308
1334
  interface PayloadInputsTransformationOptions {
@@ -1345,6 +1371,13 @@ interface GenerateOptions {
1345
1371
  * `inputsTransformation`. When neither is set, oversized-image downscaling
1346
1372
  * stays off (opt-in). */
1347
1373
  inputsTransformation?: PayloadInputsTransformationOptions;
1374
+ /**
1375
+ * Service tier for this call — overrides the client-level `serviceTier`.
1376
+ * `priority` pays the regular price to skip the limits of the user's
1377
+ * discount; see {@link ServiceTier}. Applies to `run()`, `generate()`,
1378
+ * `generateText()` and `submit()`.
1379
+ */
1380
+ serviceTier?: ServiceTier;
1348
1381
  /**
1349
1382
  * App identity stamped onto the saved generation (appId/appType).
1350
1383
  * TODO(backend-autosave): temporary — remove once the backend stamps these.
@@ -1396,11 +1429,11 @@ interface AiClient {
1396
1429
  /** Get exact credit cost for a model with specific parameters. */
1397
1430
  getCredits(model: string, params: Record<string, unknown> & {
1398
1431
  prompt: string;
1399
- }): Promise<number | null>;
1432
+ }, options?: PriceOptions): Promise<number | null>;
1400
1433
  /** What the model's /options endpoint answers for these params — credits, how they were derived, and anything else it reports. */
1401
1434
  options(model: string, params: Record<string, unknown> & {
1402
1435
  prompt: string;
1403
- }): Promise<OptionsResult | null>;
1436
+ }, options?: PriceOptions): Promise<OptionsResult | null>;
1404
1437
  /** Submit a generation job and get its generation id back. Media models only. */
1405
1438
  submit(model: string, params: Record<string, unknown> & {
1406
1439
  prompt: string;
@@ -1445,7 +1478,7 @@ interface AiClient {
1445
1478
  drive: DriveClient | undefined;
1446
1479
  }
1447
1480
 
1448
- /** Platform options carried on a {@link ModelsCommand} (ModelsGenAIOptions on the backend). */
1481
+ /** Platform options carried on a {@link ModelsCommand} (GenAIOptions on the backend). */
1449
1482
  interface ModelsGenAIOptions {
1450
1483
  safety_checks?: {
1451
1484
  enabled?: boolean;
@@ -1454,6 +1487,7 @@ interface ModelsGenAIOptions {
1454
1487
  inputs_transformation?: {
1455
1488
  downscale_oversized_images?: boolean;
1456
1489
  };
1490
+ service_tier?: ServiceTier;
1457
1491
  }
1458
1492
  /** The `v1/models` request body: which model, the SDK-shaped params, platform options. */
1459
1493
  interface ModelsCommand {
@@ -1656,4 +1690,4 @@ declare const getModel: (id: string) => ModelDefinition | undefined;
1656
1690
  */
1657
1691
  declare const findModel: (ref: string) => ModelDefinition | undefined;
1658
1692
 
1659
- export { 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 CatalogModel, type CatalogModelsResponse, type CatalogPage, type CatalogPageOptions, type CatalogParam, type CatalogPreview, type CatalogProvider, 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 InitModelCatalogOptions, type ListOptions, type MediaModelId, type MediaTypeFilter, Model, type ModelCatalogFilters, type ModelDefinition, type ModelDescriptor, type ModelFilter, type ModelMeta, type ModelParams, type ModelParamsAccessor, type ModelsCommand, type ModelsGenAIOptions, 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 RunResponse, type SaveParams, type SdkPayload, type SdkTransport, type SeedanceDraftTask, type TextDescriptor, type TextEntry, type ToolUsage, type TransportPollOptions, type TransportResult, type UnknownDescriptor, type UnknownEntry, type UserReaction, type ValidationResult, type VoiceOption, type WorkflowJobHandle, type WorkflowSubmitRequest, buildFilename, buildGenerationAttributes, catalog, createClient, decodeDeepLinkPayload, encodeDeepLinkPayload, expectedOutputFormat, findModel, getModel, getVoiceById, inferResourceType, isVisibleForReleases, parseGeneration, releaseOf, resolveExtension, toAvatarOption, toVoiceOption };
1693
+ export { 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 CatalogModel, type CatalogModelsResponse, type CatalogPage, type CatalogPageOptions, type CatalogParam, type CatalogPreview, type CatalogProvider, 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 InitModelCatalogOptions, type ListOptions, type MediaModelId, type MediaTypeFilter, Model, type ModelCatalogFilters, type ModelDefinition, type ModelDescriptor, type ModelFilter, type ModelMeta, type ModelParams, type ModelParamsAccessor, type ModelsCommand, type ModelsGenAIOptions, type ObjectDescriptor, type ObjectEntry, type OptionsResult, type ParamDescriptor, type ParamEntry, type ParamOption, type PayloadDriveFolderOptions, type PayloadDriveOptions, type PayloadInputsTransformationOptions, type PriceOptions, type PricingOptions, type ProviderInfo, type RangeDescriptor, type RangeEntry, type ReleaseTag, type RunResponse, type SaveParams, type SdkPayload, type SdkTransport, type SeedanceDraftTask, type ServiceTier, type TextDescriptor, type TextEntry, type ToolUsage, type TransportPollOptions, type TransportResult, type UnknownDescriptor, type UnknownEntry, type UserReaction, type ValidationResult, type VoiceOption, type WorkflowJobHandle, type WorkflowSubmitRequest, buildFilename, buildGenerationAttributes, catalog, createClient, decodeDeepLinkPayload, encodeDeepLinkPayload, expectedOutputFormat, findModel, getModel, getVoiceById, inferResourceType, isVisibleForReleases, parseGeneration, releaseOf, resolveExtension, toAvatarOption, toVoiceOption };
package/index.js CHANGED
@@ -2718,16 +2718,19 @@ function buildTransport(wc) {
2718
2718
 
2719
2719
  // src/client/prepare.ts
2720
2720
  var MODELS_WORKFLOW = "v1/models";
2721
- function buildModelsCommand(model, params, options) {
2722
- if (!options) return { model, params };
2721
+ function buildModelsCommand(model, params, media, serviceTier) {
2722
+ if (!media && !serviceTier) return { model, params };
2723
2723
  return {
2724
2724
  model,
2725
2725
  params,
2726
2726
  options: {
2727
- inputs_transformation: {
2728
- downscale_oversized_images: options.downscaleOversizedImages ?? false
2729
- },
2730
- ...options.drive ? { drive: options.drive } : {}
2727
+ ...media ? {
2728
+ inputs_transformation: {
2729
+ downscale_oversized_images: media.downscaleOversizedImages ?? false
2730
+ },
2731
+ ...media.drive ? { drive: media.drive } : {}
2732
+ } : {},
2733
+ ...serviceTier ? { service_tier: serviceTier } : {}
2731
2734
  }
2732
2735
  };
2733
2736
  }
@@ -3658,9 +3661,9 @@ function createClient(config) {
3658
3661
  if (typeof res === "number") return { credits: res };
3659
3662
  return res && typeof res.credits === "number" ? res : null;
3660
3663
  }
3661
- async function fetchOptions(model, params) {
3664
+ async function fetchOptions(model, params, options) {
3662
3665
  if (!transport.options) return null;
3663
- const command = buildModelsCommand(model, params);
3666
+ const command = buildModelsCommand(model, params, void 0, resolveServiceTier(options));
3664
3667
  return askOptionsRoute(MODELS_WORKFLOW, command);
3665
3668
  }
3666
3669
  function pollOptionsFor(overrides) {
@@ -3704,6 +3707,9 @@ function createClient(config) {
3704
3707
  function resolveDownscale(options) {
3705
3708
  return options?.inputsTransformation?.downscaleOversizedImages ?? inputsTransformationConfig?.downscaleOversizedImages ?? false;
3706
3709
  }
3710
+ function resolveServiceTier(options) {
3711
+ return options?.serviceTier ?? config.serviceTier;
3712
+ }
3707
3713
  function subscribeGenerator(resolveHandle, pollOptions, parse, options) {
3708
3714
  return (async function* () {
3709
3715
  let handle;
@@ -3769,11 +3775,14 @@ function createClient(config) {
3769
3775
  * model-id counterpart of `ai.apis.run()`. models-hub builds and validates
3770
3776
  * the payload, executes the workflow (sync or async), applies the model's
3771
3777
  * `outputSchema` when declared, and returns the task result as-is — no
3772
- * media-URL or text extraction, no Drive save, no options injection. The
3778
+ * media-URL or text extraction, no Drive save, no media options. The
3773
3779
  * only generation surface for json-mode (structured-output) models.
3774
3780
  */
3775
3781
  async run(model, params, options) {
3776
- const completed = await executeDynamic(buildModelsCommand(model, params), options);
3782
+ const completed = await executeDynamic(
3783
+ buildModelsCommand(model, params, void 0, resolveServiceTier(options)),
3784
+ options
3785
+ );
3777
3786
  return parseDynamicRunResult(completed, model);
3778
3787
  },
3779
3788
  /**
@@ -3789,7 +3798,7 @@ function createClient(config) {
3789
3798
  const command = buildModelsCommand(model, params, {
3790
3799
  drive,
3791
3800
  downscaleOversizedImages: resolveDownscale(options)
3792
- });
3801
+ }, resolveServiceTier(options));
3793
3802
  const completed = await executeDynamic(command, options);
3794
3803
  return parseDynamicResult(completed, model);
3795
3804
  },
@@ -3800,7 +3809,10 @@ function createClient(config) {
3800
3809
  * Text results are not saved to Drive.
3801
3810
  */
3802
3811
  async generateText(model, params, options) {
3803
- const completed = await executeDynamic(buildModelsCommand(model, params), options);
3812
+ const completed = await executeDynamic(
3813
+ buildModelsCommand(model, params, void 0, resolveServiceTier(options)),
3814
+ options
3815
+ );
3804
3816
  return parseDynamicTextResult(completed, model);
3805
3817
  },
3806
3818
  /**
@@ -3808,16 +3820,16 @@ function createClient(config) {
3808
3820
  * Calls the backend /options endpoint for real-time pricing.
3809
3821
  * Returns null if pricing is unavailable.
3810
3822
  */
3811
- async getCredits(model, params) {
3812
- return (await fetchOptions(model, params))?.credits ?? null;
3823
+ async getCredits(model, params, options) {
3824
+ return (await fetchOptions(model, params, options))?.credits ?? null;
3813
3825
  },
3814
3826
  /**
3815
3827
  * Same /options call as getCredits(), returning the whole response:
3816
3828
  * credits plus billable amount, unit, rate, whether they are estimated, and
3817
3829
  * whether the caller has the permissions the request needs.
3818
3830
  */
3819
- async options(model, params) {
3820
- return fetchOptions(model, params);
3831
+ async options(model, params, options) {
3832
+ return fetchOptions(model, params, options);
3821
3833
  },
3822
3834
  // ── Advanced lifecycle ────────────────────────────────────────────
3823
3835
  /** Submit a generation job and get its generation id back. Media models
@@ -3829,7 +3841,7 @@ function createClient(config) {
3829
3841
  const command = buildModelsCommand(model, params, {
3830
3842
  drive,
3831
3843
  downscaleOversizedImages: resolveDownscale(options)
3832
- });
3844
+ }, resolveServiceTier(options));
3833
3845
  try {
3834
3846
  return await submitJob(MODELS_WORKFLOW, command, options?.signal);
3835
3847
  } catch (err) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@picsart/ai-sdk",
3
- "version": "7.25.0",
3
+ "version": "7.27.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",