-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathnodes.py
More file actions
2335 lines (2071 loc) · 76.8 KB
/
nodes.py
File metadata and controls
2335 lines (2071 loc) · 76.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import json
import os
import time
import torch
from .kie_api.auth import _load_api_key
from .kie_api.credits import _fetch_remaining_credits, _log_remaining_credits
from .kie_api.nanobanana import (
ASPECT_RATIO_OPTIONS,
OUTPUT_FORMAT_OPTIONS,
RESOLUTION_OPTIONS,
_log,
run_nanobanana_image_job,
)
from .kie_api.nanobanana2 import (
ASPECT_RATIO_OPTIONS as NANOBANANA2_ASPECT_RATIO_OPTIONS,
OUTPUT_FORMAT_OPTIONS as NANOBANANA2_OUTPUT_FORMAT_OPTIONS,
RESOLUTION_OPTIONS as NANOBANANA2_RESOLUTION_OPTIONS,
run_nanobanana2_image_job,
)
from .kie_api.seedream45_t2i import (
ASPECT_RATIO_OPTIONS as SEEDREAM_ASPECT_RATIO_OPTIONS,
QUALITY_OPTIONS as SEEDREAM_QUALITY_OPTIONS,
run_seedream45_text_to_image,
)
from .kie_api.seedream45_edit import (
ASPECT_RATIO_OPTIONS as SEEDREAM_EDIT_ASPECT_RATIO_OPTIONS,
QUALITY_OPTIONS as SEEDREAM_EDIT_QUALITY_OPTIONS,
run_seedream45_edit,
)
from .kie_api.seedance2_video import (
DEFAULT_MODEL as SEEDANCE2_DEFAULT_MODEL,
MODEL_OPTIONS as SEEDANCE2_MODEL_OPTIONS,
ASPECT_RATIO_OPTIONS as SEEDANCE2_ASPECT_RATIO_OPTIONS,
DURATION_OPTIONS as SEEDANCE2_DURATION_OPTIONS,
RESOLUTION_OPTIONS as SEEDANCE2_RESOLUTION_OPTIONS,
preflight_seedance2_payload,
summarize_seedance2_payload,
run_seedance2_video,
run_seedance2_video_from_request,
)
from .kie_api.seedancev1pro_fast_i2v import KIE_SeedanceV1Pro_Fast_I2V
from .kie_api.seedance15pro_i2v import KIE_Seedance15Pro_I2V
from .kie_api.kling26_i2v import (
DURATION_OPTIONS as KLING26_DURATION_OPTIONS,
run_kling26_i2v_video,
)
from .kie_api.kling25_i2v import (
DURATION_OPTIONS as KLING25_DURATION_OPTIONS,
run_kling25_i2v_job,
)
from .kie_api.kling26motion_i2v import (
CHARACTER_ORIENTATION_OPTIONS as KLING26MOTION_CHARACTER_ORIENTATION_OPTIONS,
MODE_OPTIONS as KLING26MOTION_MODE_OPTIONS,
run_kling26motion_i2v_video,
)
from .kie_api.kling3motion_i2v import (
CHARACTER_ORIENTATION_OPTIONS as KLING3MOTION_CHARACTER_ORIENTATION_OPTIONS,
MODE_OPTIONS as KLING3MOTION_MODE_OPTIONS,
run_kling3motion_i2v_video,
)
from .kie_api.kling26_t2v import (
ASPECT_RATIO_OPTIONS as KLING26_T2V_ASPECT_RATIO_OPTIONS,
DURATION_OPTIONS as KLING26_T2V_DURATION_OPTIONS,
run_kling26_t2v_video,
)
from .kie_api.kling3_video import (
ASPECT_RATIO_OPTIONS as KLING3_ASPECT_RATIO_OPTIONS,
DURATION_OPTIONS as KLING3_DURATION_OPTIONS,
MODE_OPTIONS as KLING3_MODE_OPTIONS,
build_kling3_element,
merge_kling3_elements,
preflight_kling3_payload,
run_kling3_video,
run_kling3_video_from_request,
)
from .kie_api.suno_music import MODEL_OPTIONS as SUNO_MODEL_OPTIONS, run_suno_generate
from .kie_api.gemini3_pro_llm import (
MODEL_OPTIONS as GEMINI3_MODEL_OPTIONS,
REASONING_EFFORT_OPTIONS as GEMINI3_REASONING_EFFORT_OPTIONS,
ROLE_OPTIONS as GEMINI3_ROLE_OPTIONS,
run_gemini3_pro_chat,
)
from .kie_api.flux2_i2i import (
ASPECT_RATIO_OPTIONS as FLUX2_ASPECT_RATIO_OPTIONS,
MODEL_OPTIONS as FLUX2_MODEL_OPTIONS,
RESOLUTION_OPTIONS as FLUX2_RESOLUTION_OPTIONS,
run_flux2_i2i,
)
from .kie_api.grok_imagine_t2i import (
ASPECT_RATIO_OPTIONS as GROK_T2I_ASPECT_RATIO_OPTIONS,
run_grok_imagine_t2i,
)
from .kie_api.grok_imagine_t2v import (
ASPECT_RATIO_OPTIONS as GROK_T2V_ASPECT_RATIO_OPTIONS,
DURATION_OPTIONS as GROK_T2V_DURATION_OPTIONS,
MODE_OPTIONS as GROK_T2V_MODE_OPTIONS,
RESOLUTION_OPTIONS as GROK_T2V_RESOLUTION_OPTIONS,
run_grok_imagine_t2v_video,
)
from .kie_api.grok_imagine_i2i import run_grok_imagine_i2i
from .kie_api.grok_imagine_i2v import (
DURATION_OPTIONS as GROK_I2V_DURATION_OPTIONS,
MODE_OPTIONS as GROK_I2V_MODE_OPTIONS,
RESOLUTION_OPTIONS as GROK_I2V_RESOLUTION_OPTIONS,
run_grok_imagine_i2v_video,
)
from .kie_api.prompt_lists import parse_prompts_json
from .kie_api.grid import slice_grid_tensor
from .kie_api.http import TransientKieError
SYSTEM_PROMPT_MARKER = "system prompt below"
SYSTEM_PROMPT_PLACEHOLDER = "{user_prompt}"
SYSTEM_PROMPT_CATEGORIES = ("images", "videos")
def _system_prompt_dir() -> str:
return os.path.join(os.path.dirname(os.path.abspath(__file__)), "prompts")
def _scan_system_prompt_templates() -> dict[str, str]:
prompt_dir = _system_prompt_dir()
if not os.path.isdir(prompt_dir):
raise RuntimeError(f"Prompt folder not found: {prompt_dir}")
templates: dict[str, str] = {}
for category in SYSTEM_PROMPT_CATEGORIES:
category_dir = os.path.join(prompt_dir, category)
if not os.path.isdir(category_dir):
continue
for filename in sorted(os.listdir(category_dir)):
if not filename.lower().endswith(".txt"):
continue
if filename.lower() == "readme.txt":
continue
path = os.path.join(category_dir, filename)
try:
with open(path, "r", encoding="utf-8") as handle:
lines = handle.read().splitlines()
except OSError:
continue
name: str | None = None
body_index: int | None = None
for idx, line in enumerate(lines):
stripped = line.strip()
lower = stripped.lower()
if lower.startswith("name:") and name is None:
name = stripped[5:].strip()
if lower == SYSTEM_PROMPT_MARKER and body_index is None:
body_index = idx + 1
if not name or body_index is None:
continue
body = "\n".join(lines[body_index:]).strip()
if not body:
continue
label = f"{category}: {name}"
templates[label] = body
return templates
class KIE_GetRemainingCredits:
HELP = """
KIE Get Remaining Credits
Reads your remaining KIE credits using the API key in config/kie_key.txt.
Inputs:
- (none)
Outputs:
- STRING: data
- INT: Remaining credits
Notes:
- If your key is missing/invalid, this node errors.
"""
@classmethod
def INPUT_TYPES(cls):
return {"required": {"log": ("BOOLEAN", {"default": True})}}
RETURN_TYPES = ("STRING", "INT")
RETURN_NAMES = ("data", "credits_remaining")
FUNCTION = "get_remaining_credits"
CATEGORY = "kie/api"
def get_remaining_credits(self, log: bool):
_log(log, "Requesting remaining credits...")
api_key = _load_api_key()
raw_json, credits_remaining = _fetch_remaining_credits(api_key)
_log(log, f"Credits remaining: {credits_remaining}")
return (raw_json, credits_remaining)
class KIE_NanoBananaPro_Image:
HELP = """
KIE Nano Banana Pro (Image)
Generate an image using Nano Banana Pro. Optionally provide up to 8 reference images.
Inputs:
- prompt: Text prompt (required)
- images: Optional reference images (max 8)
- aspect_ratio: Output aspect ratio
- resolution: 1K / 2K / 4K
- output_format: png / jpg
- poll_interval_s: Status check interval
- timeout_s: Max wait time
- log: Console logging on/off
Outputs:
- IMAGE: ComfyUI image tensor (BHWC float32 0–1)
"""
@classmethod
def INPUT_TYPES(cls):
return {
"required": {"prompt": ("STRING", {"multiline": True})},
"optional": {
"images": ("IMAGE",),
"aspect_ratio": ("COMBO", {"options": ASPECT_RATIO_OPTIONS, "default": "auto"}),
"resolution": ("COMBO", {"options": RESOLUTION_OPTIONS, "default": "1K"}),
"output_format": ("COMBO", {"options": OUTPUT_FORMAT_OPTIONS, "default": "png"}),
"log": ("BOOLEAN", {"default": True}),
},
}
RETURN_TYPES = ("IMAGE",)
RETURN_NAMES = ("image",)
FUNCTION = "generate"
CATEGORY = "kie/api"
def generate(
self,
prompt: str,
aspect_ratio: str = "auto",
resolution: str = "1K",
output_format: str = "png",
log: bool = True,
poll_interval_s: float = 10.0,
timeout_s: int = 300,
retry_on_fail: bool = True,
max_retries: int = 2,
retry_backoff_s: float = 3.0,
images: torch.Tensor | None = None,
):
image_tensor = run_nanobanana_image_job(
prompt=prompt,
aspect_ratio=aspect_ratio,
resolution=resolution,
output_format=output_format,
log=log,
poll_interval_s=poll_interval_s,
timeout_s=timeout_s,
retry_on_fail=retry_on_fail,
max_retries=max_retries,
retry_backoff_s=retry_backoff_s,
images=images,
)
return (image_tensor,)
class KIE_NanoBanana2_Image:
HELP = """
KIE Nano Banana 2 (Image)
Generate an image using Nano Banana 2. Optionally provide up to 14 reference images
and enable Google web-search grounding.
Inputs:
- prompt: Text prompt (required)
- images: Optional reference images (max 14)
- google_search: Enable Google web search grounding
- aspect_ratio: Output aspect ratio
- resolution: 1K / 2K / 4K
- output_format: jpg / png
- poll_interval_s: Status check interval
- timeout_s: Max wait time
- log: Console logging on/off
Outputs:
- IMAGE: ComfyUI image tensor (BHWC float32 0-1)
"""
@classmethod
def INPUT_TYPES(cls):
return {
"required": {"prompt": ("STRING", {"multiline": True})},
"optional": {
"images": ("IMAGE",),
"google_search": ("BOOLEAN", {"default": False}),
"aspect_ratio": ("COMBO", {"options": NANOBANANA2_ASPECT_RATIO_OPTIONS, "default": "auto"}),
"resolution": ("COMBO", {"options": NANOBANANA2_RESOLUTION_OPTIONS, "default": "1K"}),
"output_format": ("COMBO", {"options": NANOBANANA2_OUTPUT_FORMAT_OPTIONS, "default": "jpg"}),
"log": ("BOOLEAN", {"default": True}),
},
}
RETURN_TYPES = ("IMAGE",)
RETURN_NAMES = ("image",)
FUNCTION = "generate"
CATEGORY = "kie/api"
def generate(
self,
prompt: str,
google_search: bool = False,
aspect_ratio: str = "auto",
resolution: str = "1K",
output_format: str = "jpg",
log: bool = True,
poll_interval_s: float = 10.0,
timeout_s: int = 300,
retry_on_fail: bool = True,
max_retries: int = 2,
retry_backoff_s: float = 3.0,
images: torch.Tensor | None = None,
):
image_tensor = run_nanobanana2_image_job(
prompt=prompt,
aspect_ratio=aspect_ratio,
resolution=resolution,
output_format=output_format,
google_search=google_search,
log=log,
poll_interval_s=poll_interval_s,
timeout_s=timeout_s,
retry_on_fail=retry_on_fail,
max_retries=max_retries,
retry_backoff_s=retry_backoff_s,
images=images,
)
return (image_tensor,)
class KIE_Seedream45_TextToImage:
HELP = """
KIE Seedream 4.5 Text-To-Image
Generate an image from a prompt (no reference images required).
Inputs:
- prompt: Text prompt (required)
- aspect_ratio / resolution / output_format
- poll_interval_s / timeout_s / log
Outputs:
- IMAGE: ComfyUI image tensor (BHWC float32 0–1)
"""
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"prompt": ("STRING", {"multiline": True}),
},
"optional": {
"aspect_ratio": ("COMBO", {"options": SEEDREAM_ASPECT_RATIO_OPTIONS, "default": "1:1"}),
"quality": ("COMBO", {"options": SEEDREAM_QUALITY_OPTIONS, "default": "basic"}),
"log": ("BOOLEAN", {"default": True}),
},
}
RETURN_TYPES = ("IMAGE",)
RETURN_NAMES = ("image",)
FUNCTION = "generate"
CATEGORY = "kie/api"
def generate(
self,
prompt: str,
aspect_ratio: str = "1:1",
quality: str = "basic",
log: bool = True,
poll_interval_s: float = 10.0,
timeout_s: int = 300,
):
image_tensor = run_seedream45_text_to_image(
prompt=prompt,
aspect_ratio=aspect_ratio,
quality=quality,
poll_interval_s=poll_interval_s,
timeout_s=timeout_s,
log=log,
)
return (image_tensor,)
class KIE_Seedream45_Edit:
HELP = """
KIE Seedream 4.5 Edit
Edit an input image using Seedream 4.5.
Inputs:
- prompt: Edit prompt (required)
- images: Source image batch (up to 14 images; all uploaded)
- aspect_ratio / quality
- poll_interval_s / timeout_s / log
Outputs:
- IMAGE: ComfyUI image tensor (BHWC float32 0–1)
"""
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"prompt": ("STRING", {"multiline": True}),
"images": ("IMAGE",),
},
"optional": {
"aspect_ratio": ("COMBO", {"options": SEEDREAM_EDIT_ASPECT_RATIO_OPTIONS, "default": "1:1"}),
"quality": ("COMBO", {"options": SEEDREAM_EDIT_QUALITY_OPTIONS, "default": "basic"}),
"log": ("BOOLEAN", {"default": True}),
},
}
RETURN_TYPES = ("IMAGE",)
RETURN_NAMES = ("image",)
FUNCTION = "generate"
CATEGORY = "kie/api"
def generate(
self,
prompt: str,
images: torch.Tensor,
aspect_ratio: str = "1:1",
quality: str = "basic",
log: bool = True,
poll_interval_s: float = 10.0,
timeout_s: int = 300,
):
image_tensor = run_seedream45_edit(
prompt=prompt,
images=images,
aspect_ratio=aspect_ratio,
quality=quality,
poll_interval_s=poll_interval_s,
timeout_s=timeout_s,
log=log,
)
return (image_tensor,)
class KIE_GrokImagine_T2I:
HELP = """
KIE Grok Imagine (Text-to-Image)
Generate one or more images from a text prompt using Grok Imagine.
Inputs:
- prompt: Text prompt (required, up to 5000 chars)
- aspect_ratio: 2:3, 3:2, 1:1, 9:16, or 16:9
- poll_interval_s / timeout_s / log
- retry_on_fail / max_retries / retry_backoff_s
Outputs:
- IMAGE: ComfyUI image batch (BHWC float32 0-1)
- STRING: task_id for Grok image-reference chaining
"""
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"prompt": ("STRING", {"multiline": True, "default": ""}),
},
"optional": {
"aspect_ratio": ("COMBO", {"options": GROK_T2I_ASPECT_RATIO_OPTIONS, "default": "1:1"}),
"log": ("BOOLEAN", {"default": True}),
},
}
RETURN_TYPES = ("IMAGE", "STRING")
RETURN_NAMES = ("image", "task_id")
FUNCTION = "generate"
CATEGORY = "kie/api"
def generate(
self,
prompt: str,
aspect_ratio: str = "1:1",
log: bool = True,
poll_interval_s: float = 10.0,
timeout_s: int = 300,
retry_on_fail: bool = True,
max_retries: int = 2,
retry_backoff_s: float = 3.0,
):
attempts = max_retries + 1 if retry_on_fail else 1
attempts = max(attempts, 1)
backoff = retry_backoff_s if retry_backoff_s >= 0 else 0.0
for attempt in range(1, attempts + 1):
try:
image_output, task_id = run_grok_imagine_t2i(
prompt=prompt,
aspect_ratio=aspect_ratio,
poll_interval_s=poll_interval_s,
timeout_s=timeout_s,
log=log,
)
return (image_output, task_id)
except TransientKieError:
if not retry_on_fail or attempt >= attempts:
raise
_log(log, f"Retrying (attempt {attempt + 1}/{attempts}) after {backoff}s")
time.sleep(backoff)
class KIE_GrokImagine_I2I:
HELP = """
KIE Grok Imagine (Image-to-Image)
Generate one or more images from a source image using Grok Imagine.
Inputs:
- images: Source image batch (first image used)
- prompt: Optional prompt (up to 390000 chars)
- poll_interval_s / timeout_s / log
- retry_on_fail / max_retries / retry_backoff_s
Outputs:
- IMAGE: ComfyUI image batch (BHWC float32 0-1)
- STRING: task_id for Grok image-reference chaining
"""
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"images": ("IMAGE",),
},
"optional": {
"prompt": ("STRING", {"multiline": True, "default": ""}),
"log": ("BOOLEAN", {"default": True}),
},
}
RETURN_TYPES = ("IMAGE", "STRING")
RETURN_NAMES = ("image", "task_id")
FUNCTION = "generate"
CATEGORY = "kie/api"
def generate(
self,
images: torch.Tensor,
prompt: str = "",
log: bool = True,
poll_interval_s: float = 10.0,
timeout_s: int = 300,
retry_on_fail: bool = True,
max_retries: int = 2,
retry_backoff_s: float = 3.0,
):
attempts = max_retries + 1 if retry_on_fail else 1
attempts = max(attempts, 1)
backoff = retry_backoff_s if retry_backoff_s >= 0 else 0.0
for attempt in range(1, attempts + 1):
try:
image_output, task_id = run_grok_imagine_i2i(
images=images,
prompt=prompt,
poll_interval_s=poll_interval_s,
timeout_s=timeout_s,
log=log,
)
return (image_output, task_id)
except TransientKieError:
if not retry_on_fail or attempt >= attempts:
raise
_log(log, f"Retrying (attempt {attempt + 1}/{attempts}) after {backoff}s")
time.sleep(backoff)
class KIE_Seedance2_Video:
HELP = """
KIE Seedance 2.0 (Video)
Generate a video with Seedance 2.0 using one of four supported scenarios:
- text-to-video
- first-frame image-to-video
- first+last-frame image-to-video
- multimodal reference-to-video
Inputs:
- model: `bytedance/seedance-2-fast` or `bytedance/seedance-2`
- prompt: Required prompt text
- first_frame / last_frame: Optional frame controls (mutually exclusive with reference media)
- reference_images: Optional reference image batch
- reference_video: Optional reference video
- reference_audio: Optional reference audio
- generate_audio: Ask the endpoint to create audio
- return_last_frame: Ask the endpoint to include the last frame artifact
- aspect_ratio / resolution / duration / web_search
- seedance_data: Optional validated payload from Seedance 2.0 Preflight
- log: Console logging on/off
Rules:
- last_frame requires first_frame
- first_frame/last_frame can be combined with reference media
- selected model is passed through directly to KIE
"""
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"model": ("COMBO", {"options": SEEDANCE2_MODEL_OPTIONS, "default": SEEDANCE2_DEFAULT_MODEL}),
"prompt": ("STRING", {"multiline": True, "default": ""}),
},
"optional": {
"first_frame": ("IMAGE",),
"last_frame": ("IMAGE",),
"reference_images": ("IMAGE",),
"reference_video": ("VIDEO",),
"reference_audio": ("AUDIO",),
"generate_audio": ("BOOLEAN", {"default": False}),
"return_last_frame": ("BOOLEAN", {"default": False}),
"aspect_ratio": ("COMBO", {"options": SEEDANCE2_ASPECT_RATIO_OPTIONS, "default": "16:9"}),
"resolution": ("COMBO", {"options": SEEDANCE2_RESOLUTION_OPTIONS, "default": "720p"}),
"duration": ("COMBO", {"options": SEEDANCE2_DURATION_OPTIONS, "default": "15"}),
"web_search": ("BOOLEAN", {"default": False}),
"seedance_data": ("KIE_SEEDANCE2_REQUEST",),
"log": ("BOOLEAN", {"default": True}),
},
}
RETURN_TYPES = ("VIDEO",)
RETURN_NAMES = ("video",)
FUNCTION = "generate"
CATEGORY = "kie/api"
def generate(
self,
model: str,
prompt: str,
first_frame: torch.Tensor | None = None,
last_frame: torch.Tensor | None = None,
reference_images: torch.Tensor | None = None,
reference_video: object | None = None,
reference_audio: object | None = None,
generate_audio: bool = False,
return_last_frame: bool = False,
aspect_ratio: str = "16:9",
resolution: str = "720p",
duration: str = "15",
web_search: bool = False,
seedance_data: dict | None = None,
log: bool = True,
poll_interval_s: float = 10.0,
timeout_s: int = 2000,
):
if seedance_data is not None:
video_output = run_seedance2_video_from_request(
payload=seedance_data,
poll_interval_s=poll_interval_s,
timeout_s=timeout_s,
log=log,
)
return (video_output,)
video_output = run_seedance2_video(
model=model,
prompt=prompt,
first_frame=first_frame,
last_frame=last_frame,
reference_images=reference_images,
reference_video=reference_video,
reference_audio=reference_audio,
generate_audio=generate_audio,
return_last_frame=return_last_frame,
aspect_ratio=aspect_ratio,
resolution=resolution,
duration=duration,
web_search=web_search,
poll_interval_s=poll_interval_s,
timeout_s=timeout_s,
log=log,
)
return (video_output,)
class KIE_Seedance2_Preflight:
HELP = """
KIE Seedance 2.0 Preflight
Validate Seedance 2.0 inputs, upload media, and build the exact createTask payload
without submitting a generation task.
Use this node before expensive Seedance 2.0 runs.
Outputs:
- KIE_SEEDANCE2_REQUEST: validated payload object for chaining into KIE Seedance 2.0 (Video)
- STRING: payload_json
- STRING: notes
"""
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"model": ("COMBO", {"options": SEEDANCE2_MODEL_OPTIONS, "default": SEEDANCE2_DEFAULT_MODEL}),
"prompt": ("STRING", {"multiline": True, "default": ""}),
},
"optional": {
"first_frame": ("IMAGE",),
"last_frame": ("IMAGE",),
"reference_images": ("IMAGE",),
"reference_video": ("VIDEO",),
"reference_audio": ("AUDIO",),
"generate_audio": ("BOOLEAN", {"default": False}),
"return_last_frame": ("BOOLEAN", {"default": False}),
"aspect_ratio": ("COMBO", {"options": SEEDANCE2_ASPECT_RATIO_OPTIONS, "default": "16:9"}),
"resolution": ("COMBO", {"options": SEEDANCE2_RESOLUTION_OPTIONS, "default": "720p"}),
"duration": ("COMBO", {"options": SEEDANCE2_DURATION_OPTIONS, "default": "15"}),
"web_search": ("BOOLEAN", {"default": False}),
"log": ("BOOLEAN", {"default": True}),
},
}
RETURN_TYPES = ("KIE_SEEDANCE2_REQUEST", "STRING", "STRING")
RETURN_NAMES = ("seedance_data", "payload_json", "notes")
FUNCTION = "preflight"
CATEGORY = "kie/helpers"
def preflight(
self,
model: str,
prompt: str,
first_frame: torch.Tensor | None = None,
last_frame: torch.Tensor | None = None,
reference_images: torch.Tensor | None = None,
reference_video: object | None = None,
reference_audio: object | None = None,
generate_audio: bool = False,
return_last_frame: bool = False,
aspect_ratio: str = "16:9",
resolution: str = "720p",
duration: str = "15",
web_search: bool = False,
log: bool = True,
):
payload = preflight_seedance2_payload(
model=model,
prompt=prompt,
first_frame=first_frame,
last_frame=last_frame,
reference_images=reference_images,
reference_video=reference_video,
reference_audio=reference_audio,
generate_audio=generate_audio,
return_last_frame=return_last_frame,
aspect_ratio=aspect_ratio,
resolution=resolution,
duration=duration,
web_search=web_search,
log=log,
)
payload_input = payload.get("input", {})
summary = summarize_seedance2_payload(payload)
notes_lines = [
"VALID: Seedance 2.0 preflight checks passed.",
"No createTask call was made.",
f"Model: {summary['model']}",
f"Scenario: {summary['scenario']}",
f"Aspect ratio: {payload_input.get('aspect_ratio')}",
f"Resolution: {payload_input.get('resolution')}",
f"Duration sent: {payload_input.get('duration')}s",
f"Generate audio: {bool(payload_input.get('generate_audio', False))}",
f"Return last frame: {bool(payload_input.get('return_last_frame', False))}",
f"Web search: {bool(payload_input.get('web_search', False))}",
f"First frame present: {summary['has_first_frame']}",
f"Last frame present: {summary['has_last_frame']}",
"Payload fields: " + ", ".join(summary["fields_present"]),
f"Reference image count: {summary['reference_image_count']}",
f"Reference video count: {summary['reference_video_count']}",
f"Reference audio count: {summary['reference_audio_count']}",
"Temporal slot note: first_frame_url and last_frame_url are dedicated control slots, not part of @ImageN ordering.",
"Prompt alias note: @ImageN / @VideoN / @AudioN mapping is inferred from upload order and is not API-verified.",
]
if summary["reference_image_aliases"]:
notes_lines.append("Reference image aliases: " + ", ".join(summary["reference_image_aliases"]))
if summary["reference_video_aliases"]:
notes_lines.append("Reference video aliases: " + ", ".join(summary["reference_video_aliases"]))
if summary["reference_audio_aliases"]:
notes_lines.append("Reference audio aliases: " + ", ".join(summary["reference_audio_aliases"]))
return (payload, json.dumps(payload, indent=2, ensure_ascii=False), "\n".join(notes_lines))
class KIE_Kling25_I2V_Pro:
HELP = """
KIE Kling 2.5 I2V Pro
Generate a short video clip from a prompt and one or two input images using Kling 2.5 Turbo I2V Pro.
Inputs:
- prompt: Text prompt (required)
- first_frame: Source image batch (first image used)
- last_frame: Optional tail image batch (first image used)
- negative_prompt: Optional negative prompt
- duration: 5s or 10s
- cfg_scale: 0.0 to 1.0
- poll_interval_s / timeout_s / log
- retry_on_fail / max_retries / retry_backoff_s
Outputs:
- VIDEO: ComfyUI video output referencing a temporary .mp4 file
"""
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"first_frame": ("IMAGE",),
"prompt": ("STRING", {"multiline": True, "default": ""}),
},
"optional": {
"last_frame": ("IMAGE",),
"negative_prompt": ("STRING", {"multiline": True, "default": ""}),
"duration": ("COMBO", {"options": KLING25_DURATION_OPTIONS, "default": "5"}),
"cfg_scale": ("FLOAT", {"default": 0.5, "min": 0.0, "max": 1.0, "step": 0.1}),
"log": ("BOOLEAN", {"default": True}),
},
}
RETURN_TYPES = ("VIDEO",)
RETURN_NAMES = ("video",)
FUNCTION = "generate"
CATEGORY = "kie/api"
def generate(
self,
first_frame: torch.Tensor,
prompt: str,
last_frame: torch.Tensor | None = None,
negative_prompt: str = "",
duration: str = "5",
cfg_scale: float = 0.5,
log: bool = True,
poll_interval_s: float = 10.0,
timeout_s: int = 2000,
retry_on_fail: bool = True,
max_retries: int = 2,
retry_backoff_s: float = 3.0,
):
attempts = max_retries + 1 if retry_on_fail else 1
attempts = max(attempts, 1)
backoff = retry_backoff_s if retry_backoff_s >= 0 else 0.0
for attempt in range(1, attempts + 1):
try:
video_output = run_kling25_i2v_job(
image=first_frame,
tail_image=last_frame,
prompt=prompt,
negative_prompt=negative_prompt,
duration=duration,
cfg_scale=cfg_scale,
timeout_seconds=timeout_s,
log=log,
)
return (video_output,)
except TransientKieError:
if not retry_on_fail or attempt >= attempts:
raise
_log(log, f"Retrying (attempt {attempt + 1}/{attempts}) after {backoff}s")
time.sleep(backoff)
class KIE_Kling26_I2V:
HELP = """
KIE Kling 2.6 (Video)
Generate a short video clip from a prompt and a single input image using Kling 2.6.
Inputs:
- prompt: Text prompt (required)
- images: Source image batch (first image used)
- duration: 5s or 10s
- sound: Include audio in the output video
- poll_interval_s / timeout_s / log
- retry_on_fail / max_retries / retry_backoff_s
Outputs:
- VIDEO: ComfyUI video output referencing a temporary .mp4 file
"""
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"prompt": ("STRING", {"multiline": True}),
"images": ("IMAGE",),
},
"optional": {
"duration": ("COMBO", {"options": KLING26_DURATION_OPTIONS, "default": "5"}),
"sound": ("BOOLEAN", {"default": False}),
"log": ("BOOLEAN", {"default": True}),
},
}
RETURN_TYPES = ("VIDEO",)
RETURN_NAMES = ("video",)
FUNCTION = "generate"
CATEGORY = "kie/api"
def generate(
self,
prompt: str,
images: torch.Tensor,
duration: str = "5",
sound: bool = False,
log: bool = True,
poll_interval_s: float = 10.0,
timeout_s: int = 2000,
retry_on_fail: bool = True,
max_retries: int = 2,
retry_backoff_s: float = 3.0,
):
attempts = max_retries + 1 if retry_on_fail else 1
attempts = max(attempts, 1)
backoff = retry_backoff_s if retry_backoff_s >= 0 else 0.0
for attempt in range(1, attempts + 1):
try:
video_output = run_kling26_i2v_video(
prompt=prompt,
images=images,
duration=duration,
sound=sound,
poll_interval_s=poll_interval_s,
timeout_s=timeout_s,
log=log,
)
return (video_output,)
except TransientKieError:
if not retry_on_fail or attempt >= attempts:
raise
_log(log, f"Retrying (attempt {attempt + 1}/{attempts}) after {backoff}s")
time.sleep(backoff)
class KIE_Kling26_T2V:
HELP = """
KIE Kling 2.6 (Text-to-Video)
Generate a short video clip from a text prompt using Kling 2.6.
Inputs:
- prompt: Text prompt (required)
- sound: Include audio in the output video
- aspect_ratio: 1:1, 16:9, or 9:16
- duration: 5s or 10s
- poll_interval_s / timeout_s / log
- retry_on_fail / max_retries / retry_backoff_s
Outputs:
- VIDEO: ComfyUI video output referencing a temporary .mp4 file
"""
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"prompt": ("STRING", {"multiline": True, "default": ""}),
},
"optional": {
"sound": ("BOOLEAN", {"default": False}),
"aspect_ratio": ("COMBO", {"options": KLING26_T2V_ASPECT_RATIO_OPTIONS, "default": "9:16"}),
"duration": ("COMBO", {"options": KLING26_T2V_DURATION_OPTIONS, "default": "5"}),
"log": ("BOOLEAN", {"default": True}),
},
}
RETURN_TYPES = ("VIDEO",)
RETURN_NAMES = ("video",)
FUNCTION = "generate"
CATEGORY = "kie/api"
def generate(
self,
prompt: str,
sound: bool = False,
aspect_ratio: str = "9:16",
duration: str = "5",
log: bool = True,
poll_interval_s: float = 10.0,
timeout_s: int = 2000,
retry_on_fail: bool = True,
max_retries: int = 2,
retry_backoff_s: float = 3.0,