@picsart/ai-sdk 3.17.4 → 3.17.6

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 +224 -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,224 @@
1
+ # @picsart/ai-sdk
2
+
3
+ Generate images, video, audio, and text with 100+ AI models.
4
+
5
+ ## Documentation
6
+
7
+ Full guides, the model catalog, and the API reference live on the Picsart API Platform:
8
+
9
+ - [Documentation](https://picsart.com/api-platform/docs) -- overview and guides
10
+ - [Quickstart](https://picsart.com/api-platform/docs/quickstart) -- install, authenticate, first generation
11
+ - [SDK guide](https://picsart.com/api-platform/docs/sdk) -- client setup, `generate`/`generateText`, Drive, lifecycle
12
+ - [Authentication](https://picsart.com/api-platform/docs/authentication) -- create an API key
13
+ - [Model catalog](https://picsart.com/api-platform/models) -- browse every supported model
14
+ - [API reference](https://picsart.com/api-platform/docs/api-reference)
15
+
16
+ Repository: [github.com/PicsArt/ai-sdk](https://github.com/PicsArt/ai-sdk)
17
+
18
+ ## Quick Start
19
+
20
+ ```bash
21
+ npm install @picsart/ai-sdk
22
+ ```
23
+
24
+ ```typescript
25
+ import { createClient, Models, Model, catalog } from '@picsart/ai-sdk'
26
+
27
+ // Create a client — pass your authenticated fetch
28
+ const ai = createClient({
29
+ fetch: myAuthenticatedFetch,
30
+ apiUrl: 'https://api.picsart.com',
31
+ })
32
+
33
+ // Generate (Models.* are typed model-id constants)
34
+ const result = await ai.generate(Models.Flux2Pro, { prompt: 'a cat on mars' })
35
+ console.log(result.url)
36
+
37
+ // Browse models — the `catalog` accessor
38
+ catalog.all() // every model
39
+ catalog.find({ output: 'video' }) // video models only
40
+ catalog.search('kling') // search by name/id/provider
41
+
42
+ // Model metadata & params — the `Model` accessor
43
+ Model(Models.Flux2Pro).name // 'Flux 2 Pro'
44
+ Model(Models.Flux2Pro).meta() // mode, provider, badges, …
45
+ Model(Models.Flux2Pro).params() // accepted parameters
46
+ Model(Models.Flux2Pro).params().toSchema() // param schema
47
+
48
+ // Validate input (never throws) → { valid, errors? }
49
+ Model(Models.Flux2Pro).validate({ prompt: 'a cat' })
50
+ ```
51
+
52
+ ## Drive Integration
53
+
54
+ Auto-save generations to Picsart Drive:
55
+
56
+ ```typescript
57
+ const ai = createClient({
58
+ fetch: myAuthenticatedFetch,
59
+ apiUrl: 'https://api.picsart.com',
60
+ drive: { folder: 'AI Playground' },
61
+ })
62
+
63
+ // Generates and auto-saves to the root folder
64
+ const result = await ai.generate(Models.Flux2Pro, { prompt: 'a cat' })
65
+ // result.drive = { uid: '...', folder: { name: 'AI Playground', uid: '...' } }
66
+
67
+ // Save to a subfolder
68
+ const board = await ai.drive.ensureFolder('Cats')
69
+ const result = await ai.generate(Models.Flux2Pro, { prompt: 'a cat' }, { folder: board })
70
+
71
+ // Browse Drive
72
+ const folders = await ai.drive.folders()
73
+ const items = await ai.drive.list()
74
+ ```
75
+
76
+ ## Text Generation (LLMs)
77
+
78
+ Claude, GPT, and Gemini text models are called with `generateText()`. Single-shot:
79
+ pass a prompt and optional image(s)/video, get text back. They surface in the catalog
80
+ as `mode: 'text'`. Each vendor uses its own native workflow, so capabilities aren't lost
81
+ — Gemini accepts video input, Claude uses the Anthropic-native messages API.
82
+
83
+ ```typescript
84
+ import { createClient, Models } from '@picsart/ai-sdk'
85
+
86
+ const ai = createClient({ fetch: myAuthenticatedFetch, apiUrl: 'https://api.picsart.com' })
87
+
88
+ // Text in, text out
89
+ const { text } = await ai.generateText(Models.ClaudeOpus48, { prompt: 'Explain RAG in one line.' })
90
+ console.log(text)
91
+
92
+ // Optional vision input + reasoning level (OpenAI / Gemini)
93
+ const res = await ai.generateText(Models.Gpt55, {
94
+ prompt: 'What is in this image?',
95
+ imageUrls: ['https://cdn.example.com/photo.jpg'],
96
+ thinking: 'high', // 'off' | 'low' | 'medium' | 'high'
97
+ })
98
+ console.log(res.text)
99
+ console.log(res.raw) // full backend response — usage, finish_reason, etc.
100
+
101
+ // Gemini accepts video input
102
+ await ai.generateText(Models.Gemini3Pro, {
103
+ prompt: 'Summarize this clip',
104
+ videoUrl: 'https://cdn.example.com/clip.mp4',
105
+ })
106
+
107
+ // Browse text models
108
+ catalog.find({ output: 'text' })
109
+ ```
110
+
111
+ > Thinking level maps per vendor: OpenAI → `reasoning_effort`, Gemini →
112
+ > `thinkingConfig.thinkingLevel` (LOW/HIGH). Claude’s `claude/v1/messages`
113
+ > workflow exposes no thinking knob, so Claude models omit `thinking`.
114
+
115
+ `generateText()` is type-narrowed to text models (`TextModelId`); calling it with an
116
+ image/video model throws, and `generate()` throws on a text model — use the matching
117
+ method for each.
118
+
119
+ ## Advanced Lifecycle
120
+
121
+ For progress tracking, cancellation, and job recovery:
122
+
123
+ ```typescript
124
+ // Submit without waiting
125
+ const handle = await ai.submit(Models.KlingV3Pro, { prompt: 'a sunset' })
126
+
127
+ // Subscribe to status updates
128
+ for await (const update of ai.subscribe(handle)) {
129
+ console.log(update.status, update.progress?.percent)
130
+ }
131
+
132
+ // Or poll manually
133
+ const status = await ai.status(handle)
134
+ ```
135
+
136
+ ## Public API
137
+
138
+ The SDK exports 7 symbols:
139
+
140
+ | Export | Type | Description |
141
+ |--------|------|-------------|
142
+ | `createClient` | function | Create an AI client from authenticated fetch |
143
+ | `Models` | object | Model catalog: 108 models + list/search/validate/toSchema |
144
+ | `GenerateResult` | type | `{ url, model, handle, drive? }` |
145
+ | `ClientConfig` | type | `{ fetch, apiUrl, drive? }` |
146
+ | `AuthenticatedFetch` | type | `(url, init?) => Promise<Response>` |
147
+ | `SdkTransport` | type | Advanced: custom transport interface |
148
+ | `WorkflowJobHandle` | type | Job handle for submit/status/cancel |
149
+
150
+ ## Package Structure
151
+
152
+ ```
153
+ packages/ai-sdk/
154
+ package.json
155
+ tsconfig.json
156
+ tsup.config.ts
157
+ src/
158
+ index.ts # Public API entry (7 exports)
159
+ client/
160
+ types.ts # ClientConfig, GenerateResult, DriveConfig
161
+ transport.ts # Authenticated fetch → SdkTransport
162
+ prepare.ts # Validate input, build payload, parse result
163
+ drive.ts # Drive folder management + file saving
164
+ index.ts # createClient() factory
165
+ core/
166
+ types.ts # ModelDefinition, ParamConfig, GenerationContext
167
+ workflow.ts # Generic polling/execution engine
168
+ contracts.ts # Runtime input validation
169
+ schema.ts # ParamConfig → JSON Schema
170
+ response.ts # Vendor-agnostic result extraction
171
+ pricing.ts # ToolId resolution
172
+ model-registry.ts # Model lookup indexes
173
+ providers.ts # Provider colors, labels, names
174
+ voices.ts # Voice catalogs (ElevenLabs, OpenAI, Gemini)
175
+ helpers.ts # Vendor utilities
176
+ generated/
177
+ model-constants.ts # AUTO-GENERATED: Models object + 108 constants
178
+ model-input-types.ts # AUTO-GENERATED: per-model TypeScript input types
179
+ vendors/
180
+ define.ts # defineModels() framework + params.* helpers
181
+ presets.ts # Reusable paramConfig factories
182
+ catalog/
183
+ index.ts # Aggregation: ALL_MODELS, VENDOR_CATALOGS
184
+ kling.ts # One file per vendor (31 total)
185
+ flux.ts
186
+ ...
187
+ __tests__/ # SDK tests
188
+ scripts/ # Build scripts
189
+ ```
190
+
191
+ ## Adding a New Model
192
+
193
+ ### Standard flow (pass-through payload)
194
+
195
+ When the backend accepts param values as-is (no field renaming needed):
196
+
197
+ 1. Add config in `src/vendors/catalog/{vendor}.ts` via `defineModels()`:
198
+ - `buildPayload` is **optional** — omit it and param values pass through as-is
199
+ 2. Run `npm run build:model-constants` to regenerate constants
200
+ 3. Run `npm run build:model-input-types` to regenerate TypeScript types
201
+ 4. Model automatically appears in `catalog.all()` and as the `Models.NewModel` id constant
202
+
203
+ ### With payload transforms
204
+
205
+ When the vendor API uses different field names or value formats:
206
+
207
+ 1. Define the model config as above (no `buildPayload`)
208
+ 2. Run `npm run build:model-input-types` — generates typed input for your model
209
+ 3. Create `src/vendors/catalog/{vendor}.payloads.ts`:
210
+ ```ts
211
+ import type { ModelInput } from '../../generated/model-input-types.ts';
212
+ import { registerPayloads } from '../define.ts';
213
+ import { SPECS, MODELS } from './{vendor}.ts';
214
+
215
+ registerPayloads({ SPECS, MODELS }, {
216
+ 'model-id': (input: ModelInput<'model-id'>) => ({
217
+ prompt: input.prompt,
218
+ aspect_ratio: input.aspectRatio, // rename for vendor API
219
+ }),
220
+ });
221
+ ```
222
+ 4. Import the `.payloads.ts` file in `src/vendors/catalog/index.ts` (after the vendor import)
223
+
224
+ 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.6",
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",