@picsart/ai-sdk 3.24.0 → 3.24.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.
Files changed (3) hide show
  1. package/README.md +35 -7
  2. package/index.js +7 -0
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -24,9 +24,9 @@ npm install @picsart/ai-sdk
24
24
  ```typescript
25
25
  import { createClient, Models, Model, catalog } from '@picsart/ai-sdk'
26
26
 
27
- // Create a client — pass your authenticated fetch
27
+ // Create a client — pass your Picsart API key
28
28
  const ai = createClient({
29
- fetch: myAuthenticatedFetch,
29
+ apiKey: process.env.PICSART_API_KEY,
30
30
  apiUrl: 'https://api.picsart.com',
31
31
  })
32
32
 
@@ -49,13 +49,41 @@ Model(Models.Flux2Pro).params().toSchema() // param schema
49
49
  Model(Models.Flux2Pro).validate({ prompt: 'a cat' })
50
50
  ```
51
51
 
52
+ ## Authentication
53
+
54
+ Pass `apiKey` and the SDK sends `Authorization: Bearer <apiKey>` on every request
55
+ (a leading `Bearer ` is stripped if present). Create a key from the
56
+ [Authentication guide](https://picsart.com/api-platform/docs/authentication).
57
+
58
+ ```typescript
59
+ const ai = createClient({
60
+ apiKey: process.env.PICSART_API_KEY,
61
+ apiUrl: 'https://api.picsart.com',
62
+ })
63
+ ```
64
+
65
+ Keep the key server-side — anything shipped to a browser is public.
66
+
67
+ Apps that already handle auth themselves (session cookies, token refresh, a
68
+ backend proxy) can pass their own `fetch` instead. It takes precedence over
69
+ `apiKey` when both are set:
70
+
71
+ ```typescript
72
+ const ai = createClient({
73
+ fetch: myAuthenticatedFetch,
74
+ apiUrl: 'https://api.picsart.com',
75
+ })
76
+ ```
77
+
78
+ `createClient` throws if neither `apiKey` nor `fetch` is provided.
79
+
52
80
  ## Drive Integration
53
81
 
54
82
  Auto-save generations to Picsart Drive:
55
83
 
56
84
  ```typescript
57
85
  const ai = createClient({
58
- fetch: myAuthenticatedFetch,
86
+ apiKey: process.env.PICSART_API_KEY,
59
87
  apiUrl: 'https://api.picsart.com',
60
88
  drive: { folder: 'AI Playground' },
61
89
  })
@@ -83,7 +111,7 @@ as `mode: 'text'`. Each vendor uses its own native workflow, so capabilities are
83
111
  ```typescript
84
112
  import { createClient, Models } from '@picsart/ai-sdk'
85
113
 
86
- const ai = createClient({ fetch: myAuthenticatedFetch, apiUrl: 'https://api.picsart.com' })
114
+ const ai = createClient({ apiKey: process.env.PICSART_API_KEY, apiUrl: 'https://api.picsart.com' })
87
115
 
88
116
  // Text in, text out
89
117
  const { text } = await ai.generateText(Models.ClaudeOpus48, { prompt: 'Explain RAG in one line.' })
@@ -139,11 +167,11 @@ The SDK exports 7 symbols:
139
167
 
140
168
  | Export | Type | Description |
141
169
  |--------|------|-------------|
142
- | `createClient` | function | Create an AI client from authenticated fetch |
170
+ | `createClient` | function | Create an AI client from an API key (or a custom authenticated fetch) |
143
171
  | `Models` | object | Model catalog: 108 models + list/search/validate/toSchema |
144
172
  | `GenerateResult` | type | `{ url, model, handle, drive? }` |
145
- | `ClientConfig` | type | `{ fetch, apiUrl, drive? }` |
146
- | `AuthenticatedFetch` | type | `(url, init?) => Promise<Response>` |
173
+ | `ClientConfig` | type | `{ apiKey?, fetch?, apiUrl, drive? }` — one of `apiKey` / `fetch` required |
174
+ | `AuthenticatedFetch` | type | `(url, init?) => Promise<Response>` — for the custom-`fetch` path |
147
175
  | `SdkTransport` | type | Advanced: custom transport interface |
148
176
  | `WorkflowJobHandle` | type | Job handle for submit/status/cancel |
149
177
 
package/index.js CHANGED
@@ -8553,6 +8553,10 @@ function resolveModel(id) {
8553
8553
  }
8554
8554
 
8555
8555
  // src/client/transport.ts
8556
+ var GATEWAY_HEADERS = {
8557
+ "platform": "api",
8558
+ "X-Touchpoint": "sdk"
8559
+ };
8556
8560
  function resolveFetch(config) {
8557
8561
  if (config.fetch) return config.fetch;
8558
8562
  if (config.apiKey) {
@@ -8560,6 +8564,9 @@ function resolveFetch(config) {
8560
8564
  return (url, init) => {
8561
8565
  const headers = new Headers(init?.headers);
8562
8566
  headers.set("Authorization", `Bearer ${token}`);
8567
+ for (const [name, value] of Object.entries(GATEWAY_HEADERS)) {
8568
+ if (!headers.has(name)) headers.set(name, value);
8569
+ }
8563
8570
  return globalThis.fetch(url, { ...init, headers });
8564
8571
  };
8565
8572
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@picsart/ai-sdk",
3
- "version": "3.24.0",
3
+ "version": "3.24.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",