runapi-kling 0.2.4 → 0.2.7

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 15dc6670d6a88eff6385d1b29b2f413edf0b6fee71f1c9ed359739934119ac79
4
- data.tar.gz: 8988cd7485fd0c33d1ff69c6881681a712ccab07b1c90c2d3e0edc082f8dc0b6
3
+ metadata.gz: 584b5be5ffeeb256f9d0d2a33533132cce5d94a48ba70b67382f603e3f63993e
4
+ data.tar.gz: 0e3421cbd6a27db1744dfb5b4f79ed94cc7cace043ea8cd0e3adad8423520df8
5
5
  SHA512:
6
- metadata.gz: c7960d362b6603113936756f8a6f4aa035c1730f8df179746f61cc55840c0baa35c645c4e811c225e50d1c24304feb42720939e4bc031dae73eff56c7757b046
7
- data.tar.gz: 04e1ed432f1935db93bd3b5b0f94f8e16b88c2fbddd80b965fd4beb0d9402784b81758936566291b321e0d3c7e4c1cc784ffeb0083b7259011c9c6a08a81e065
6
+ metadata.gz: ee240679da24f460d550384d362eb05b5547a3f96a6a96b188652bd51813c2237500daf89c6d236cc1d876560fbe17521deaf1590de946b020aad3b6bbc33fdd
7
+ data.tar.gz: 13b5771791a2148eaf1d7535e633ce6d4f372413a76133376909f92d6dc07ea2355b2b0d8643cd0d4a0dac3265b7ea6011d57fe6946ba9bd2ae1cb78b888197f
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # Kling AI API Ruby SDK for RunAPI
2
+
3
+ The kling ai api Ruby SDK is the language-specific package for Kling on RunAPI. Use this kling ai api package for text-to-video, image-to-video, video editing, and animation flows when your application needs JSON request bodies, task status lookup, and consistent RunAPI errors in Ruby.
4
+
5
+ This kling ai api README is the Ruby package guide inside the public `kling-sdk` repository. For the repository overview, start at `../README.md`; for model details, use https://runapi.ai/models/kling; for API reference, use https://runapi.ai/docs#kling; for SDK docs, use https://runapi.ai/docs#sdk-kling.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ gem install runapi-kling
11
+ ```
12
+
13
+ ## Quick start
14
+
15
+ ```ruby
16
+ require "runapi-kling"
17
+
18
+ client = RunApi::Kling::Client.new
19
+ task = client.generations.create(
20
+ # Pass the Kling JSON request body from https://runapi.ai/docs#kling.
21
+ )
22
+ status = client.generations.get(task.id)
23
+ ```
24
+
25
+ Use `create` when you want to submit a task and return quickly, `get` when you need the latest task state, and `run` when a script should create and poll until completion. In web request handlers, prefer `create` plus webhook or later `get` polling so a worker is not held open.
26
+
27
+ ## Language notes
28
+
29
+ Use Ruby keyword arguments and the `RunApi::Kling` error classes when building video jobs, Rails workers, or scripts. The available resources include text-to-video, image-to-video, AI avatars, V2.1/V2.5 video variants, and motion controls. Keep `RUNAPI_API_KEY` in the environment or your secret manager; never commit API keys or callback secrets.
30
+
31
+ ## Links
32
+
33
+ - Model page: https://runapi.ai/models/kling
34
+ - SDK docs: https://runapi.ai/docs#sdk-kling
35
+ - Product docs: https://runapi.ai/docs#kling
36
+ - Pricing and rate limits: https://runapi.ai/models/kling/3.0
37
+ - Provider comparison: https://runapi.ai/providers/kuaishou
38
+ - Full catalog: https://runapi.ai/models
39
+ - Repository: https://github.com/runapi-ai/kling-sdk
40
+
41
+ ## License
42
+
43
+ Licensed under the Apache License, Version 2.0.
@@ -53,8 +53,8 @@ module RunApi
53
53
  raise Core::ValidationError, "Invalid model: #{model}. Must be one of: #{Types::AI_AVATAR_MODELS.join(", ")}"
54
54
  end
55
55
 
56
- raise Core::ValidationError, "image_url is required" unless param(params, :image_url)
57
- raise Core::ValidationError, "audio_url is required" unless param(params, :audio_url)
56
+ raise Core::ValidationError, "source_image_url is required" unless param(params, :source_image_url)
57
+ raise Core::ValidationError, "source_audio_url is required" unless param(params, :source_audio_url)
58
58
  raise Core::ValidationError, "prompt is required" unless param(params, :prompt)
59
59
  end
60
60
  end
@@ -54,7 +54,17 @@ module RunApi
54
54
  end
55
55
 
56
56
  raise Core::ValidationError, "prompt is required" unless param(params, :prompt)
57
- raise Core::ValidationError, "image_url is required" unless param(params, :image_url)
57
+ raise Core::ValidationError, "first_frame_image_url is required" unless param(params, :first_frame_image_url)
58
+
59
+ duration_seconds = param(params, :duration_seconds)
60
+ if duration_seconds && !Types::FIXED_DURATIONS.include?(duration_seconds)
61
+ raise Core::ValidationError, "Invalid duration_seconds: #{duration_seconds}. Must be one of: #{Types::FIXED_DURATIONS.join(", ")}"
62
+ end
63
+
64
+ last_frame_image_url = param(params, :last_frame_image_url)
65
+ if last_frame_image_url && !%w[kling-v2.5-turbo-image-to-video-pro kling-v2.1-pro].include?(model)
66
+ raise Core::ValidationError, "last_frame_image_url is only supported by kling-v2.5-turbo-image-to-video-pro and kling-v2.1-pro"
67
+ end
58
68
  end
59
69
  end
60
70
  end
@@ -49,15 +49,18 @@ module RunApi
49
49
  def validate_params!(params)
50
50
  model = param(params, :model)
51
51
  raise Core::ValidationError, "model is required" unless model
52
- unless Types::MODELS.include?(model)
53
- raise Core::ValidationError, "Invalid model: #{model}. Must be one of: #{Types::MODELS.join(", ")}"
52
+ unless Types::MOTION_CONTROL_MODELS.include?(model)
53
+ raise Core::ValidationError, "Invalid model: #{model}. Must be one of: #{Types::MOTION_CONTROL_MODELS.join(", ")}"
54
54
  end
55
+ validate_optional!(params, :output_resolution, Types::MOTION_CONTROL_OUTPUT_RESOLUTIONS)
56
+ validate_optional!(params, :character_orientation, Types::MOTION_CONTROL_CHARACTER_ORIENTATIONS)
57
+ validate_optional!(params, :background_source, Types::MOTION_CONTROL_BACKGROUND_SOURCES)
55
58
 
56
- input_urls = param(params, :input_urls)
57
- raise Core::ValidationError, "input_urls is required" unless input_urls.is_a?(Array) && input_urls.any?
59
+ source_image_url = param(params, :source_image_url)
60
+ raise Core::ValidationError, "source_image_url is required" unless source_image_url
58
61
 
59
- video_urls = param(params, :video_urls)
60
- raise Core::ValidationError, "video_urls is required" unless video_urls.is_a?(Array) && video_urls.any?
62
+ reference_video_url = param(params, :reference_video_url)
63
+ raise Core::ValidationError, "reference_video_url is required" unless reference_video_url
61
64
  end
62
65
  end
63
66
  end
@@ -56,7 +56,8 @@ module RunApi
56
56
  multi_shots = param(params, :multi_shots) == true
57
57
 
58
58
  if multi_shots
59
- raise Core::ValidationError, "sound must be true when multi_shots is true" unless param(params, :sound) == true
59
+ raise Core::ValidationError, "enable_sound must be true when multi_shots is true" unless param(params, :enable_sound) == true
60
+ raise Core::ValidationError, "last_frame_image_url is not supported when multi_shots is true" if param(params, :last_frame_image_url)
60
61
 
61
62
  multi_prompt = param(params, :multi_prompt)
62
63
  validate_multi_prompt!(multi_prompt)
@@ -64,14 +65,18 @@ module RunApi
64
65
  raise Core::ValidationError, "prompt is required" unless param(params, :prompt)
65
66
  end
66
67
 
67
- validate_optional!(params, :mode, Types::MODES)
68
+ validate_optional!(params, :output_resolution, Types::TEXT_TO_VIDEO_OUTPUT_RESOLUTIONS)
68
69
  validate_optional!(params, :aspect_ratio, Types::ASPECT_RATIOS)
69
70
 
70
- duration = param(params, :duration)
71
- if duration
72
- dur_int = duration.to_i
73
- unless Types::DURATION_RANGE.cover?(dur_int)
74
- raise Core::ValidationError, "Invalid duration: #{duration}. Must be an integer between #{Types::DURATION_RANGE.min} and #{Types::DURATION_RANGE.max}"
71
+ duration_seconds = param(params, :duration_seconds)
72
+ if duration_seconds
73
+ dur_int = duration_seconds.to_i
74
+ if model == "kling-v2.1-master-text-to-video" || model == "kling-v2.5-turbo-text-to-video-pro"
75
+ unless Types::FIXED_DURATIONS.include?(duration_seconds)
76
+ raise Core::ValidationError, "Invalid duration_seconds: #{duration_seconds}. Must be one of: #{Types::FIXED_DURATIONS.join(", ")}"
77
+ end
78
+ elsif !Types::DURATION_RANGE.cover?(dur_int)
79
+ raise Core::ValidationError, "Invalid duration_seconds: #{duration_seconds}. Must be an integer between #{Types::DURATION_RANGE.min} and #{Types::DURATION_RANGE.max}"
75
80
  end
76
81
  end
77
82
  end
@@ -83,7 +88,7 @@ module RunApi
83
88
 
84
89
  multi_prompt.each_with_index do |shot, index|
85
90
  prompt = shot.is_a?(Hash) ? (shot[:prompt] || shot["prompt"]) : nil
86
- duration = shot.is_a?(Hash) ? (shot[:duration] || shot["duration"]) : nil
91
+ duration_seconds = shot.is_a?(Hash) ? (shot[:duration_seconds] || shot["duration_seconds"]) : nil
87
92
 
88
93
  raise Core::ValidationError, "multi_prompt[#{index}].prompt is required" if prompt.nil? || prompt.empty?
89
94
 
@@ -91,11 +96,11 @@ module RunApi
91
96
  raise Core::ValidationError, "multi_prompt[#{index}].prompt exceeds #{Types::MULTI_PROMPT_MAX_LENGTH} characters"
92
97
  end
93
98
 
94
- raise Core::ValidationError, "multi_prompt[#{index}].duration is required" if duration.nil?
99
+ raise Core::ValidationError, "multi_prompt[#{index}].duration_seconds is required" if duration_seconds.nil?
95
100
 
96
- dur_int = duration.to_i
101
+ dur_int = duration_seconds.to_i
97
102
  unless Types::MULTI_PROMPT_DURATION_RANGE.cover?(dur_int)
98
- raise Core::ValidationError, "multi_prompt[#{index}].duration must be between #{Types::MULTI_PROMPT_DURATION_RANGE.min} and #{Types::MULTI_PROMPT_DURATION_RANGE.max}"
103
+ raise Core::ValidationError, "multi_prompt[#{index}].duration_seconds must be between #{Types::MULTI_PROMPT_DURATION_RANGE.min} and #{Types::MULTI_PROMPT_DURATION_RANGE.max}"
99
104
  end
100
105
  end
101
106
  end
@@ -3,13 +3,35 @@
3
3
  module RunApi
4
4
  module Kling
5
5
  module Types
6
- TEXT_TO_VIDEO_MODELS = %w[kling-3.0 kling-v2.5-turbo-text-to-video-pro].freeze
6
+ TEXT_TO_VIDEO_MODELS = %w[
7
+ kling-3.0
8
+ kling-v2.5-turbo-text-to-video-pro
9
+ kling-v2.1-master-text-to-video
10
+ ].freeze
7
11
 
8
- AI_AVATAR_MODELS = %w[kling-ai-avatar-pro kling-ai-avatar-standard].freeze
12
+ AI_AVATAR_MODELS = %w[
13
+ kling-ai-avatar-pro
14
+ kling-ai-avatar-standard
15
+ kling-ai-avatar-v1-pro
16
+ kling-v1-avatar-standard
17
+ ].freeze
9
18
 
10
- IMAGE_TO_VIDEO_MODELS = %w[kling-v2.5-turbo-image-to-video-pro].freeze
19
+ IMAGE_TO_VIDEO_MODELS = %w[
20
+ kling-v2.5-turbo-image-to-video-pro
21
+ kling-v2.1-pro
22
+ kling-v2.1-standard
23
+ kling-v2.1-master-image-to-video
24
+ ].freeze
11
25
 
12
- MODES = %w[std pro].freeze
26
+ TEXT_TO_VIDEO_OUTPUT_RESOLUTIONS = %w[720p 1080p 4k].freeze
27
+
28
+ MOTION_CONTROL_MODELS = %w[kling-3.0].freeze
29
+
30
+ MOTION_CONTROL_OUTPUT_RESOLUTIONS = %w[720p 1080p].freeze
31
+
32
+ MOTION_CONTROL_CHARACTER_ORIENTATIONS = %w[video image].freeze
33
+
34
+ MOTION_CONTROL_BACKGROUND_SOURCES = %w[video image].freeze
13
35
 
14
36
  ASPECT_RATIOS = %w[16:9 9:16 1:1].freeze
15
37
 
@@ -17,6 +39,8 @@ module RunApi
17
39
 
18
40
  MULTI_PROMPT_DURATION_RANGE = (1..12)
19
41
 
42
+ FIXED_DURATIONS = [5, 10].freeze
43
+
20
44
  MULTI_PROMPT_MAX_LENGTH = 500
21
45
 
22
46
  class Video < RunApi::Core::BaseModel
@@ -29,22 +53,22 @@ module RunApi
29
53
  end
30
54
 
31
55
  class TextToVideoResponse < AsyncTaskResponse
32
- optional :videos, [ -> { Video } ]
56
+ optional :videos, [-> { Video }]
33
57
  optional :error, String
34
58
  end
35
59
 
36
60
  class AiAvatarResponse < AsyncTaskResponse
37
- optional :videos, [ -> { Video } ]
61
+ optional :videos, [-> { Video }]
38
62
  optional :error, String
39
63
  end
40
64
 
41
65
  class ImageToVideoResponse < AsyncTaskResponse
42
- optional :videos, [ -> { Video } ]
66
+ optional :videos, [-> { Video }]
43
67
  optional :error, String
44
68
  end
45
69
 
46
70
  class MotionControlResponse < AsyncTaskResponse
47
- optional :videos, [ -> { Video } ]
71
+ optional :videos, [-> { Video }]
48
72
  optional :error, String
49
73
  end
50
74
 
@@ -52,19 +76,19 @@ module RunApi
52
76
  # `status: "completed"`. `videos` is required so consumers never have to
53
77
  # null-check it on a successful task.
54
78
  class CompletedTextToVideoResponse < TextToVideoResponse
55
- required :videos, [ -> { Video } ]
79
+ required :videos, [-> { Video }]
56
80
  end
57
81
 
58
82
  class CompletedAiAvatarResponse < AiAvatarResponse
59
- required :videos, [ -> { Video } ]
83
+ required :videos, [-> { Video }]
60
84
  end
61
85
 
62
86
  class CompletedImageToVideoResponse < ImageToVideoResponse
63
- required :videos, [ -> { Video } ]
87
+ required :videos, [-> { Video }]
64
88
  end
65
89
 
66
90
  class CompletedMotionControlResponse < MotionControlResponse
67
- required :videos, [ -> { Video } ]
91
+ required :videos, [-> { Video }]
68
92
  end
69
93
  end
70
94
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: runapi-kling
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - RunAPI
@@ -15,22 +15,27 @@ dependencies:
15
15
  requirements:
16
16
  - - "~>"
17
17
  - !ruby/object:Gem::Version
18
- version: 0.2.4
18
+ version: 0.2.5
19
19
  type: :runtime
20
20
  prerelease: false
21
21
  version_requirements: !ruby/object:Gem::Requirement
22
22
  requirements:
23
23
  - - "~>"
24
24
  - !ruby/object:Gem::Version
25
- version: 0.2.4
26
- description: RunAPI Kling SDK for JavaScript, Ruby, and Go
25
+ version: 0.2.5
26
+ description: The kling ai api Ruby SDK is the language-specific package for Kling
27
+ on RunAPI. Use this kling ai api package for text-to-video, image-to-video, video
28
+ editing, and animation flows when your application needs JSON request bodies, task
29
+ status lookup, and consistent RunAPI errors in Ruby.
27
30
  email:
28
31
  - contact@runapi.ai
29
32
  executables: []
30
33
  extensions: []
31
- extra_rdoc_files: []
34
+ extra_rdoc_files:
35
+ - README.md
32
36
  files:
33
37
  - LICENSE
38
+ - README.md
34
39
  - lib/runapi-kling.rb
35
40
  - lib/runapi/kling.rb
36
41
  - lib/runapi/kling/client.rb
@@ -44,7 +49,7 @@ licenses:
44
49
  - Apache-2.0
45
50
  metadata:
46
51
  homepage_uri: https://runapi.ai/models/kling
47
- documentation_uri: https://github.com/runapi-ai/kling-sdk/blob/main/README.md
52
+ documentation_uri: https://github.com/runapi-ai/kling-sdk/blob/main/ruby/README.md
48
53
  source_code_uri: https://github.com/runapi-ai/kling-sdk
49
54
  changelog_uri: https://github.com/runapi-ai/kling-sdk/blob/main/CHANGELOG.md
50
55
  rdoc_options: []
@@ -63,5 +68,5 @@ required_rubygems_version: !ruby/object:Gem::Requirement
63
68
  requirements: []
64
69
  rubygems_version: 4.0.10
65
70
  specification_version: 4
66
- summary: Kling API SDKs for JavaScript, Ruby, and Go on RunAPI.
71
+ summary: Kling AI API Ruby SDK for RunAPI
67
72
  test_files: []