@picsart/ai-sdk 3.17.4 → 3.17.5

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.
Files changed (3) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +222 -0
  3. package/package.json +1 -1
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Picsart, Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,222 @@
1
+ # @picsart/ai-sdk
2
+
3
+ Generate images, videos, and audio with 100+ AI models.
4
+
5
+ ## Documentation
6
+
7
+ Interactive guides deployed via GitLab Pages:
8
+
9
+ - [SDK Guide](https://picsart.gitlab.io/web/miniapp-projects/ai-toolkit/sdk_guide.html) -- Usage examples, client setup, model registry, Drive integration, and full API reference
10
+ - [CLI Guide](https://picsart.gitlab.io/web/miniapp-projects/ai-toolkit/cli_guide.html) -- Commands, flags, interactive mode, scripting, batch processing, and troubleshooting
11
+
12
+ Source: [`sdk_guide.html`](sdk_guide.html)
13
+
14
+ Repository: [gitlab.com/picsart/backend/Editor/external-ai-integrations/pa-gen-ai-sdk](https://gitlab.com/picsart/backend/Editor/external-ai-integrations/pa-gen-ai-sdk)
15
+
16
+ ## Quick Start
17
+
18
+ ```bash
19
+ npm install @picsart/ai-sdk
20
+ ```
21
+
22
+ ```typescript
23
+ import { createClient, Models, Model, catalog } from '@picsart/ai-sdk'
24
+
25
+ // Create a client — pass your authenticated fetch
26
+ const ai = createClient({
27
+ fetch: myAuthenticatedFetch,
28
+ apiUrl: 'https://api.picsart.com',
29
+ })
30
+
31
+ // Generate (Models.* are typed model-id constants)
32
+ const result = await ai.generate(Models.Flux2Pro, { prompt: 'a cat on mars' })
33
+ console.log(result.url)
34
+
35
+ // Browse models — the `catalog` accessor
36
+ catalog.all() // every model
37
+ catalog.find({ output: 'video' }) // video models only
38
+ catalog.search('kling') // search by name/id/provider
39
+
40
+ // Model metadata & params — the `Model` accessor
41
+ Model(Models.Flux2Pro).name // 'Flux 2 Pro'
42
+ Model(Models.Flux2Pro).meta() // mode, provider, badges, …
43
+ Model(Models.Flux2Pro).params() // accepted parameters
44
+ Model(Models.Flux2Pro).params().toSchema() // param schema
45
+
46
+ // Validate input (never throws) → { valid, errors? }
47
+ Model(Models.Flux2Pro).validate({ prompt: 'a cat' })
48
+ ```
49
+
50
+ ## Drive Integration
51
+
52
+ Auto-save generations to Picsart Drive:
53
+
54
+ ```typescript
55
+ const ai = createClient({
56
+ fetch: myAuthenticatedFetch,
57
+ apiUrl: 'https://api.picsart.com',
58
+ drive: { folder: 'AI Playground' },
59
+ })
60
+
61
+ // Generates and auto-saves to the root folder
62
+ const result = await ai.generate(Models.Flux2Pro, { prompt: 'a cat' })
63
+ // result.drive = { uid: '...', folder: { name: 'AI Playground', uid: '...' } }
64
+
65
+ // Save to a subfolder
66
+ const board = await ai.drive.ensureFolder('Cats')
67
+ const result = await ai.generate(Models.Flux2Pro, { prompt: 'a cat' }, { folder: board })
68
+
69
+ // Browse Drive
70
+ const folders = await ai.drive.folders()
71
+ const items = await ai.drive.list()
72
+ ```
73
+
74
+ ## Text Generation (LLMs)
75
+
76
+ Claude, GPT, and Gemini text models are called with `generateText()`. Single-shot:
77
+ pass a prompt and optional image(s)/video, get text back. They surface in the catalog
78
+ as `mode: 'text'`. Each vendor uses its own native workflow, so capabilities aren't lost
79
+ — Gemini accepts video input, Claude uses the Anthropic-native messages API.
80
+
81
+ ```typescript
82
+ import { createClient, Models } from '@picsart/ai-sdk'
83
+
84
+ const ai = createClient({ fetch: myAuthenticatedFetch, apiUrl: 'https://api.picsart.com' })
85
+
86
+ // Text in, text out
87
+ const { text } = await ai.generateText(Models.ClaudeOpus48, { prompt: 'Explain RAG in one line.' })
88
+ console.log(text)
89
+
90
+ // Optional vision input + reasoning level (OpenAI / Gemini)
91
+ const res = await ai.generateText(Models.Gpt55, {
92
+ prompt: 'What is in this image?',
93
+ imageUrls: ['https://cdn.example.com/photo.jpg'],
94
+ thinking: 'high', // 'off' | 'low' | 'medium' | 'high'
95
+ })
96
+ console.log(res.text)
97
+ console.log(res.raw) // full backend response — usage, finish_reason, etc.
98
+
99
+ // Gemini accepts video input
100
+ await ai.generateText(Models.Gemini3Pro, {
101
+ prompt: 'Summarize this clip',
102
+ videoUrl: 'https://cdn.example.com/clip.mp4',
103
+ })
104
+
105
+ // Browse text models
106
+ catalog.find({ output: 'text' })
107
+ ```
108
+
109
+ > Thinking level maps per vendor: OpenAI → `reasoning_effort`, Gemini →
110
+ > `thinkingConfig.thinkingLevel` (LOW/HIGH). Claude’s `claude/v1/messages`
111
+ > workflow exposes no thinking knob, so Claude models omit `thinking`.
112
+
113
+ `generateText()` is type-narrowed to text models (`TextModelId`); calling it with an
114
+ image/video model throws, and `generate()` throws on a text model — use the matching
115
+ method for each.
116
+
117
+ ## Advanced Lifecycle
118
+
119
+ For progress tracking, cancellation, and job recovery:
120
+
121
+ ```typescript
122
+ // Submit without waiting
123
+ const handle = await ai.submit(Models.KlingV3Pro, { prompt: 'a sunset' })
124
+
125
+ // Subscribe to status updates
126
+ for await (const update of ai.subscribe(handle)) {
127
+ console.log(update.status, update.progress?.percent)
128
+ }
129
+
130
+ // Or poll manually
131
+ const status = await ai.status(handle)
132
+ ```
133
+
134
+ ## Public API
135
+
136
+ The SDK exports 7 symbols:
137
+
138
+ | Export | Type | Description |
139
+ |--------|------|-------------|
140
+ | `createClient` | function | Create an AI client from authenticated fetch |
141
+ | `Models` | object | Model catalog: 108 models + list/search/validate/toSchema |
142
+ | `GenerateResult` | type | `{ url, model, handle, drive? }` |
143
+ | `ClientConfig` | type | `{ fetch, apiUrl, drive? }` |
144
+ | `AuthenticatedFetch` | type | `(url, init?) => Promise<Response>` |
145
+ | `SdkTransport` | type | Advanced: custom transport interface |
146
+ | `WorkflowJobHandle` | type | Job handle for submit/status/cancel |
147
+
148
+ ## Package Structure
149
+
150
+ ```
151
+ packages/ai-sdk/
152
+ package.json
153
+ tsconfig.json
154
+ tsup.config.ts
155
+ src/
156
+ index.ts # Public API entry (7 exports)
157
+ client/
158
+ types.ts # ClientConfig, GenerateResult, DriveConfig
159
+ transport.ts # Authenticated fetch → SdkTransport
160
+ prepare.ts # Validate input, build payload, parse result
161
+ drive.ts # Drive folder management + file saving
162
+ index.ts # createClient() factory
163
+ core/
164
+ types.ts # ModelDefinition, ParamConfig, GenerationContext
165
+ workflow.ts # Generic polling/execution engine
166
+ contracts.ts # Runtime input validation
167
+ schema.ts # ParamConfig → JSON Schema
168
+ response.ts # Vendor-agnostic result extraction
169
+ pricing.ts # ToolId resolution
170
+ model-registry.ts # Model lookup indexes
171
+ providers.ts # Provider colors, labels, names
172
+ voices.ts # Voice catalogs (ElevenLabs, OpenAI, Gemini)
173
+ helpers.ts # Vendor utilities
174
+ generated/
175
+ model-constants.ts # AUTO-GENERATED: Models object + 108 constants
176
+ model-input-types.ts # AUTO-GENERATED: per-model TypeScript input types
177
+ vendors/
178
+ define.ts # defineModels() framework + params.* helpers
179
+ presets.ts # Reusable paramConfig factories
180
+ catalog/
181
+ index.ts # Aggregation: ALL_MODELS, VENDOR_CATALOGS
182
+ kling.ts # One file per vendor (31 total)
183
+ flux.ts
184
+ ...
185
+ __tests__/ # SDK tests
186
+ scripts/ # Build scripts
187
+ ```
188
+
189
+ ## Adding a New Model
190
+
191
+ ### Standard flow (pass-through payload)
192
+
193
+ When the backend accepts param values as-is (no field renaming needed):
194
+
195
+ 1. Add config in `src/vendors/catalog/{vendor}.ts` via `defineModels()`:
196
+ - `buildPayload` is **optional** — omit it and param values pass through as-is
197
+ 2. Run `npm run build:model-constants` to regenerate constants
198
+ 3. Run `npm run build:model-input-types` to regenerate TypeScript types
199
+ 4. Model automatically appears in `catalog.all()` and as the `Models.NewModel` id constant
200
+
201
+ ### With payload transforms
202
+
203
+ When the vendor API uses different field names or value formats:
204
+
205
+ 1. Define the model config as above (no `buildPayload`)
206
+ 2. Run `npm run build:model-input-types` — generates typed input for your model
207
+ 3. Create `src/vendors/catalog/{vendor}.payloads.ts`:
208
+ ```ts
209
+ import type { ModelInput } from '../../generated/model-input-types.ts';
210
+ import { registerPayloads } from '../define.ts';
211
+ import { SPECS, MODELS } from './{vendor}.ts';
212
+
213
+ registerPayloads({ SPECS, MODELS }, {
214
+ 'model-id': (input: ModelInput<'model-id'>) => ({
215
+ prompt: input.prompt,
216
+ aspect_ratio: input.aspectRatio, // rename for vendor API
217
+ }),
218
+ });
219
+ ```
220
+ 4. Import the `.payloads.ts` file in `src/vendors/catalog/index.ts` (after the vendor import)
221
+
222
+ See `src/vendors/catalog/imagen.ts` + `src/vendors/catalog/imagen.payloads.ts` for a working example.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@picsart/ai-sdk",
3
- "version": "3.17.4",
3
+ "version": "3.17.5",
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",