@picsart/ai-sdk 6.21.3 → 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 +2 -2
- package/_vendor/workflows-client/index.d.ts +4 -3
- package/index.d.ts +28 -3
- package/index.js +18 -7
- package/package.json +1 -1
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()`
|
|
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
|
-
|
|
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
|
-
/**
|
|
97
|
-
|
|
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
|
@@ -6393,8 +6393,6 @@ var { MODELS: MODELS21 } = defineModels("flux", [
|
|
|
6393
6393
|
workflow: "bfl/v1/flux-3-image",
|
|
6394
6394
|
mode: "image",
|
|
6395
6395
|
inputType: "t2i",
|
|
6396
|
-
// Early-access at the vendor — stage only until it is cleared for prod.
|
|
6397
|
-
release: "preview",
|
|
6398
6396
|
addedAt: "2026-09-22",
|
|
6399
6397
|
// Deliberately generous. Measured end-to-end against stage at 1k/16:9:
|
|
6400
6398
|
// 44s for count 1, 68s for count 4 — of which only 3-6s is our pipeline,
|
|
@@ -12249,7 +12247,8 @@ function buildTransport(wc) {
|
|
|
12249
12247
|
async options(workflow, payload) {
|
|
12250
12248
|
try {
|
|
12251
12249
|
const res = await wc.options(workflow, payload);
|
|
12252
|
-
|
|
12250
|
+
if (typeof res?.credits !== "number") return null;
|
|
12251
|
+
return { ...res, credits: res.credits };
|
|
12253
12252
|
} catch {
|
|
12254
12253
|
return null;
|
|
12255
12254
|
}
|
|
@@ -13237,6 +13236,14 @@ function createClient(config) {
|
|
|
13237
13236
|
}
|
|
13238
13237
|
};
|
|
13239
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
|
+
}
|
|
13240
13247
|
async function resolveJobHandle(model, generationId, signal) {
|
|
13241
13248
|
const primary = { workflow: model.workflow, id: generationId };
|
|
13242
13249
|
if (!model.editWorkflow || !transport.status) return primary;
|
|
@@ -13296,10 +13303,14 @@ function createClient(config) {
|
|
|
13296
13303
|
* Returns null if pricing is unavailable.
|
|
13297
13304
|
*/
|
|
13298
13305
|
async getCredits(model, params2) {
|
|
13299
|
-
|
|
13300
|
-
|
|
13301
|
-
|
|
13302
|
-
|
|
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);
|
|
13303
13314
|
},
|
|
13304
13315
|
/** Build the vendor-specific payload for a model without submitting. */
|
|
13305
13316
|
buildPayload(model, params2) {
|