runapi-kling 0.5.0__tar.gz → 0.7.0__tar.gz
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.
- {runapi_kling-0.5.0 → runapi_kling-0.7.0}/PKG-INFO +14 -4
- {runapi_kling-0.5.0 → runapi_kling-0.7.0}/README.md +4 -0
- {runapi_kling-0.5.0 → runapi_kling-0.7.0}/pyproject.toml +12 -4
- {runapi_kling-0.5.0 → runapi_kling-0.7.0}/src/runapi/kling/client.py +6 -0
- {runapi_kling-0.5.0 → runapi_kling-0.7.0}/src/runapi/kling/resources/__init__.py +3 -1
- runapi_kling-0.7.0/src/runapi/kling/resources/keyframe_to_video.py +23 -0
- runapi_kling-0.7.0/src/runapi/kling/resources/reference_to_video.py +23 -0
- runapi_kling-0.7.0/src/runapi/kling/resources/text_to_image.py +56 -0
- {runapi_kling-0.5.0 → runapi_kling-0.7.0}/src/runapi/kling/resources/text_to_video.py +6 -1
- {runapi_kling-0.5.0 → runapi_kling-0.7.0}/src/runapi/kling/types.py +13 -0
- {runapi_kling-0.5.0 → runapi_kling-0.7.0}/tests/test_client.py +8 -0
- runapi_kling-0.7.0/tests/test_text_to_image.py +24 -0
- {runapi_kling-0.5.0 → runapi_kling-0.7.0}/src/runapi/kling/__init__.py +0 -0
- {runapi_kling-0.5.0 → runapi_kling-0.7.0}/src/runapi/kling/py.typed +0 -0
- {runapi_kling-0.5.0 → runapi_kling-0.7.0}/src/runapi/kling/resources/ai_avatar.py +0 -0
- {runapi_kling-0.5.0 → runapi_kling-0.7.0}/src/runapi/kling/resources/edit_video.py +0 -0
- {runapi_kling-0.5.0 → runapi_kling-0.7.0}/src/runapi/kling/resources/extend_video.py +0 -0
- {runapi_kling-0.5.0 → runapi_kling-0.7.0}/src/runapi/kling/resources/image_to_video.py +0 -0
- {runapi_kling-0.5.0 → runapi_kling-0.7.0}/src/runapi/kling/resources/motion_control.py +0 -0
|
@@ -1,18 +1,24 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: runapi-kling
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.7.0
|
|
4
4
|
Summary: RunAPI Kling SDK for text-to-video, image-to-video, source-video editing, avatar, and motion-control workflows in JavaScript, Python, Ruby, Go, Java, and PHP
|
|
5
5
|
Project-URL: Homepage, https://runapi.ai/models/kling
|
|
6
6
|
Project-URL: Documentation, https://runapi.ai/docs/resources/sdks
|
|
7
7
|
Project-URL: Source, https://github.com/runapi-ai/kling-sdk
|
|
8
8
|
Project-URL: Issues, https://github.com/runapi-ai/kling-sdk/issues
|
|
9
9
|
Project-URL: Changelog, https://github.com/runapi-ai/kling-sdk/blob/main/CHANGELOG.md
|
|
10
|
-
Project-URL: Release Notes, https://github.com/runapi-ai/kling-sdk/releases/tag/python%2Fv0.
|
|
10
|
+
Project-URL: Release Notes, https://github.com/runapi-ai/kling-sdk/releases/tag/python%2Fv0.7.0
|
|
11
11
|
Author-email: RunAPI <contact@runapi.ai>
|
|
12
12
|
License-Expression: Apache-2.0
|
|
13
13
|
Keywords: api,golang,gradle,java,kling,kling-ai-api,maven,python,ruby,runapi,runapi-ai,sdk,text-to-video,typescript,video-api,video-generation
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
20
|
+
Requires-Python: >=3.10
|
|
21
|
+
Requires-Dist: runapi-core~=0.10.1
|
|
16
22
|
Description-Content-Type: text/markdown
|
|
17
23
|
|
|
18
24
|
# Kling API Python SDK for RunAPI
|
|
@@ -100,3 +106,7 @@ Pass parameters as keyword arguments and catch the `runapi.kling` error classes
|
|
|
100
106
|
## License
|
|
101
107
|
|
|
102
108
|
Licensed under the Apache License, Version 2.0.
|
|
109
|
+
|
|
110
|
+
## Kling 4.0 images
|
|
111
|
+
|
|
112
|
+
Use the `text_to_image` resource, named `textToImage` in JavaScript, PHP, and Java and `TextToImage` in Go. It supports `kling-v4-image` and `kling-v4-long-image` through create, get, and run. Completed tasks return ordered `images` with download URLs; 8k output is JPEG. Standard image references use `source_image_urls` and named `elements` with `name`, `image_urls`, optional `description`, and optional `tag`. Long images require `skill`: ecommerce uses product `source_image_urls` and optional `length`, while webpage uses optional `style_image_url` and `subject_image_url`. See the [image guide](https://runapi.ai/docs/guides/task-api/kling-images) for constraints and the [model catalog](https://runapi.ai/models/kling) for current pricing.
|
|
@@ -83,3 +83,7 @@ Pass parameters as keyword arguments and catch the `runapi.kling` error classes
|
|
|
83
83
|
## License
|
|
84
84
|
|
|
85
85
|
Licensed under the Apache License, Version 2.0.
|
|
86
|
+
|
|
87
|
+
## Kling 4.0 images
|
|
88
|
+
|
|
89
|
+
Use the `text_to_image` resource, named `textToImage` in JavaScript, PHP, and Java and `TextToImage` in Go. It supports `kling-v4-image` and `kling-v4-long-image` through create, get, and run. Completed tasks return ordered `images` with download URLs; 8k output is JPEG. Standard image references use `source_image_urls` and named `elements` with `name`, `image_urls`, optional `description`, and optional `tag`. Long images require `skill`: ecommerce uses product `source_image_urls` and optional `length`, while webpage uses optional `style_image_url` and `subject_image_url`. See the [image guide](https://runapi.ai/docs/guides/task-api/kling-images) for constraints and the [model catalog](https://runapi.ai/models/kling) for current pricing.
|
|
@@ -4,14 +4,22 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "runapi-kling"
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "0.7.0"
|
|
8
8
|
description = "RunAPI Kling SDK for text-to-video, image-to-video, source-video editing, avatar, and motion-control workflows in JavaScript, Python, Ruby, Go, Java, and PHP"
|
|
9
9
|
readme = "README.md"
|
|
10
|
-
requires-python = ">=3.
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
classifiers = [
|
|
12
|
+
"Programming Language :: Python :: 3",
|
|
13
|
+
"Programming Language :: Python :: 3.10",
|
|
14
|
+
"Programming Language :: Python :: 3.11",
|
|
15
|
+
"Programming Language :: Python :: 3.12",
|
|
16
|
+
"Programming Language :: Python :: 3.13",
|
|
17
|
+
"Programming Language :: Python :: 3.14",
|
|
18
|
+
]
|
|
11
19
|
license = "Apache-2.0"
|
|
12
20
|
authors = [{ name = "RunAPI", email = "contact@runapi.ai" }]
|
|
13
21
|
keywords = ["runapi", "runapi-ai", "kling", "api", "sdk", "typescript", "python", "ruby", "golang", "java", "maven", "gradle", "video-generation", "text-to-video", "video-api", "kling-ai-api"]
|
|
14
|
-
dependencies = ["runapi-core~=0.10.
|
|
22
|
+
dependencies = ["runapi-core~=0.10.1"]
|
|
15
23
|
|
|
16
24
|
[project.urls]
|
|
17
25
|
Homepage = "https://runapi.ai/models/kling"
|
|
@@ -19,7 +27,7 @@ Documentation = "https://runapi.ai/docs/resources/sdks"
|
|
|
19
27
|
Source = "https://github.com/runapi-ai/kling-sdk"
|
|
20
28
|
Issues = "https://github.com/runapi-ai/kling-sdk/issues"
|
|
21
29
|
Changelog = "https://github.com/runapi-ai/kling-sdk/blob/main/CHANGELOG.md"
|
|
22
|
-
"Release Notes" = "https://github.com/runapi-ai/kling-sdk/releases/tag/python%2Fv0.
|
|
30
|
+
"Release Notes" = "https://github.com/runapi-ai/kling-sdk/releases/tag/python%2Fv0.7.0"
|
|
23
31
|
|
|
24
32
|
[tool.hatch.build.targets.wheel]
|
|
25
33
|
packages = ["src/runapi"]
|
|
@@ -11,7 +11,10 @@ from .resources.edit_video import EditVideo
|
|
|
11
11
|
from .resources.image_to_video import ImageToVideo
|
|
12
12
|
from .resources.motion_control import MotionControl
|
|
13
13
|
from .resources.text_to_video import TextToVideo
|
|
14
|
+
from .resources.text_to_image import TextToImage
|
|
14
15
|
from .resources.extend_video import ExtendVideo
|
|
16
|
+
from .resources.keyframe_to_video import KeyframeToVideo
|
|
17
|
+
from .resources.reference_to_video import ReferenceToVideo
|
|
15
18
|
|
|
16
19
|
|
|
17
20
|
class KlingClient(ProviderClient):
|
|
@@ -28,9 +31,12 @@ class KlingClient(ProviderClient):
|
|
|
28
31
|
def __init__(self, api_key: Optional[str] = None, **options: Any) -> None:
|
|
29
32
|
super().__init__(api_key, **options)
|
|
30
33
|
http = self._http
|
|
34
|
+
self.text_to_image = TextToImage(http)
|
|
31
35
|
self.text_to_video = TextToVideo(http)
|
|
32
36
|
self.ai_avatar = AiAvatar(http)
|
|
33
37
|
self.image_to_video = ImageToVideo(http)
|
|
34
38
|
self.motion_control = MotionControl(http)
|
|
35
39
|
self.extend_video = ExtendVideo(http)
|
|
36
40
|
self.edit_video = EditVideo(http)
|
|
41
|
+
self.keyframe_to_video = KeyframeToVideo(http)
|
|
42
|
+
self.reference_to_video = ReferenceToVideo(http)
|
|
@@ -4,5 +4,7 @@ from .extend_video import ExtendVideo
|
|
|
4
4
|
from .image_to_video import ImageToVideo
|
|
5
5
|
from .motion_control import MotionControl
|
|
6
6
|
from .text_to_video import TextToVideo
|
|
7
|
+
from .keyframe_to_video import KeyframeToVideo
|
|
8
|
+
from .reference_to_video import ReferenceToVideo
|
|
7
9
|
|
|
8
|
-
__all__ = ["TextToVideo", "AiAvatar", "EditVideo", "ImageToVideo", "MotionControl", "ExtendVideo"]
|
|
10
|
+
__all__ = ["TextToVideo", "AiAvatar", "EditVideo", "ImageToVideo", "MotionControl", "ExtendVideo", "KeyframeToVideo", "ReferenceToVideo"]
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"""Kling 4.0 keyframe-to-video resource."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Any, Optional
|
|
6
|
+
|
|
7
|
+
from runapi.core import RequestOptions, Resource
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class KeyframeToVideo(Resource):
|
|
11
|
+
"""Generate video from ordered keyframe references."""
|
|
12
|
+
|
|
13
|
+
ENDPOINT = "/api/v1/kling/keyframe_to_video"
|
|
14
|
+
|
|
15
|
+
def run(self, options: Optional[RequestOptions] = None, **params: Any) -> Any:
|
|
16
|
+
task = self.create(options=options, **params)
|
|
17
|
+
return self._poll_until_complete(lambda: self.get(task.id, options=options))
|
|
18
|
+
|
|
19
|
+
def create(self, options: Optional[RequestOptions] = None, **params: Any) -> Any:
|
|
20
|
+
return self._request("post", self.ENDPOINT, body=self._compact_params(params), options=options)
|
|
21
|
+
|
|
22
|
+
def get(self, id: str, options: Optional[RequestOptions] = None) -> Any:
|
|
23
|
+
return self._request("get", f"{self.ENDPOINT}/{id}", options=options)
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"""Kling 4.0 reference-to-video resource."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Any, Optional
|
|
6
|
+
|
|
7
|
+
from runapi.core import RequestOptions, Resource
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class ReferenceToVideo(Resource):
|
|
11
|
+
"""Generate video from image, video, subject, and voice references."""
|
|
12
|
+
|
|
13
|
+
ENDPOINT = "/api/v1/kling/reference_to_video"
|
|
14
|
+
|
|
15
|
+
def run(self, options: Optional[RequestOptions] = None, **params: Any) -> Any:
|
|
16
|
+
task = self.create(options=options, **params)
|
|
17
|
+
return self._poll_until_complete(lambda: self.get(task.id, options=options))
|
|
18
|
+
|
|
19
|
+
def create(self, options: Optional[RequestOptions] = None, **params: Any) -> Any:
|
|
20
|
+
return self._request("post", self.ENDPOINT, body=self._compact_params(params), options=options)
|
|
21
|
+
|
|
22
|
+
def get(self, id: str, options: Optional[RequestOptions] = None) -> Any:
|
|
23
|
+
return self._request("get", f"{self.ENDPOINT}/{id}", options=options)
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"""Kling text-to-image resource."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Any, Optional
|
|
6
|
+
|
|
7
|
+
from runapi.core import Resource, RequestOptions
|
|
8
|
+
|
|
9
|
+
from ..types import (
|
|
10
|
+
CompletedTextToImageResponse,
|
|
11
|
+
TextToImageResponse,
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class TextToImage(Resource):
|
|
16
|
+
"""Generate ordered standard, series, ecommerce, or webpage images."""
|
|
17
|
+
|
|
18
|
+
ENDPOINT = "/api/v1/kling/text_to_image"
|
|
19
|
+
|
|
20
|
+
RESPONSE_CLASS = TextToImageResponse
|
|
21
|
+
COMPLETED_RESPONSE_CLASS = CompletedTextToImageResponse
|
|
22
|
+
|
|
23
|
+
def run(self, options: Optional[RequestOptions] = None, **params: Any) -> Any:
|
|
24
|
+
"""Generate an image from text and poll until it completes.
|
|
25
|
+
|
|
26
|
+
Args:
|
|
27
|
+
**params: Text-to-image parameters (model, prompt, ...).
|
|
28
|
+
|
|
29
|
+
Returns:
|
|
30
|
+
The completed task with images.
|
|
31
|
+
"""
|
|
32
|
+
task = self.create(options=options, **params)
|
|
33
|
+
return self._poll_until_complete(lambda: self.get(task.id, options=options))
|
|
34
|
+
|
|
35
|
+
def create(self, options: Optional[RequestOptions] = None, **params: Any) -> Any:
|
|
36
|
+
"""Create a text-to-image task and return immediately with an ``id``.
|
|
37
|
+
|
|
38
|
+
Args:
|
|
39
|
+
**params: Text-to-image parameters (model, prompt, ...).
|
|
40
|
+
|
|
41
|
+
Returns:
|
|
42
|
+
The task creation result with an id.
|
|
43
|
+
"""
|
|
44
|
+
compacted = self._compact_params(params)
|
|
45
|
+
return self._request("post", self.ENDPOINT, body=compacted, options=options)
|
|
46
|
+
|
|
47
|
+
def get(self, id: str, options: Optional[RequestOptions] = None) -> Any:
|
|
48
|
+
"""Fetch the current status of a text-to-image task.
|
|
49
|
+
|
|
50
|
+
Args:
|
|
51
|
+
id: The task id.
|
|
52
|
+
|
|
53
|
+
Returns:
|
|
54
|
+
The current task status.
|
|
55
|
+
"""
|
|
56
|
+
return self._request("get", f"{self.ENDPOINT}/{id}", options=options)
|
|
@@ -15,7 +15,12 @@ V3_TURBO_MODEL = "kling-v3-turbo-text-to-video"
|
|
|
15
15
|
|
|
16
16
|
|
|
17
17
|
class TextToVideo(Resource):
|
|
18
|
-
"""Generate videos from text prompts with Kling models.
|
|
18
|
+
"""Generate videos from text prompts with Kling models.
|
|
19
|
+
|
|
20
|
+
Kling 3.0 multi_shots supports custom or automatic shot_type. Custom
|
|
21
|
+
storyboards use multi_prompt; automatic storyboards use prompt. Sound is
|
|
22
|
+
optional. The server applies the custom default only in multi-shot mode.
|
|
23
|
+
"""
|
|
19
24
|
|
|
20
25
|
ENDPOINT = "/api/v1/kling/text_to_video"
|
|
21
26
|
|
|
@@ -68,3 +68,16 @@ class CompletedMotionControlResponse(MotionControlResponse):
|
|
|
68
68
|
"""Narrowed motion control response once polling observes completion."""
|
|
69
69
|
|
|
70
70
|
videos = required([lambda: Video])
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
class Image(BaseModel):
|
|
74
|
+
url = optional(str)
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
class TextToImageResponse(AsyncTaskResponse):
|
|
78
|
+
images = optional([lambda: Image])
|
|
79
|
+
error = optional(str)
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
class CompletedTextToImageResponse(TextToImageResponse):
|
|
83
|
+
images = required([lambda: Image])
|
|
@@ -570,3 +570,11 @@ def test_edit_video_create_get_and_run_for_edit_model():
|
|
|
570
570
|
("post", "/api/v1/kling/edit_video", params),
|
|
571
571
|
("get", "/api/v1/kling/edit_video/edit-run", None)]
|
|
572
572
|
assert result.status == "completed"
|
|
573
|
+
|
|
574
|
+
|
|
575
|
+
def test_custom_multi_shot_forwards_storyboard_without_sound():
|
|
576
|
+
fake = FakeHttp({"id": "multi", "status": "pending"})
|
|
577
|
+
client = KlingClient(api_key="k", http_client=fake)
|
|
578
|
+
params = {"model": "kling-3.0", "multi_shots": True, "shot_type": "custom", "enable_sound": False, "duration_seconds": 5, "multi_prompt": [{"prompt": "A sunrise", "duration_seconds": 5}]}
|
|
579
|
+
client.text_to_video.create(**params)
|
|
580
|
+
assert fake.calls == [("post", "/api/v1/kling/text_to_video", params)]
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
from runapi.kling import KlingClient
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class FakeHttp:
|
|
5
|
+
def __init__(self, *responses):
|
|
6
|
+
self._responses = list(responses)
|
|
7
|
+
self.calls = []
|
|
8
|
+
|
|
9
|
+
def request(self, method, path, body=None, options=None):
|
|
10
|
+
self.calls.append((method, path, body))
|
|
11
|
+
if self._responses:
|
|
12
|
+
return self._responses.pop(0)
|
|
13
|
+
return {"id": "task_1", "status": "pending"}
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def test_text_to_image_preserves_series_and_ordered_outputs():
|
|
17
|
+
fake = FakeHttp({"id": "images"}, {"id": "images", "status": "completed", "images": [
|
|
18
|
+
{"url": "https://file.runapi.ai/first.jpg"}, {"url": "https://file.runapi.ai/second.png"}]})
|
|
19
|
+
client = KlingClient(api_key="test", http_client=fake)
|
|
20
|
+
params = {"model": "kling-v4-image", "prompt": "@Hero", "mode": "series", "output_count": 2,
|
|
21
|
+
"elements": [{"name": "Hero", "image_urls": ["https://cdn.runapi.ai/public/samples/portrait.jpg", "https://cdn.runapi.ai/public/samples/image-to-video.jpg"]}]}
|
|
22
|
+
result = client.text_to_image.run(**params)
|
|
23
|
+
assert fake.calls == [("post", "/api/v1/kling/text_to_image", params), ("get", "/api/v1/kling/text_to_image/images", None)]
|
|
24
|
+
assert [image.url for image in result.images] == ["https://file.runapi.ai/first.jpg", "https://file.runapi.ai/second.png"]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|