runapi-kling 0.2.4 → 0.2.8

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: '06496c392220522b5dedc8acd4f71436ba22fd51df6ac685d8600fc5a5f3d02f'
4
+ data.tar.gz: ba507498208a38a168ec79b1e7a1041c95101c5aa510f1ba11cd55a3cd6e4a1a
5
5
  SHA512:
6
- metadata.gz: c7960d362b6603113936756f8a6f4aa035c1730f8df179746f61cc55840c0baa35c645c4e811c225e50d1c24304feb42720939e4bc031dae73eff56c7757b046
7
- data.tar.gz: 04e1ed432f1935db93bd3b5b0f94f8e16b88c2fbddd80b965fd4beb0d9402784b81758936566291b321e0d3c7e4c1cc784ffeb0083b7259011c9c6a08a81e065
6
+ metadata.gz: 361d632584c9a124c7e295bd3ae2f337f0434166ee76e13871afc5e17a96fc11e30f86802daa65724f1c8ee421cc4638ab97329cacce8dff1e14a701f12e0f89
7
+ data.tar.gz: 2a4358323094f9d1d2269b857107927042707cb003df73abb7855d3305cf30d1bcf5e09bda2799dec94da92ca85fc72d5eb5ac334e448de688749ac81a16daba
data/README.md ADDED
@@ -0,0 +1,45 @@
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
+ RunAPI-generated file URLs are temporary. Download and store generated images, videos, audio, or other files in your own durable storage within 7 days; do not treat returned URLs as long-term assets.
28
+
29
+ ## Language notes
30
+
31
+ 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.
32
+
33
+ ## Links
34
+
35
+ - Model page: https://runapi.ai/models/kling
36
+ - SDK docs: https://runapi.ai/docs#sdk-kling
37
+ - Product docs: https://runapi.ai/docs#kling
38
+ - Pricing and rate limits: https://runapi.ai/models/kling/3.0
39
+ - Provider comparison: https://runapi.ai/providers/kuaishou
40
+ - Full catalog: https://runapi.ai/models
41
+ - Repository: https://github.com/runapi-ai/kling-sdk
42
+
43
+ ## License
44
+
45
+ Licensed under the Apache License, Version 2.0.
@@ -9,7 +9,7 @@ module RunApi
9
9
  # result = client.text_to_video.run(
10
10
  # model: "kling-3.0", prompt: "A cat walking through a garden"
11
11
  # )
12
- class Client
12
+ class Client < RunApi::Core::Client
13
13
  # @return [Resources::TextToVideo] Text-to-video operations.
14
14
  attr_reader :text_to_video
15
15
  # @return [Resources::AiAvatar] AI avatar generation operations.
@@ -20,10 +20,7 @@ module RunApi
20
20
  attr_reader :motion_control
21
21
 
22
22
  def initialize(api_key: nil, **options)
23
- @api_key = Core::Auth.resolve_api_key(api_key)
24
-
25
- client_options = Core::ClientOptions.new(api_key: @api_key, **options)
26
- http = client_options.http_client || Core::HttpClient.new(client_options)
23
+ super
27
24
  @text_to_video = Resources::TextToVideo.new(http)
28
25
  @ai_avatar = Resources::AiAvatar.new(http)
29
26
  @image_to_video = Resources::ImageToVideo.new(http)
@@ -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
@@ -2,23 +2,60 @@
2
2
 
3
3
  module RunApi
4
4
  module Kling
5
+ # Type definitions and constants for Kling video generation.
5
6
  module Types
6
- TEXT_TO_VIDEO_MODELS = %w[kling-3.0 kling-v2.5-turbo-text-to-video-pro].freeze
7
-
8
- AI_AVATAR_MODELS = %w[kling-ai-avatar-pro kling-ai-avatar-standard].freeze
9
-
10
- IMAGE_TO_VIDEO_MODELS = %w[kling-v2.5-turbo-image-to-video-pro].freeze
11
-
12
- MODES = %w[std pro].freeze
7
+ # Text-to-video model variants. kling-3.0 supports multi-shot, sound, and elements;
8
+ # V2.x models support negative prompts and cfg_scale.
9
+ TEXT_TO_VIDEO_MODELS = %w[
10
+ kling-3.0
11
+ kling-v2.5-turbo-text-to-video-pro
12
+ kling-v2.1-master-text-to-video
13
+ ].freeze
14
+
15
+ # AI avatar lip-sync quality tiers, from highest to fastest.
16
+ AI_AVATAR_MODELS = %w[
17
+ kling-ai-avatar-pro
18
+ kling-ai-avatar-standard
19
+ kling-ai-avatar-v1-pro
20
+ kling-v1-avatar-standard
21
+ ].freeze
22
+
23
+ # Image-to-video model variants. V2.5 turbo and V2.1 pro support last-frame image control.
24
+ IMAGE_TO_VIDEO_MODELS = %w[
25
+ kling-v2.5-turbo-image-to-video-pro
26
+ kling-v2.1-pro
27
+ kling-v2.1-standard
28
+ kling-v2.1-master-image-to-video
29
+ ].freeze
30
+
31
+ # Output resolution options. 4k is highest quality but slowest.
32
+ TEXT_TO_VIDEO_OUTPUT_RESOLUTIONS = %w[720p 1080p 4k].freeze
33
+
34
+ MOTION_CONTROL_MODELS = %w[kling-3.0].freeze
35
+
36
+ MOTION_CONTROL_OUTPUT_RESOLUTIONS = %w[720p 1080p].freeze
37
+
38
+ # Whether the character faces the direction from the video or the image.
39
+ MOTION_CONTROL_CHARACTER_ORIENTATIONS = %w[video image].freeze
40
+
41
+ # Whether the background comes from the reference video or the subject image.
42
+ MOTION_CONTROL_BACKGROUND_SOURCES = %w[video image].freeze
13
43
 
14
44
  ASPECT_RATIOS = %w[16:9 9:16 1:1].freeze
15
45
 
46
+ # Duration range for kling-3.0 (seconds).
16
47
  DURATION_RANGE = (3..15)
17
48
 
49
+ # Per-shot duration range in multi-shot mode (seconds).
18
50
  MULTI_PROMPT_DURATION_RANGE = (1..12)
19
51
 
52
+ # Fixed duration options for V2.x models (seconds).
53
+ FIXED_DURATIONS = [5, 10].freeze
54
+
55
+ # Maximum character length for each multi-shot prompt segment.
20
56
  MULTI_PROMPT_MAX_LENGTH = 500
21
57
 
58
+ # A generated video file with a download URL.
22
59
  class Video < RunApi::Core::BaseModel
23
60
  optional :url, String
24
61
  end
@@ -29,22 +66,22 @@ module RunApi
29
66
  end
30
67
 
31
68
  class TextToVideoResponse < AsyncTaskResponse
32
- optional :videos, [ -> { Video } ]
69
+ optional :videos, [-> { Video }]
33
70
  optional :error, String
34
71
  end
35
72
 
36
73
  class AiAvatarResponse < AsyncTaskResponse
37
- optional :videos, [ -> { Video } ]
74
+ optional :videos, [-> { Video }]
38
75
  optional :error, String
39
76
  end
40
77
 
41
78
  class ImageToVideoResponse < AsyncTaskResponse
42
- optional :videos, [ -> { Video } ]
79
+ optional :videos, [-> { Video }]
43
80
  optional :error, String
44
81
  end
45
82
 
46
83
  class MotionControlResponse < AsyncTaskResponse
47
- optional :videos, [ -> { Video } ]
84
+ optional :videos, [-> { Video }]
48
85
  optional :error, String
49
86
  end
50
87
 
@@ -52,19 +89,19 @@ module RunApi
52
89
  # `status: "completed"`. `videos` is required so consumers never have to
53
90
  # null-check it on a successful task.
54
91
  class CompletedTextToVideoResponse < TextToVideoResponse
55
- required :videos, [ -> { Video } ]
92
+ required :videos, [-> { Video }]
56
93
  end
57
94
 
58
95
  class CompletedAiAvatarResponse < AiAvatarResponse
59
- required :videos, [ -> { Video } ]
96
+ required :videos, [-> { Video }]
60
97
  end
61
98
 
62
99
  class CompletedImageToVideoResponse < ImageToVideoResponse
63
- required :videos, [ -> { Video } ]
100
+ required :videos, [-> { Video }]
64
101
  end
65
102
 
66
103
  class CompletedMotionControlResponse < MotionControlResponse
67
- required :videos, [ -> { Video } ]
104
+ required :videos, [-> { Video }]
68
105
  end
69
106
  end
70
107
  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.8
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.6
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.6
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: []