@devvibex/aiflow 1.13.0 → 1.14.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
@@ -97,20 +97,23 @@ to invalidate the cache.
97
97
  {
98
98
  appId: string,
99
99
  models: {
100
- chat: string[], // e.g. ["claude-sonnet-4-6", "gpt-4o", ...]
100
+ chat: string[], // version-less ids, e.g. ["claude-opus", "gpt", ...]
101
101
  image: string[],
102
102
  embed: string[],
103
103
  video: string[],
104
- audio: string[], // Lyria — e.g. ["lyria-3-clip-preview", ...]
105
- sfx: string[], // ElevenLabs — e.g. ["eleven_text_to_sound_v2"]
104
+ audio: string[], // Lyria 3.5 — ["lyria-pro"]
105
+ sfx: string[], // ElevenLabs — ["elevenlabs-sfx"]
106
106
  },
107
107
  defaults: { chat: string, image: string, embed: string, video: string, audio: string, sfx: string },
108
+ imageBackgroundModels: string[], // image models that honour `background`
109
+ audioImageInputModels: string[], // audio models that take `images`
108
110
  limits: {
109
111
  maxTokens: number,
110
112
  maxImageN: number,
111
113
  maxEmbedInputs: number,
112
114
  minSfxDurationSeconds: number,
113
115
  maxSfxDurationSeconds: number,
116
+ maxAudioInputImages: number,
114
117
  },
115
118
  creditValue: number,
116
119
  }
@@ -125,17 +128,25 @@ Returns `Promise<{ id, model, content, usage: { inputTokens, outputTokens, credi
125
128
  Async iterable of `{ delta: string, done: boolean }` chunks. The final chunk
126
129
  has `done: true` and carries the cumulative `usage` object.
127
130
 
128
- ### `aiflow.generateImage({ prompt, model?, size?, n?, image?, images?, system?, language?, signal? })`
131
+ ### `aiflow.generateImage({ prompt, model?, size?, n?, image?, images?, system?, language?, background?, signal? })`
129
132
 
130
133
  Returns `{ images: [{ url?, b64?, mimeType }], usage: { creditsUsed } }`.
131
134
  `url` is a short-lived signed URL (~1h). Pass `image`/`images` to edit an
132
- existing image (image-to-image) instead of generating from text.
135
+ existing image (image-to-image) instead of generating from text. `background`
136
+ (`'auto'` | `'transparent'` | `'opaque'`) is honoured only by the models in
137
+ `config.imageBackgroundModels`; `generateImageBatch` takes it top-level or per
138
+ page. The module default is set with `admin.updateConfig({ imageBackground })`.
133
139
 
134
140
  ### `aiflow.generateVideo({ prompt, model?, aspectRatio?, image?, video?, signal? })`
135
141
 
136
142
  Returns `{ videoUrl, usage: { creditsUsed } }`. Pass `image` for image-to-video
137
143
  or `video` for video-to-video; omit both for pure text-to-video.
138
144
 
145
+ The default model is **Gemini Omni**: one clip of ~10s, **with sound**, 16:9 or
146
+ 9:16 only, and no length parameter. For a longer or extendable video use
147
+ `generateLongVideo` / `createVideoSession` below — same model, so a single clip
148
+ and an extended one look and sound alike. Veo and Seedance are opt-in per module.
149
+
139
150
  ### `aiflow.generateLongVideo({ prompt, durationSeconds, ... })` — long video from one prompt
140
151
 
141
152
  One prompt plus a duration, one call, one finished video. The gateway splits your
@@ -143,10 +154,16 @@ prompt into a storyboard of ~10s beats, generates the opening clip, then extends
143
154
  turn after turn — concatenating as it goes — until the timeline reaches the
144
155
  length you asked for.
145
156
 
157
+ **Maximum 40 seconds.** A video is one Gemini Omni chain: an opening clip of up
158
+ to 10s (its default and its maximum) plus consecutive extends, 40s in total.
159
+ That is a model limit, not a setting — ask for more and you get 40s back with a
160
+ `warning` saying so. Past 40s, generate several videos and join them with
161
+ `mergeVideos` (below) — the joins are hard cuts.
162
+
146
163
  ```js
147
164
  const video = await aiflow.generateLongVideo({
148
165
  prompt: 'A lighthouse keeper climbing the spiral stairs at dawn, then the lamp sweeping out over the water',
149
- durationSeconds: 30,
166
+ durationSeconds: 30, // 5-40
150
167
  aspectRatio: '16:9',
151
168
  onProgress: ({ segmentsDone, segmentsPlanned, durationSeconds, videoUrl }) => {
152
169
  // videoUrl is ALREADY PLAYABLE — show the partial video, not a spinner
@@ -161,53 +178,32 @@ video.usage.creditsUsed;
161
178
  video.warning; // set if it finished shorter than asked (still playable)
162
179
  ```
163
180
 
164
- **Two shapes, chosen automatically from the duration you ask for:**
165
-
166
- | | up to 2 min | over 2 min |
167
- |---|---|---|
168
- | Shape | ONE continuous shot (chained) | independent SCENES, hard cuts |
169
- | Generated | sequentially — each clip continues the last | **in parallel** |
170
- | 10 min of video | impossible (~2.75h, and continuity is gone after ~1 min) | ~55 min |
171
- | Resumable | no (extend it instead) | **yes** — `resumeLongVideo` |
172
-
173
- Because scenes run in parallel, a 2m01s video finishes FASTER than a 2m00s one
174
- (~14 min vs ~33 min). That is not a bug: past two minutes there is no continuous
175
- shot left to preserve, so the build stops paying for sequencing.
176
-
177
- Long-form scenes are planned to restate the subject and style verbatim in every
178
- scene, which is what holds the film together visually across the cuts.
179
-
180
- ```js
181
- // 10 minutes. ~60 scenes, ~55 min of building, ~$61 of provider cost.
182
- const film = await aiflow.generateLongVideo({ prompt, durationSeconds: 600, onProgress });
183
-
184
- // If it stopped short (gateway restart, provider hiccup, credits ran out):
185
- if (film.warning) {
186
- const finished = await aiflow.resumeLongVideo(film.sessionId, { onProgress });
187
- }
188
- ```
189
-
190
- `resumeLongVideo` regenerates **only the missing scenes** — every finished scene
191
- is already paid for and is never regenerated. That is what makes an hours-long
192
- build survivable, so treat `warning` as "call resume", not as a failure.
181
+ The result is always ONE CONTINUOUS SHOT — each clip continues the last — and
182
+ `extendVideo` can lengthen it afterwards while it is still under 40s.
193
183
 
194
- Design the UI around three facts:
184
+ Design the UI around four facts:
195
185
 
196
- - **It takes a long time** — roughly 2.5–3 minutes per 10 seconds for a
197
- continuous video (~8 min for 30s, ~33 min for 2 min), and roughly that divided
198
- by the gateway's scene concurrency for long-form (~55 min for 10 min of video).
199
- `onProgress` fires after each clip, so show progress — and for continuous
200
- builds the partial video, which is already playable.
201
- - **The result is "at least" the requested length.** Omni cannot be asked for a
202
- clip length, so the timeline overshoots by up to one segment.
186
+ - **Cap the duration control at 40s.** Preset chips (10s / 20s / 30s / 40s) say
187
+ it most clearly. Anything above is clamped, not honoured.
188
+ - **It takes a long time** — roughly 2.5–3 minutes per 10 seconds, so ~8 min for
189
+ a 30s video and ~10 for the full 40s. `onProgress` fires after each clip, so
190
+ show progress and the partial video, which is already playable.
191
+ - **The result is "at least" the requested length** (up to the 40s cap). Omni
192
+ cannot be asked for a clip length, so the timeline overshoots by up to one
193
+ segment.
203
194
  - **A short build still resolves.** If a turn fails or credits run out mid-way,
204
195
  you get the shorter video plus `warning` explaining why — show both; it is not
205
196
  an error.
206
197
 
198
+ `resumeLongVideo(sessionId)` exists for the older **scene-based** long-form
199
+ builds (parallel scenes with hard cuts, `session.mode === 'scenes'`). No new
200
+ session is built that way while the 40s cap is in place; the method stays for
201
+ sessions created before it.
202
+
207
203
  Cost scales with the finished length (Omni bills per delivered second), so show a
208
- credit estimate before calling. The platform caps what can be requested
209
- (`AIFLOW_VIDEO_MAX_TARGET_SECONDS`, default 120s); a larger request is clamped,
210
- not refused.
204
+ credit estimate before calling. A deployment can lower the cap below 40s
205
+ (`AIFLOW_VIDEO_MAX_TARGET_SECONDS`) but never raise it; either way a larger
206
+ request is clamped, not refused.
211
207
 
212
208
  Under the hood this is a video session (below) that the gateway drives for you —
213
209
  `sessionId` comes back on the result, so you can keep extending it manually
@@ -255,9 +251,10 @@ interaction it still holds server-side. The gateway concatenates the segments
255
251
  and always hands back the whole timeline, so your app plays **one url** and
256
252
  never stitches anything itself.
257
253
 
258
- Requires a Gemini Omni model — Veo and Seedance hold no context between calls,
259
- so the gateway refuses to open a session on them rather than accept one clip and
260
- then fail every extend. Total length is capped at **40 seconds**.
254
+ Runs on Gemini Omni — Veo and Seedance hold no context between calls. Leave
255
+ `model` unset: the gateway uses Omni even when the module's video model is Veo
256
+ or Seedance, and refuses only a non-Omni model you pass explicitly. Total length
257
+ is capped at **40 seconds**.
261
258
 
262
259
  ```js
263
260
  // 1. Open a session — generate the opening clip…
@@ -267,10 +264,11 @@ const { sessionId, jobId } = await aiflow.createVideoSession({
267
264
  });
268
265
  const opening = await aiflow.getVideoJob(jobId); // poll until 'succeeded'
269
266
 
270
- // …or seed it from the user's own clip instead (no jobId — ready on return;
271
- // a clip longer than 10s is trimmed to its last 10s, Omni's input limit)
267
+ // …or seed it from a clip you already have — an upload, a generateVideo or a
268
+ // mergeVideos result (no jobId — ready on return). The WHOLE clip stays on the
269
+ // timeline and counts toward the 40s, so up to 37s; Omni continues from its end.
272
270
  const { sessionId: seeded } = await aiflow.createVideoSession({
273
- video: uploadedVideoUrlOrDataUrl,
271
+ video: existingVideoUrlOrDataUrl,
274
272
  });
275
273
 
276
274
  // 2. Extend. Keep the prompt SIMPLE — terse continuation prompts extend best.
@@ -299,12 +297,16 @@ job's `videoUrl` is the timeline and `segmentUrl` the new tail.
299
297
  Every turn is billed separately (Omni prices by output token), and
300
298
  `session.usage.creditsUsed` is the running total for the whole session.
301
299
 
302
- ### `aiflow.generateAudio({ prompt, model?, negativePrompt?, seed?, signal?, timeout? })`
300
+ ### `aiflow.generateAudio({ prompt, model?, images?, signal?, timeout? })`
303
301
 
304
- Generate music / background audio from a text prompt (Google Vertex AI **Lyria**).
305
- Returns `{ audioUrl, model, durationSeconds, usage: { creditsUsed } }`. `audioUrl`
306
- is a hosted mp3/wav on the CDN. `prompt` should be a musical description (mood,
307
- genre, tempo/BPM, instrumentation). `negativePrompt`/`seed` apply to Lyria 2 only.
302
+ Generate music from a text prompt with Google **Lyria 3.5**. Returns
303
+ `{ audioUrl, model, durationSeconds, usage: { creditsUsed } }`; `audioUrl` is a
304
+ hosted mp3 on the CDN. `prompt` is a musical description (mood, genre,
305
+ tempo/BPM, instrumentation), and length or exclusions go in it too ("about 30
306
+ seconds, seamless loop", "no vocals"). `images` takes up to 10 https:// or
307
+ data: URLs for the music to be inspired by, on the models in
308
+ `config.audioImageInputModels`. `negativePrompt` / `seed` are still accepted
309
+ but ignored by Lyria 3.5.
308
310
 
309
311
  ### `aiflow.generateSfx({ prompt, model?, durationSeconds?, signal?, timeout? })`
310
312
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devvibex/aiflow",
3
- "version": "1.13.0",
3
+ "version": "1.14.0",
4
4
  "description": "First-party LLM gateway SDK for apps generated on the VibeX platform — chat, streaming, image, video (including stateful multi-turn video extension with Gemini Omni), music (Lyria), sound effects (ElevenLabs), embeddings and real-time speech translation (Gemini Live) without shipping any third-party API key.",
5
5
  "keywords": [
6
6
  "ai",
package/src/index.d.ts CHANGED
@@ -84,6 +84,9 @@ export interface ChatStreamChunk {
84
84
  [key: string]: unknown;
85
85
  }
86
86
 
87
+ /** Values for the image `background` option. */
88
+ export type ImageBackground = 'auto' | 'transparent' | 'opaque';
89
+
87
90
  export interface ImageRequest {
88
91
  prompt: string;
89
92
  model?: string;
@@ -102,6 +105,12 @@ export interface ImageRequest {
102
105
  * `{{language}}` placeholder in the system/user prompt server-side.
103
106
  */
104
107
  language?: string;
108
+ /**
109
+ * What sits behind the subject: 'auto' (model decides, the default),
110
+ * 'transparent' (alpha PNG) or 'opaque'. Honoured only by the models in
111
+ * `config.imageBackgroundModels`; other models ignore it.
112
+ */
113
+ background?: ImageBackground;
105
114
  signal?: AbortSignal;
106
115
  /** Per-call timeout (ms). Defaults to 180000 — image edits exceed the 60s client default. */
107
116
  timeout?: number;
@@ -135,6 +144,8 @@ export interface ImageBatchPage {
135
144
  images?: string[];
136
145
  system?: string;
137
146
  language?: string;
147
+ /** Per-page override of the shared `background`. */
148
+ background?: ImageBackground;
138
149
  }
139
150
 
140
151
  export interface ImageBatchRequest {
@@ -148,6 +159,8 @@ export interface ImageBatchRequest {
148
159
  size?: '512x512' | '1024x1024' | '1024x1792' | string;
149
160
  /** Max pages processed simultaneously (1–4, default 3 server-side). */
150
161
  concurrency?: number;
162
+ /** Shared `background` for every page — see {@link ImageRequest.background}. */
163
+ background?: ImageBackground;
151
164
  signal?: AbortSignal;
152
165
  /** Per-call timeout (ms). Defaults to 600000 (10 min). */
153
166
  timeout?: number;
@@ -173,25 +186,28 @@ export interface ImageBatchResponse {
173
186
  export interface VideoRequest {
174
187
  prompt: string;
175
188
  /**
176
- * Video model. Defaults to the app's configured default. Veo models
177
- * (`veo-*`) run on Google Vertex; Seedance/Dreamina
178
- * (`dreamina-seedance-*`) run on BytePlus Ark.
189
+ * Video model: `'gemini-omni'` | `'veo'` | `'seedance'`. Defaults to the
190
+ * app's configured model, which is Gemini Omni unless the module was pinned
191
+ * to another one. Omni clips always have sound and are the only ones that
192
+ * can be extended (see {@link AIFlowClient.createVideoSession}).
179
193
  */
180
194
  model?: string;
181
195
  /**
182
- * Output aspect ratio. Veo supports 16:9 / 9:16 / 1:1; Seedance also
183
- * accepts 4:3 / 3:4 / 21:9 (the server maps unsupported ratios to 16:9).
196
+ * Output aspect ratio. Gemini Omni supports 16:9 / 9:16 only; Veo also 1:1;
197
+ * Seedance also 1:1 / 4:3 / 3:4 / 21:9. An unsupported ratio is mapped to
198
+ * 16:9 by the server.
184
199
  */
185
200
  aspectRatio?: '16:9' | '9:16' | '1:1' | '4:3' | '3:4' | '21:9' | string;
186
201
  /**
187
- * Output resolution (Seedance/Dreamina only): '480p' | '720p' | '1080p'.
188
- * Lower resolution generates faster. Defaults to the app's server-side
189
- * default (720p) when omitted. Ignored by Veo.
202
+ * Output resolution: '720p' (default) | '1080p' on Gemini Omni and
203
+ * Seedance; Seedance also '480p' (Omni treats it as 720p). Lower generates
204
+ * faster and, on Omni, costs less. Ignored by Veo.
190
205
  */
191
206
  resolution?: '480p' | '720p' | '1080p' | string;
192
207
  /**
193
- * Clip length in seconds. Seedance 2.0 supports an integer 4–15 (clamped to
194
- * that range, default 5). Ignored by Veo, which uses a fixed length per mode.
208
+ * Clip length in seconds — Seedance only: an integer 4–15 (clamped to that
209
+ * range, default 5). Gemini Omni takes no length and returns a ~10s clip
210
+ * (longer: {@link AIFlowClient.generateLongVideo}); Veo uses a fixed length.
195
211
  */
196
212
  duration?: number;
197
213
  /** Burn the provider watermark into the output (Seedance only). */
@@ -333,9 +349,9 @@ export interface VideoSessionRequest {
333
349
  */
334
350
  prompt?: string;
335
351
  /**
336
- * Must be a Gemini Omni model — it is the only one with a stateful extend
337
- * protocol. Defaults to the module's configured video model, which the
338
- * gateway rejects if it is not Omni.
352
+ * Leave unset. Sessions run on Gemini Omni — the only model with a stateful
353
+ * extend protocol — and the gateway picks it even when the module's video
354
+ * model is Veo or Seedance. A non-Omni model passed here is rejected.
339
355
  */
340
356
  model?: string;
341
357
  /** Omni supports 16:9 and 9:16 only. Fixed for the whole session. */
@@ -345,9 +361,11 @@ export interface VideoSessionRequest {
345
361
  /** Still image to animate into the opening clip (image-to-video). */
346
362
  image?: string;
347
363
  /**
348
- * Your OWN clip to seed the timeline with instead of generating an opener.
349
- * An `https://` or `data:` URL. Longer than 10s is trimmed to its last 10s
350
- * (Omni's input limit).
364
+ * A clip you already have — an upload, a `generateVideo` or a
365
+ * `mergeVideos` result — to seed the timeline with instead of generating an
366
+ * opener. An `https://` or `data:` URL. The WHOLE clip stays on the timeline
367
+ * and counts toward the 40s cap, so it may be at most 37s (longer is a 400);
368
+ * the model continues from its last ~10s (Omni's input limit).
351
369
  */
352
370
  video?: string;
353
371
  description?: string;
@@ -377,9 +395,14 @@ export interface LongVideoRequest {
377
395
  /** What the whole video shows. The gateway splits it into per-segment beats. */
378
396
  prompt: string;
379
397
  /**
380
- * How long the finished video should be, in seconds. The result is "at
381
- * least" this: Omni cannot be asked for a clip length, so the timeline
382
- * overshoots by up to one ~10s segment.
398
+ * How long the finished video should be, in seconds — **5 to 40**.
399
+ *
400
+ * 40s is a model limit: a video is one Omni chain (an opening clip of up to
401
+ * 10s, then consecutive extends) and Google will not extend one past 40s.
402
+ * A larger number is CLAMPED to 40 and the result carries a `warning`.
403
+ *
404
+ * The result is "at least" this, up to the cap: Omni cannot be asked for a
405
+ * clip length, so the timeline overshoots by up to one ~10s segment.
383
406
  */
384
407
  durationSeconds: number;
385
408
  /** Must be a Gemini Omni model; defaults to the module's video model. */
@@ -403,9 +426,9 @@ export interface LongVideoResponse extends VideoResponse {
403
426
  durationSeconds?: number;
404
427
  segmentsDone?: number;
405
428
  /**
406
- * Set when the build came up short of `durationSeconds`. The video is real
407
- * and already paid for — show it, and the reason; do not treat it as an
408
- * error.
429
+ * Set when the build came up short of `durationSeconds`, or when the request
430
+ * was clamped to the 40s maximum. The video is real and already paid for —
431
+ * show it, and the reason; do not treat it as an error.
409
432
  */
410
433
  warning?: string;
411
434
  }
@@ -464,15 +487,24 @@ export interface VideoExtendSubmitResponse extends VideoJobSubmitResponse {
464
487
  sessionId: string;
465
488
  }
466
489
 
467
- // ─── Audio (music — Lyria) ──────────────────────────────────────────────────
490
+ // ─── Audio (music — Lyria 3.5) ──────────────────────────────────────────────
468
491
 
469
492
  export interface AudioRequest {
470
- /** Musical description — mood, genre, tempo (BPM), instrumentation, texture. */
493
+ /**
494
+ * Musical description — mood, genre, tempo (BPM), instrumentation, texture,
495
+ * length ("about 30 seconds") and exclusions ("no vocals").
496
+ */
471
497
  prompt: string;
472
498
  model?: string;
473
- /** Things to steer away from. Lyria 2 only — ignored by Lyria 3. */
499
+ /**
500
+ * Up to `config.limits.maxAudioInputImages` (10) reference images — https://
501
+ * or data: URLs — that the music should be inspired by. Only for models in
502
+ * `config.audioImageInputModels`; the gateway answers 400 otherwise.
503
+ */
504
+ images?: string[];
505
+ /** Ignored by Lyria 3.5 — put exclusions in `prompt`. */
474
506
  negativePrompt?: string;
475
- /** Deterministic seed (Lyria 2 only). */
507
+ /** Ignored by Lyria 3.5. */
476
508
  seed?: number;
477
509
  signal?: AbortSignal;
478
510
  /** Per-call timeout (ms). Defaults to 180000 (3 min) — music gen is slow. */
@@ -810,12 +842,20 @@ export interface AiflowConfig {
810
842
  modelUserSelectable?: boolean;
811
843
  /** Per-feature form of `modelUserSelectable`. */
812
844
  userSelectable?: Record<string, boolean>;
845
+ /** Module default for the image `background` option. */
846
+ imageBackground?: ImageBackground;
847
+ /** Image models that honour `background`. */
848
+ imageBackgroundModels?: string[];
849
+ /** Audio models that accept reference `images` in `generateAudio`. */
850
+ audioImageInputModels?: string[];
813
851
  limits: {
814
852
  maxTokens: number;
815
853
  maxImageN: number;
816
854
  maxEmbedInputs: number;
817
855
  minSfxDurationSeconds: number;
818
856
  maxSfxDurationSeconds: number;
857
+ /** Reference images per `generateAudio` call. */
858
+ maxAudioInputImages?: number;
819
859
  };
820
860
  creditValue: number;
821
861
  /** Module-configured default system prompt, or null if none. */
@@ -838,6 +878,12 @@ export interface AiflowAdminModule {
838
878
  title: string | null;
839
879
  systemPrompt: string | null;
840
880
  defaults: Record<string, string>;
881
+ /** Per-feature "User Selection" flags, key-for-key with `defaults`. */
882
+ userSelectable?: Record<string, boolean>;
883
+ /** Stored default for the image `background` option. */
884
+ imageBackground?: ImageBackground;
885
+ /** Image models that honour `background`. */
886
+ imageBackgroundModels?: string[];
841
887
  models: string[];
842
888
  }
843
889
 
@@ -852,6 +898,8 @@ export interface AiflowAdminUpdateConfigInput {
852
898
  defaults?: Record<string, string>;
853
899
  /** Sugar: sets the chat default model (folded into `defaults.chat`). */
854
900
  defaultModel?: string;
901
+ /** Default image `background` for the module. Top-level — never inside `defaults`. */
902
+ imageBackground?: ImageBackground;
855
903
  }
856
904
 
857
905
  /**
@@ -967,6 +1015,10 @@ export class AIFlowClient {
967
1015
  * the gateway storyboards the prompt into ~10s beats, generates them turn by
968
1016
  * turn and concatenates them into one finished clip.
969
1017
  *
1018
+ * **Maximum 40 seconds** — see {@link LongVideoRequest.durationSeconds}.
1019
+ * For anything longer, generate several videos and {@link mergeVideos} them;
1020
+ * the joins are hard cuts.
1021
+ *
970
1022
  * Takes MINUTES (roughly two to three per 10s). `onProgress` fires after
971
1023
  * every segment with a playable partial `videoUrl` — build the UI around
972
1024
  * that, not a spinner.
@@ -986,6 +1038,11 @@ export class AIFlowClient {
986
1038
  * provider hiccup, or credits that have since been topped up. Only missing
987
1039
  * scenes are generated; finished ones are already paid for and are never
988
1040
  * regenerated. Resolves with the re-assembled video.
1041
+ *
1042
+ * Applies to SCENE-based sessions (`mode === 'scenes'`) only. None are
1043
+ * created while the 40s cap is in place — every new build is continuous and
1044
+ * is lengthened with {@link extendVideo} — so this serves sessions made
1045
+ * before it. A continuous session is rejected with a 400.
989
1046
  */
990
1047
  resumeLongVideo(
991
1048
  sessionId: string,
package/src/index.js CHANGED
@@ -403,6 +403,7 @@ export class AIFlowClient {
403
403
  images,
404
404
  system,
405
405
  language,
406
+ background,
406
407
  signal,
407
408
  timeout,
408
409
  } = {}) {
@@ -426,6 +427,9 @@ export class AIFlowClient {
426
427
  images,
427
428
  system: resolvedSystem,
428
429
  language,
430
+ // 'auto' | 'transparent' | 'opaque' — honoured only by the
431
+ // models in `config.imageBackgroundModels`.
432
+ background,
429
433
  },
430
434
  // Image edits (esp. document translation) routinely exceed the 60s
431
435
  // client default — a single 2K edit was observed at ~63s. Default
@@ -455,6 +459,7 @@ export class AIFlowClient {
455
459
  language,
456
460
  size,
457
461
  concurrency,
462
+ background,
458
463
  signal,
459
464
  timeout,
460
465
  } = {}) {
@@ -474,6 +479,7 @@ export class AIFlowClient {
474
479
  language,
475
480
  size,
476
481
  concurrency,
482
+ background,
477
483
  },
478
484
  // A batch of multi-minute edits needs far longer than a single
479
485
  // request — default to 10 minutes, matching the server socket.
@@ -723,9 +729,9 @@ export class AIFlowClient {
723
729
  // continuous. The gateway concatenates the segments and always hands back the
724
730
  // whole timeline, so an app plays ONE url and never stitches anything itself.
725
731
  //
726
- // Requires a Gemini Omni model — Veo and Seedance hold no context between
727
- // calls, and the gateway refuses to open a session on them rather than accept
728
- // one clip and then fail every extend.
732
+ // Runs on Gemini Omni — Veo and Seedance hold no context between calls. The
733
+ // gateway picks Omni itself when the module's video model is one of those;
734
+ // it refuses only a non-Omni `model` the caller passed explicitly.
729
735
 
730
736
  /**
731
737
  * Open a stateful video session.
@@ -734,9 +740,11 @@ export class AIFlowClient {
734
740
  * - `prompt` (± `image`): the opening clip is GENERATED. The returned
735
741
  * `jobId` is polled like any video job; `session.videoUrl` is empty until
736
742
  * it lands.
737
- * - `video`: the timeline is SEEDED from your own clip — ready on return,
738
- * no `jobId`. A clip longer than Omni's 10s input limit is trimmed to its
739
- * last 10 seconds.
743
+ * - `video`: the timeline is SEEDED from a clip you already have (an
744
+ * upload, a `generateVideo` result, a `mergeVideos` result) — ready on
745
+ * return, no `jobId`. The WHOLE clip stays on the timeline and counts
746
+ * toward the 40s cap, so it can be at most 37s; the model continues from
747
+ * its last ~10s (Omni's input limit).
740
748
  *
741
749
  * `aspectRatio` / `resolution` are fixed for the WHOLE session here: Omni
742
750
  * inherits them across the chain, and segments of differing geometry could
@@ -761,12 +769,14 @@ export class AIFlowClient {
761
769
  'createVideoSession needs either a prompt (to generate the opening clip) or a video (to seed the timeline)',
762
770
  );
763
771
  }
764
- const resolvedModel =
765
- model || (await this._resolveDefaultModel('video'));
772
+ // `model` is sent only when the caller chose one. Filling it from the
773
+ // module default (as every other call does) would name `veo` on a module
774
+ // pinned to Veo, and the gateway refuses a session on an explicitly
775
+ // named non-Omni model; left out, it resolves to Omni itself.
766
776
  const res = await this._request(
767
777
  '/video/sessions',
768
778
  {
769
- model: resolvedModel,
779
+ model,
770
780
  prompt,
771
781
  aspectRatio,
772
782
  resolution,
@@ -793,18 +803,25 @@ export class AIFlowClient {
793
803
  * ```js
794
804
  * const video = await aiflow.generateLongVideo({
795
805
  * prompt: 'A lighthouse keeper climbing the spiral stairs at dawn',
796
- * durationSeconds: 30,
806
+ * durationSeconds: 30, // 5-40
797
807
  * onProgress: (p) => setStatus(`${p.segmentsDone}/${p.segmentsPlanned} — ${p.durationSeconds ?? 0}s`),
798
808
  * });
799
809
  * ```
800
810
  *
801
- * Two things to design the UI around:
811
+ * **Maximum 40 seconds.** A video is one Omni chain — an opening clip of up
812
+ * to 10s plus consecutive extends — and Google will not extend one past 40s.
813
+ * A larger `durationSeconds` is CLAMPED to 40 and the result carries a
814
+ * `warning`. For anything longer, generate several videos and
815
+ * {@link AIFlowClient#mergeVideos} them; the joins are hard cuts.
816
+ *
817
+ * Three things to design the UI around:
818
+ * - cap the duration control at 40s (chips of 10 / 20 / 30 / 40 read best);
802
819
  * - it takes MINUTES (roughly two to three per 10s of video), and
803
820
  * `onProgress` fires after every segment with a PLAYABLE partial
804
821
  * `videoUrl` — show it rather than a spinner;
805
- * - the result is "at least" `durationSeconds`. Omni cannot be asked for a
806
- * clip length, so the timeline overshoots by up to one segment; read
807
- * `durationSeconds` off the result for the real length.
822
+ * - the result is "at least" `durationSeconds` up to the cap. Omni cannot be
823
+ * asked for a clip length, so the timeline overshoots by up to one
824
+ * segment; read `durationSeconds` off the result for the real length.
808
825
  *
809
826
  * A build that comes up short still RESOLVES — with a shorter, already-paid
810
827
  * video and a `warning` saying why. Show the video and the warning; do not
@@ -987,12 +1004,15 @@ export class AIFlowClient {
987
1004
  }
988
1005
 
989
1006
  /**
990
- * Generate music / background audio from a text prompt (Lyria).
1007
+ * Generate music / background audio from a text prompt (Lyria 3.5),
1008
+ * optionally inspired by up to 10 reference `images` (https:// or data:
1009
+ * URLs) on the models in `config.audioImageInputModels`.
991
1010
  * @returns {Promise<{audioUrl:string, model:string, durationSeconds:number|null, prompt?:string, usage:{creditsUsed:number}}>}
992
1011
  */
993
1012
  async generateAudio({
994
1013
  prompt,
995
1014
  model,
1015
+ images,
996
1016
  negativePrompt,
997
1017
  seed,
998
1018
  signal,
@@ -1001,6 +1021,9 @@ export class AIFlowClient {
1001
1021
  if (!prompt || typeof prompt !== 'string') {
1002
1022
  throw new AIFlowError('prompt is required');
1003
1023
  }
1024
+ if (images !== undefined && !Array.isArray(images)) {
1025
+ throw new AIFlowError('images must be an array of URLs');
1026
+ }
1004
1027
  const resolvedModel =
1005
1028
  model || (await this._resolveDefaultModel('audio'));
1006
1029
  const res = await this._request(
@@ -1008,11 +1031,12 @@ export class AIFlowClient {
1008
1031
  {
1009
1032
  model: resolvedModel,
1010
1033
  prompt,
1034
+ images: images?.length ? images : undefined,
1011
1035
  negativePrompt,
1012
1036
  seed,
1013
1037
  },
1014
- // Music generation (esp. full-song Lyria 3 Pro) runs well past the
1015
- // 60s client default — allow 3 minutes before aborting.
1038
+ // Music generation (a full Lyria 3.5 song) runs well past the 60s
1039
+ // client default — allow 3 minutes before aborting.
1016
1040
  { signal, timeout: timeout ?? 180_000 },
1017
1041
  );
1018
1042
  return await res.json();
@@ -1408,6 +1432,7 @@ export class AIFlowClient {
1408
1432
  systemPrompt,
1409
1433
  defaults,
1410
1434
  defaultModel,
1435
+ imageBackground,
1411
1436
  signal,
1412
1437
  } = {}) {
1413
1438
  // `defaultModel` is sugar for setting the chat default; fold it into
@@ -1420,6 +1445,9 @@ export class AIFlowClient {
1420
1445
  if (moduleId != null) body.moduleId = moduleId;
1421
1446
  if (systemPrompt !== undefined) body.systemPrompt = systemPrompt;
1422
1447
  if (resolvedDefaults !== undefined) body.defaults = resolvedDefaults;
1448
+ // A TOP-LEVEL sibling of `defaults`, never inside it: the gateway reads
1449
+ // every `defaults` key as a feature and rejects this one.
1450
+ if (imageBackground !== undefined) body.imageBackground = imageBackground;
1423
1451
  const res = await this._adminRequest('/admin/config', body, {
1424
1452
  method: 'PATCH',
1425
1453
  signal,