runapi-seedance 0.3.0__tar.gz → 0.4.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.
@@ -1,18 +1,18 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: runapi-seedance
3
- Version: 0.3.0
3
+ Version: 0.4.0
4
4
  Summary: RunAPI Seedance SDK for text-to-video workflows in JavaScript, Python, Ruby, Go, Java, and PHP
5
5
  Project-URL: Homepage, https://runapi.ai/models/seedance
6
6
  Project-URL: Documentation, https://runapi.ai/docs/resources/sdks
7
7
  Project-URL: Source, https://github.com/runapi-ai/seedance-sdk
8
8
  Project-URL: Issues, https://github.com/runapi-ai/seedance-sdk/issues
9
9
  Project-URL: Changelog, https://github.com/runapi-ai/seedance-sdk/blob/main/CHANGELOG.md
10
- Project-URL: Release Notes, https://github.com/runapi-ai/seedance-sdk/releases/tag/python%2Fv0.3.0
10
+ Project-URL: Release Notes, https://github.com/runapi-ai/seedance-sdk/releases/tag/python%2Fv0.4.0
11
11
  Author-email: RunAPI <contact@runapi.ai>
12
12
  License-Expression: Apache-2.0
13
13
  Keywords: api,golang,gradle,java,maven,python,ruby,runapi,runapi-ai,sdk,seedance,seedance-api,text-to-video,typescript,video-api,video-generation
14
14
  Requires-Python: >=3.9
15
- Requires-Dist: runapi-core>=0.7.0
15
+ Requires-Dist: runapi-core~=0.10.0
16
16
  Description-Content-Type: text/markdown
17
17
 
18
18
  # Seedance Python SDK for RunAPI
@@ -4,14 +4,14 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "runapi-seedance"
7
- version = "0.3.0"
7
+ version = "0.4.0"
8
8
  description = "RunAPI Seedance SDK for text-to-video workflows in JavaScript, Python, Ruby, Go, Java, and PHP"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.9"
11
11
  license = "Apache-2.0"
12
12
  authors = [{ name = "RunAPI", email = "contact@runapi.ai" }]
13
13
  keywords = ["runapi", "runapi-ai", "seedance", "api", "sdk", "typescript", "python", "ruby", "golang", "java", "maven", "gradle", "video-generation", "text-to-video", "video-api", "seedance-api"]
14
- dependencies = ["runapi-core>=0.7.0"]
14
+ dependencies = ["runapi-core~=0.10.0"]
15
15
 
16
16
  [project.urls]
17
17
  Homepage = "https://runapi.ai/models/seedance"
@@ -19,7 +19,7 @@ Documentation = "https://runapi.ai/docs/resources/sdks"
19
19
  Source = "https://github.com/runapi-ai/seedance-sdk"
20
20
  Issues = "https://github.com/runapi-ai/seedance-sdk/issues"
21
21
  Changelog = "https://github.com/runapi-ai/seedance-sdk/blob/main/CHANGELOG.md"
22
- "Release Notes" = "https://github.com/runapi-ai/seedance-sdk/releases/tag/python%2Fv0.3.0"
22
+ "Release Notes" = "https://github.com/runapi-ai/seedance-sdk/releases/tag/python%2Fv0.4.0"
23
23
 
24
24
  [tool.hatch.build.targets.wheel]
25
25
  packages = ["src/runapi"]
@@ -0,0 +1,56 @@
1
+ """Seedance text-to-video 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
+ CompletedTextToVideoResponse,
11
+ TextToVideoResponse,
12
+ )
13
+
14
+
15
+ class TextToVideo(Resource):
16
+ """Generate videos from text prompts, images, or reference media."""
17
+
18
+ ENDPOINT = "/api/v1/seedance/text_to_video"
19
+
20
+ RESPONSE_CLASS = TextToVideoResponse
21
+ COMPLETED_RESPONSE_CLASS = CompletedTextToVideoResponse
22
+
23
+ def run(self, options: Optional[RequestOptions] = None, **params: Any) -> Any:
24
+ """Generate a video and poll until it completes.
25
+
26
+ Args:
27
+ **params: video generation parameters (model, ...).
28
+
29
+ Returns:
30
+ The completed (narrowed) video generation response.
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 video generation task and return immediately with an id.
37
+
38
+ Args:
39
+ **params: video generation parameters (model, ...).
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 video generation task.
49
+
50
+ Args:
51
+ id: The task id returned by ``create``.
52
+
53
+ Returns:
54
+ The current task status.
55
+ """
56
+ return self._request("get", f"{self.ENDPOINT}/{id}", options=options)
@@ -1,21 +1,9 @@
1
- """Seedance model lists, enums, and response models."""
1
+ """Seedance response models."""
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
5
  from runapi.core import BaseModel, TaskResponse, optional, required
6
6
 
7
- V1_MODELS = ["seedance-v1-pro", "seedance-v1-pro-fast"]
8
-
9
- SEED_RANGE = range(-1, 2_147_483_648)
10
-
11
- PROMPT_MIN_LENGTH = 3
12
- PROMPT_MAX_LENGTH_1_5 = 2500
13
- PROMPT_MAX_LENGTH_2 = 20000
14
- PROMPT_MAX_LENGTH_V1 = 10000
15
-
16
- FRAME_FIELDS = ["first_frame_image_url", "last_frame_image_url"]
17
- REFERENCE_FIELDS = ["reference_image_urls", "reference_video_urls", "reference_audio_urls"]
18
-
19
7
 
20
8
  class Video(BaseModel):
21
9
  url = optional(str)
@@ -0,0 +1,190 @@
1
+ import pytest
2
+
3
+ from runapi.core import config
4
+ from runapi.core.errors import AuthenticationError
5
+ from runapi.seedance import SeedanceClient
6
+ from runapi.seedance.resources.text_to_video import TextToVideo
7
+ from runapi.seedance.types import CompletedTextToVideoResponse, TextToVideoResponse
8
+
9
+
10
+ class FakeHttp:
11
+ def __init__(self, *responses):
12
+ self._responses = list(responses)
13
+ self.calls = []
14
+
15
+ def request(self, method, path, body=None, options=None):
16
+ self.calls.append((method, path, body))
17
+ if self._responses:
18
+ return self._responses.pop(0)
19
+ return {"id": "task_1", "status": "pending"}
20
+
21
+
22
+ @pytest.fixture(autouse=True)
23
+ def reset_config(monkeypatch):
24
+ monkeypatch.delenv("RUNAPI_API_KEY", raising=False)
25
+ monkeypatch.setattr(config, "api_key", None)
26
+ yield
27
+
28
+
29
+ # --- auth -----------------------------------------------------------------
30
+
31
+
32
+ def test_accepts_api_key_parameter():
33
+ assert isinstance(SeedanceClient(api_key="k", http_client=FakeHttp()), SeedanceClient)
34
+
35
+
36
+ def test_falls_back_to_global(monkeypatch):
37
+ monkeypatch.setattr(config, "api_key", "global-key")
38
+ assert isinstance(SeedanceClient(http_client=FakeHttp()), SeedanceClient)
39
+
40
+
41
+ def test_falls_back_to_env(monkeypatch):
42
+ monkeypatch.setenv("RUNAPI_API_KEY", "env-key")
43
+ assert isinstance(SeedanceClient(http_client=FakeHttp()), SeedanceClient)
44
+
45
+
46
+ def test_raises_without_api_key():
47
+ with pytest.raises(AuthenticationError, match="API key is required"):
48
+ SeedanceClient()
49
+
50
+
51
+ # --- injection / accessors ------------------------------------------------
52
+
53
+
54
+ def test_uses_injected_http_client():
55
+ fake = FakeHttp()
56
+ client = SeedanceClient(api_key="k", http_client=fake)
57
+ assert client.text_to_video._http is fake
58
+
59
+
60
+ def test_exposes_resource_accessors():
61
+ client = SeedanceClient(api_key="k", http_client=FakeHttp())
62
+ assert isinstance(client.text_to_video, TextToVideo)
63
+
64
+
65
+ # --- request shapes -------------------------------------------------------
66
+
67
+
68
+ def test_create_posts_compacted_body():
69
+ fake = FakeHttp({"id": "t1", "status": "pending"})
70
+ client = SeedanceClient(api_key="k", http_client=fake)
71
+ result = client.text_to_video.create(
72
+ model="seedance-2.0", prompt="a serene lake at dawn", duration_seconds=8, seed=None
73
+ )
74
+ assert fake.calls == [
75
+ (
76
+ "post",
77
+ "/api/v1/seedance/text_to_video",
78
+ {"model": "seedance-2.0", "prompt": "a serene lake at dawn", "duration_seconds": 8},
79
+ )]
80
+ assert isinstance(result, TextToVideoResponse)
81
+
82
+
83
+ def test_get_fetches_by_id():
84
+ fake = FakeHttp({"id": "t1", "status": "processing"})
85
+ client = SeedanceClient(api_key="k", http_client=fake)
86
+ client.text_to_video.get("t1")
87
+ assert fake.calls == [("get", "/api/v1/seedance/text_to_video/t1", None)]
88
+
89
+
90
+ def test_run_narrows_completed_type():
91
+ fake = FakeHttp(
92
+ {"id": "t1", "status": "pending"},
93
+ {"id": "t1", "status": "completed", "usage": {"cost": 0.05}, "videos": [{"url": "https://x/y.mp4"}]},
94
+ )
95
+ client = SeedanceClient(api_key="k", http_client=fake)
96
+ result = client.text_to_video.run(
97
+ model="seedance-2.0", prompt="a cinematic city flyover", duration_seconds=8
98
+ )
99
+ assert isinstance(result, CompletedTextToVideoResponse)
100
+ assert result.videos[0].url == "https://x/y.mp4"
101
+
102
+
103
+ # --- per-model request params ---------------------------------------------
104
+
105
+
106
+ def test_v2_mini_accepts_reference_mode():
107
+ http = FakeHttp([{"id": "task-mini", "status": "processing"}])
108
+ client = SeedanceClient(api_key="k", http_client=http)
109
+
110
+ client.text_to_video.create(
111
+ model="seedance-2-mini",
112
+ prompt="a compact cinematic scene",
113
+ reference_video_urls=["https://storage.googleapis.com/gtv-videos-bucket/sample/ForBiggerJoyrides.mp4"],
114
+ reference_audio_urls=["https://cdn.runapi.ai/public/samples/music.mp3"],
115
+ output_resolution="720p",
116
+ aspect_ratio="auto",
117
+ duration_seconds=8,
118
+ generate_audio=False,
119
+ )
120
+
121
+ assert http.calls[0][2]["model"] == "seedance-2-mini"
122
+
123
+
124
+ def test_v2_5_accepts_multimodal_fields():
125
+ http = FakeHttp({"id": "task-25", "status": "processing"})
126
+ client = SeedanceClient(api_key="k", http_client=http)
127
+
128
+ client.text_to_video.create(
129
+ model="seedance-2.5",
130
+ prompt="Match the reference media",
131
+ reference_image_urls=["https://cdn.runapi.ai/public/samples/reference.jpg"],
132
+ reference_video_urls=["https://cdn.runapi.ai/public/samples/reference.mp4"],
133
+ output_resolution="1080p",
134
+ duration_seconds=-1,
135
+ return_last_frame=True,
136
+ output_format="mov",
137
+ )
138
+
139
+ assert http.calls[0][2]["model"] == "seedance-2.5"
140
+ assert http.calls[0][2]["output_resolution"] == "1080p"
141
+ assert http.calls[0][2]["return_last_frame"] is True
142
+ assert http.calls[0][2]["output_format"] == "mov"
143
+
144
+
145
+ def test_v2_accepts_generated_4k():
146
+ fake = FakeHttp({"id": "t1", "status": "pending"})
147
+ client = SeedanceClient(api_key="k", http_client=fake)
148
+
149
+ client.text_to_video.create(
150
+ model="seedance-2.0", prompt="a cinematic city flyover", output_resolution="4k"
151
+ )
152
+
153
+ assert fake.calls == [
154
+ (
155
+ "post",
156
+ "/api/v1/seedance/text_to_video",
157
+ {
158
+ "model": "seedance-2.0",
159
+ "prompt": "a cinematic city flyover",
160
+ "output_resolution": "4k"},
161
+ )]
162
+
163
+
164
+ def test_1_5_pro_sends_seed():
165
+ fake = FakeHttp({"id": "task_15_seed", "status": "pending"})
166
+ client = SeedanceClient(api_key="k", http_client=fake)
167
+ client.text_to_video.create(
168
+ model="seedance-1.5-pro",
169
+ prompt="a serene lake at dawn",
170
+ aspect_ratio="16:9",
171
+ duration_seconds=4,
172
+ seed=42,
173
+ )
174
+
175
+ assert fake.calls[0][2]["seed"] == 42
176
+
177
+
178
+ def test_v1_pro_fast_sends_seed():
179
+ fake = FakeHttp({"id": "task_fast_seed", "status": "pending"})
180
+ client = SeedanceClient(api_key="k", http_client=fake)
181
+ client.text_to_video.create(
182
+ model="seedance-v1-pro-fast",
183
+ prompt="animate quickly",
184
+ first_frame_image_url="https://cdn.runapi.ai/public/samples/image.jpg",
185
+ output_resolution="720p",
186
+ duration_seconds=5,
187
+ seed=42,
188
+ )
189
+
190
+ assert fake.calls[0][2]["seed"] == 42
@@ -1,215 +0,0 @@
1
- CONTRACT = {
2
- "text-to-video": {
3
- "models": ["seedance-1.5-pro", "seedance-2-mini", "seedance-2.0", "seedance-2.0-fast", "seedance-2.5", "seedance-v1-pro", "seedance-v1-pro-fast"],
4
- "fields_by_model": {
5
- "seedance-1.5-pro": {
6
- "aspect_ratio": {
7
- "enum": ["1:1", "4:3", "3:4", "16:9", "9:16", "21:9"]
8
- },
9
- "duration_seconds": {
10
- "required": True,
11
- "min": 4,
12
- "max": 12,
13
- "type": "integer"
14
- },
15
- "output_resolution": {
16
- "enum": ["480p", "720p", "1080p"]
17
- },
18
- "seed": {
19
- "min": -1,
20
- "max": 2147483647,
21
- "type": "integer"
22
- },
23
- "source_image_urls": {
24
- "max_items": 2
25
- }
26
- },
27
- "seedance-2-mini": {
28
- "aspect_ratio": {
29
- "enum": ["1:1", "4:3", "3:4", "16:9", "9:16", "21:9", "auto"]
30
- },
31
- "duration_seconds": {
32
- "min": 4,
33
- "max": 15,
34
- "type": "integer"
35
- },
36
- "output_resolution": {
37
- "enum": ["480p", "720p"]
38
- },
39
- "reference_audio_urls": {
40
- "max_items": 3
41
- },
42
- "reference_image_urls": {
43
- "max_items": 9
44
- },
45
- "reference_video_urls": {
46
- "max_items": 3
47
- }
48
- },
49
- "seedance-2.0": {
50
- "aspect_ratio": {
51
- "enum": ["1:1", "4:3", "3:4", "16:9", "9:16", "21:9", "auto"]
52
- },
53
- "duration_seconds": {
54
- "min": 4,
55
- "max": 15,
56
- "type": "integer"
57
- },
58
- "output_resolution": {
59
- "enum": ["480p", "720p", "1080p", "4k"]
60
- },
61
- "reference_audio_urls": {
62
- "max_items": 3
63
- },
64
- "reference_image_urls": {
65
- "max_items": 9
66
- },
67
- "reference_video_urls": {
68
- "max_items": 3
69
- }
70
- },
71
- "seedance-2.0-fast": {
72
- "aspect_ratio": {
73
- "enum": ["1:1", "4:3", "3:4", "16:9", "9:16", "21:9", "auto"]
74
- },
75
- "duration_seconds": {
76
- "min": 4,
77
- "max": 15,
78
- "type": "integer"
79
- },
80
- "output_resolution": {
81
- "enum": ["480p", "720p"]
82
- },
83
- "reference_audio_urls": {
84
- "max_items": 3
85
- },
86
- "reference_image_urls": {
87
- "max_items": 9
88
- },
89
- "reference_video_urls": {
90
- "max_items": 3
91
- }
92
- },
93
- "seedance-2.5": {
94
- "aspect_ratio": {
95
- "enum": ["1:1", "4:3", "3:4", "16:9", "9:16", "21:9", "auto"]
96
- },
97
- "duration_seconds": {
98
- "enum": [-1, 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],
99
- "type": "integer"
100
- },
101
- "model": {
102
- "required": True
103
- },
104
- "output_format": {
105
- "enum": ["mp4", "mov"]
106
- },
107
- "output_resolution": {
108
- "enum": ["480p", "720p", "1080p"]
109
- },
110
- "prompt": {
111
- "required": True,
112
- "min": 3,
113
- "max": 30000,
114
- "length": True
115
- },
116
- "reference_audio_urls": {
117
- "max_items": 10
118
- },
119
- "reference_image_urls": {
120
- "max_items": 30
121
- },
122
- "reference_video_urls": {
123
- "max_items": 10
124
- }
125
- },
126
- "seedance-v1-pro": {
127
- "aspect_ratio": {
128
- "enum": ["1:1", "4:3", "3:4", "16:9", "9:16", "21:9"]
129
- },
130
- "duration_seconds": {
131
- "enum": [5, 10],
132
- "required": True,
133
- "type": "integer"
134
- },
135
- "output_resolution": {
136
- "enum": ["480p", "720p", "1080p"]
137
- },
138
- "seed": {
139
- "type": "integer"
140
- }
141
- },
142
- "seedance-v1-pro-fast": {
143
- "duration_seconds": {
144
- "enum": [5, 10],
145
- "required": True,
146
- "type": "integer"
147
- },
148
- "first_frame_image_url": {
149
- "required": True
150
- },
151
- "output_resolution": {
152
- "enum": ["720p", "1080p"]
153
- },
154
- "seed": {
155
- "min": -1,
156
- "max": 2147483647,
157
- "type": "integer"
158
- }
159
- }
160
- },
161
- "rules": [{
162
- "when": {
163
- "model": "seedance-2.5",
164
- "first_frame_image_url": {
165
- "present": True
166
- }
167
- },
168
- "forbidden": ["reference_image_urls", "reference_video_urls", "reference_audio_urls"]
169
- }, {
170
- "when": {
171
- "model": "seedance-2.5",
172
- "last_frame_image_url": {
173
- "present": True
174
- }
175
- },
176
- "required": ["first_frame_image_url"],
177
- "forbidden": ["reference_image_urls", "reference_video_urls", "reference_audio_urls"]
178
- }, {
179
- "when": {
180
- "model": "seedance-1.5-pro"
181
- },
182
- "forbidden": ["first_frame_image_url", "last_frame_image_url", "reference_image_urls", "reference_video_urls", "reference_audio_urls", "web_search", "return_last_frame", "output_format"]
183
- }, {
184
- "when": {
185
- "model": "seedance-2-mini"
186
- },
187
- "forbidden": ["source_image_urls", "lock_camera", "seed", "enable_safety_checker", "return_last_frame", "output_format"]
188
- }, {
189
- "when": {
190
- "model": "seedance-2.0"
191
- },
192
- "forbidden": ["source_image_urls", "lock_camera", "seed", "return_last_frame", "output_format"]
193
- }, {
194
- "when": {
195
- "model": "seedance-2.0-fast"
196
- },
197
- "forbidden": ["source_image_urls", "lock_camera", "seed", "return_last_frame", "output_format"]
198
- }, {
199
- "when": {
200
- "model": "seedance-2.5"
201
- },
202
- "forbidden": ["source_image_urls", "lock_camera", "seed"]
203
- }, {
204
- "when": {
205
- "model": "seedance-v1-pro"
206
- },
207
- "forbidden": ["source_image_urls", "last_frame_image_url", "reference_image_urls", "reference_video_urls", "reference_audio_urls", "web_search", "generate_audio", "return_last_frame", "output_format"]
208
- }, {
209
- "when": {
210
- "model": "seedance-v1-pro-fast"
211
- },
212
- "forbidden": ["aspect_ratio", "source_image_urls", "lock_camera", "last_frame_image_url", "reference_image_urls", "reference_video_urls", "reference_audio_urls", "web_search", "generate_audio", "return_last_frame", "output_format"]
213
- }]
214
- }
215
- }
@@ -1,174 +0,0 @@
1
- """Seedance text-to-video resource."""
2
-
3
- from __future__ import annotations
4
-
5
- from typing import Any, Dict, Optional
6
-
7
- from runapi.core import Resource, ValidationError, RequestOptions
8
-
9
- from ..contract_gen import CONTRACT
10
- from ..types import (
11
- FRAME_FIELDS,
12
- PROMPT_MAX_LENGTH_1_5,
13
- PROMPT_MAX_LENGTH_2,
14
- PROMPT_MAX_LENGTH_V1,
15
- PROMPT_MIN_LENGTH,
16
- REFERENCE_FIELDS,
17
- SEED_RANGE,
18
- V1_MODELS,
19
- CompletedTextToVideoResponse,
20
- TextToVideoResponse,
21
- )
22
-
23
-
24
- class TextToVideo(Resource):
25
- """Generate videos from text prompts, images, or reference media."""
26
-
27
- ENDPOINT = "/api/v1/seedance/text_to_video"
28
-
29
- RESPONSE_CLASS = TextToVideoResponse
30
- COMPLETED_RESPONSE_CLASS = CompletedTextToVideoResponse
31
-
32
- def run(self, options: Optional[RequestOptions] = None, **params: Any) -> Any:
33
- """Generate a video and poll until it completes.
34
-
35
- Args:
36
- **params: video generation parameters (model, ...).
37
-
38
- Returns:
39
- The completed (narrowed) video generation response.
40
- """
41
- task = self.create(options=options, **params)
42
- return self._poll_until_complete(lambda: self.get(task.id, options=options))
43
-
44
- def create(self, options: Optional[RequestOptions] = None, **params: Any) -> Any:
45
- """Create a video generation task and return immediately with an id.
46
-
47
- Args:
48
- **params: video generation parameters (model, ...).
49
-
50
- Returns:
51
- The task creation result with an id.
52
- """
53
- compacted = self._compact_params(params)
54
- self._validate_params(compacted)
55
- return self._request("post", self.ENDPOINT, body=compacted, options=options)
56
-
57
- def get(self, id: str, options: Optional[RequestOptions] = None) -> Any:
58
- """Fetch the current status of a video generation task.
59
-
60
- Args:
61
- id: The task id returned by ``create``.
62
-
63
- Returns:
64
- The current task status.
65
- """
66
- return self._request("get", f"{self.ENDPOINT}/{id}", options=options)
67
-
68
- def _validate_params(self, params: Dict[str, Any]) -> None:
69
- prompt = params.get("prompt")
70
- if not prompt:
71
- raise ValidationError("prompt is required")
72
-
73
- self._validate_contract(CONTRACT["text-to-video"], params)
74
-
75
- model = params.get("model")
76
- if model != "seedance-2.5":
77
- if model == "seedance-1.5-pro":
78
- max_prompt = PROMPT_MAX_LENGTH_1_5
79
- elif model in V1_MODELS:
80
- max_prompt = PROMPT_MAX_LENGTH_V1
81
- else:
82
- max_prompt = PROMPT_MAX_LENGTH_2
83
- if not (PROMPT_MIN_LENGTH <= len(prompt) <= max_prompt):
84
- raise ValidationError(
85
- f"prompt length must be between {PROMPT_MIN_LENGTH} and {max_prompt} characters"
86
- )
87
-
88
- if model == "seedance-1.5-pro":
89
- self._validate_1_5_pro(params)
90
- elif model in V1_MODELS:
91
- self._validate_v1(params)
92
- else:
93
- self._validate_2(params)
94
-
95
- def _validate_v1(self, params: Dict[str, Any]) -> None:
96
- model = params.get("model")
97
- has_image = self._field_present(params, "first_frame_image_url")
98
-
99
- if has_image and self._field_present(params, "aspect_ratio"):
100
- raise ValidationError(
101
- "aspect_ratio is not accepted in image-to-video mode; it is derived from the image"
102
- )
103
-
104
- if self._field_present(params, "last_frame_image_url"):
105
- raise ValidationError(f"last_frame_image_url is not supported by {model}")
106
-
107
- unsupported = [
108
- "source_image_urls",
109
- "reference_image_urls",
110
- "reference_video_urls",
111
- "reference_audio_urls",
112
- "web_search",
113
- "generate_audio",
114
- ]
115
- self._reject_unsupported(params, unsupported, model)
116
-
117
- if model == "seedance-v1-pro-fast":
118
- self._reject_unsupported(params, ["lock_camera"], model)
119
-
120
- seed = params.get("seed")
121
- if seed is not None:
122
- if not (isinstance(seed, int) and not isinstance(seed, bool) and seed in SEED_RANGE):
123
- raise ValidationError(
124
- f"seed must be an integer between {SEED_RANGE.start} and {SEED_RANGE.stop - 1}"
125
- )
126
-
127
- def _validate_1_5_pro(self, params: Dict[str, Any]) -> None:
128
- unsupported = [
129
- "first_frame_image_url",
130
- "last_frame_image_url",
131
- "reference_image_urls",
132
- "reference_video_urls",
133
- "reference_audio_urls",
134
- "web_search",
135
- ]
136
- self._reject_unsupported(params, unsupported, "seedance-1.5-pro")
137
-
138
- def _validate_2(self, params: Dict[str, Any]) -> None:
139
- unsupported = ["source_image_urls", "lock_camera"]
140
- self._reject_unsupported(params, unsupported, params.get("model"))
141
-
142
- self._validate_mode_conflicts(params)
143
- self._validate_seedance_2_4k_mode(params)
144
-
145
- def _validate_mode_conflicts(self, params: Dict[str, Any]) -> None:
146
- has_frame = any(self._field_present(params, f) for f in FRAME_FIELDS)
147
- has_reference = any(self._field_present(params, f) for f in REFERENCE_FIELDS)
148
-
149
- if has_frame and has_reference:
150
- raise ValidationError("Cannot use frame mode and reference mode at the same time")
151
-
152
- def _validate_seedance_2_4k_mode(self, params: Dict[str, Any]) -> None:
153
- if params.get("model") != "seedance-2.0" or params.get("output_resolution") != "4k":
154
- return
155
-
156
- for field in [*FRAME_FIELDS, *REFERENCE_FIELDS]:
157
- if self._field_present(params, field):
158
- raise ValidationError(
159
- f"{field} is not allowed when model is seedance-2.0 and output_resolution is 4k"
160
- )
161
-
162
- def _reject_unsupported(self, params: Dict[str, Any], fields: Any, model: Any) -> None:
163
- for field in fields:
164
- if self._field_present(params, field):
165
- raise ValidationError(f"{field} is not supported for {model}")
166
-
167
- @staticmethod
168
- def _field_present(params: Dict[str, Any], key: str) -> bool:
169
- value = params.get(key)
170
- if value is None:
171
- return False
172
- if hasattr(value, "__len__"):
173
- return len(value) > 0
174
- return True
@@ -1,383 +0,0 @@
1
- import pytest
2
-
3
- from runapi.core import config
4
- from runapi.core.errors import AuthenticationError, ValidationError
5
- from runapi.seedance import SeedanceClient
6
- from runapi.seedance.resources.text_to_video import TextToVideo
7
- from runapi.seedance.types import CompletedTextToVideoResponse, TextToVideoResponse
8
-
9
-
10
- class FakeHttp:
11
- def __init__(self, *responses):
12
- self._responses = list(responses)
13
- self.calls = []
14
-
15
- def request(self, method, path, body=None, options=None):
16
- self.calls.append((method, path, body))
17
- if self._responses:
18
- return self._responses.pop(0)
19
- return {"id": "task_1", "status": "pending"}
20
-
21
-
22
- @pytest.fixture(autouse=True)
23
- def reset_config(monkeypatch):
24
- monkeypatch.delenv("RUNAPI_API_KEY", raising=False)
25
- monkeypatch.setattr(config, "api_key", None)
26
- yield
27
-
28
-
29
- # --- auth -----------------------------------------------------------------
30
-
31
-
32
- def test_accepts_api_key_parameter():
33
- assert isinstance(SeedanceClient(api_key="k", http_client=FakeHttp()), SeedanceClient)
34
-
35
-
36
- def test_falls_back_to_global(monkeypatch):
37
- monkeypatch.setattr(config, "api_key", "global-key")
38
- assert isinstance(SeedanceClient(http_client=FakeHttp()), SeedanceClient)
39
-
40
-
41
- def test_falls_back_to_env(monkeypatch):
42
- monkeypatch.setenv("RUNAPI_API_KEY", "env-key")
43
- assert isinstance(SeedanceClient(http_client=FakeHttp()), SeedanceClient)
44
-
45
-
46
- def test_raises_without_api_key():
47
- with pytest.raises(AuthenticationError, match="API key is required"):
48
- SeedanceClient()
49
-
50
-
51
- # --- injection / accessors ------------------------------------------------
52
-
53
-
54
- def test_uses_injected_http_client():
55
- fake = FakeHttp()
56
- client = SeedanceClient(api_key="k", http_client=fake)
57
- assert client.text_to_video._http is fake
58
-
59
-
60
- def test_exposes_resource_accessors():
61
- client = SeedanceClient(api_key="k", http_client=FakeHttp())
62
- assert isinstance(client.text_to_video, TextToVideo)
63
-
64
-
65
- # --- request shapes -------------------------------------------------------
66
-
67
-
68
- def test_create_posts_compacted_body():
69
- fake = FakeHttp({"id": "t1", "status": "pending"})
70
- client = SeedanceClient(api_key="k", http_client=fake)
71
- result = client.text_to_video.create(
72
- model="seedance-2.0", prompt="a serene lake at dawn", duration_seconds=8, seed=None
73
- )
74
- assert fake.calls == [
75
- (
76
- "post",
77
- "/api/v1/seedance/text_to_video",
78
- {"model": "seedance-2.0", "prompt": "a serene lake at dawn", "duration_seconds": 8},
79
- ),
80
- ]
81
- assert isinstance(result, TextToVideoResponse)
82
-
83
-
84
- def test_get_fetches_by_id():
85
- fake = FakeHttp({"id": "t1", "status": "processing"})
86
- client = SeedanceClient(api_key="k", http_client=fake)
87
- client.text_to_video.get("t1")
88
- assert fake.calls == [("get", "/api/v1/seedance/text_to_video/t1", None)]
89
-
90
-
91
- def test_run_narrows_completed_type():
92
- fake = FakeHttp(
93
- {"id": "t1", "status": "pending"},
94
- {"id": "t1", "status": "completed", "videos": [{"url": "https://x/y.mp4"}]},
95
- )
96
- client = SeedanceClient(api_key="k", http_client=fake)
97
- result = client.text_to_video.run(
98
- model="seedance-2.0", prompt="a cinematic city flyover", duration_seconds=8
99
- )
100
- assert isinstance(result, CompletedTextToVideoResponse)
101
- assert result.videos[0].url == "https://x/y.mp4"
102
-
103
-
104
- # --- validation -----------------------------------------------------------
105
-
106
-
107
- def test_requires_model():
108
- client = SeedanceClient(api_key="k", http_client=FakeHttp())
109
- with pytest.raises(ValidationError, match="model must be one of:"):
110
- client.text_to_video.create(prompt="a serene lake at dawn")
111
-
112
-
113
- def test_rejects_unknown_model():
114
- client = SeedanceClient(api_key="k", http_client=FakeHttp())
115
- with pytest.raises(ValidationError, match="model must be one of:"):
116
- client.text_to_video.create(model="nope", prompt="a serene lake at dawn")
117
-
118
-
119
- def test_requires_prompt():
120
- client = SeedanceClient(api_key="k", http_client=FakeHttp())
121
- with pytest.raises(ValidationError, match="prompt is required"):
122
- client.text_to_video.create(model="seedance-2.0")
123
-
124
-
125
- def test_prompt_length_bounds():
126
- client = SeedanceClient(api_key="k", http_client=FakeHttp())
127
- with pytest.raises(
128
- ValidationError, match="prompt length must be between 3 and 20000 characters"
129
- ):
130
- client.text_to_video.create(model="seedance-2.0", prompt="hi", duration_seconds=8)
131
-
132
-
133
- # --- conditional validators per model version -----------------------------
134
-
135
-
136
- def test_v2_aspect_ratio_enum():
137
- client = SeedanceClient(api_key="k", http_client=FakeHttp())
138
- with pytest.raises(ValidationError, match="aspect_ratio must be one of:"):
139
- client.text_to_video.create(
140
- model="seedance-2.0", prompt="a serene lake at dawn", aspect_ratio="bogus"
141
- )
142
-
143
-
144
- def test_v2_fast_resolution_excludes_1080p():
145
- client = SeedanceClient(api_key="k", http_client=FakeHttp())
146
- with pytest.raises(ValidationError, match="output_resolution must be one of:"):
147
- client.text_to_video.create(
148
- model="seedance-2.0-fast", prompt="a serene lake at dawn", output_resolution="1080p"
149
- )
150
-
151
-
152
- def test_v2_mini_accepts_reference_mode():
153
- http = FakeHttp([{"id": "task-mini", "status": "processing"}])
154
- client = SeedanceClient(api_key="k", http_client=http)
155
-
156
- client.text_to_video.create(
157
- model="seedance-2-mini",
158
- prompt="a compact cinematic scene",
159
- reference_video_urls=["https://storage.googleapis.com/gtv-videos-bucket/sample/ForBiggerJoyrides.mp4"],
160
- reference_audio_urls=["https://cdn.runapi.ai/public/samples/music.mp3"],
161
- output_resolution="720p",
162
- aspect_ratio="auto",
163
- duration_seconds=8,
164
- generate_audio=False,
165
- )
166
-
167
- assert http.calls[0][2]["model"] == "seedance-2-mini"
168
-
169
-
170
- def test_v2_5_accepts_multimodal_fields():
171
- http = FakeHttp({"id": "task-25", "status": "processing"})
172
- client = SeedanceClient(api_key="k", http_client=http)
173
-
174
- client.text_to_video.create(
175
- model="seedance-2.5",
176
- prompt="Match the reference media",
177
- reference_image_urls=["https://cdn.runapi.ai/public/samples/reference.jpg"],
178
- reference_video_urls=["https://cdn.runapi.ai/public/samples/reference.mp4"],
179
- output_resolution="1080p",
180
- duration_seconds=-1,
181
- return_last_frame=True,
182
- output_format="mov",
183
- )
184
-
185
- assert http.calls[0][2]["model"] == "seedance-2.5"
186
- assert http.calls[0][2]["output_resolution"] == "1080p"
187
- assert http.calls[0][2]["return_last_frame"] is True
188
- assert http.calls[0][2]["output_format"] == "mov"
189
-
190
-
191
- def test_v2_mini_resolution_excludes_1080p():
192
- client = SeedanceClient(api_key="k", http_client=FakeHttp())
193
- with pytest.raises(ValidationError, match="output_resolution must be one of:"):
194
- client.text_to_video.create(
195
- model="seedance-2-mini", prompt="a serene lake at dawn", output_resolution="1080p"
196
- )
197
-
198
-
199
- def test_v2_accepts_generated_4k():
200
- fake = FakeHttp({"id": "t1", "status": "pending"})
201
- client = SeedanceClient(api_key="k", http_client=fake)
202
-
203
- client.text_to_video.create(
204
- model="seedance-2.0", prompt="a cinematic city flyover", output_resolution="4k"
205
- )
206
-
207
- assert fake.calls == [
208
- (
209
- "post",
210
- "/api/v1/seedance/text_to_video",
211
- {
212
- "model": "seedance-2.0",
213
- "prompt": "a cinematic city flyover",
214
- "output_resolution": "4k",
215
- },
216
- ),
217
- ]
218
-
219
-
220
- def test_v2_rejects_frame_4k():
221
- client = SeedanceClient(api_key="k", http_client=FakeHttp())
222
- with pytest.raises(
223
- ValidationError,
224
- match="first_frame_image_url is not allowed when model is seedance-2.0 and output_resolution is 4k",
225
- ):
226
- client.text_to_video.create(
227
- model="seedance-2.0",
228
- prompt="a cinematic city flyover",
229
- output_resolution="4k",
230
- first_frame_image_url="https://x/a.png",
231
- )
232
-
233
-
234
- def test_v2_duration_range():
235
- client = SeedanceClient(api_key="k", http_client=FakeHttp())
236
- with pytest.raises(
237
- ValidationError, match="duration_seconds must be between 4 and 15"
238
- ):
239
- client.text_to_video.create(
240
- model="seedance-2.0", prompt="a serene lake at dawn", duration_seconds=99
241
- )
242
-
243
-
244
- def test_v2_frame_and_reference_conflict():
245
- client = SeedanceClient(api_key="k", http_client=FakeHttp())
246
- with pytest.raises(
247
- ValidationError, match="Cannot use frame mode and reference mode at the same time"
248
- ):
249
- client.text_to_video.create(
250
- model="seedance-2.0",
251
- prompt="a serene lake at dawn",
252
- first_frame_image_url="https://x/a.png",
253
- reference_image_urls=["https://x/b.png"],
254
- )
255
-
256
-
257
- def test_v2_rejects_source_image_urls():
258
- client = SeedanceClient(api_key="k", http_client=FakeHttp())
259
- with pytest.raises(ValidationError, match="source_image_urls is not allowed when model is seedance-2.0"):
260
- client.text_to_video.create(
261
- model="seedance-2.0",
262
- prompt="a serene lake at dawn",
263
- source_image_urls=["https://x/a.png"],
264
- )
265
-
266
-
267
- def test_1_5_pro_sends_seed():
268
- fake = FakeHttp({"id": "task_15_seed", "status": "pending"})
269
- client = SeedanceClient(api_key="k", http_client=fake)
270
- client.text_to_video.create(
271
- model="seedance-1.5-pro",
272
- prompt="a serene lake at dawn",
273
- aspect_ratio="16:9",
274
- duration_seconds=4,
275
- seed=42,
276
- )
277
-
278
- assert fake.calls[0][2]["seed"] == 42
279
-
280
-
281
- def test_1_5_pro_requires_duration():
282
- client = SeedanceClient(api_key="k", http_client=FakeHttp())
283
- with pytest.raises(
284
- ValidationError, match="duration_seconds is required"
285
- ):
286
- client.text_to_video.create(model="seedance-1.5-pro", prompt="a serene lake at dawn")
287
-
288
-
289
- def test_1_5_pro_invalid_duration():
290
- client = SeedanceClient(api_key="k", http_client=FakeHttp())
291
- with pytest.raises(
292
- ValidationError, match="duration_seconds must be between 4 and 12"
293
- ):
294
- client.text_to_video.create(
295
- model="seedance-1.5-pro", prompt="a serene lake at dawn", duration_seconds=13
296
- )
297
-
298
-
299
- def test_1_5_pro_source_image_cap():
300
- client = SeedanceClient(api_key="k", http_client=FakeHttp())
301
- with pytest.raises(
302
- ValidationError, match="source_image_urls must contain at most 2 items"
303
- ):
304
- client.text_to_video.create(
305
- model="seedance-1.5-pro",
306
- prompt="a serene lake at dawn",
307
- duration_seconds=4,
308
- source_image_urls=["a", "b", "c"],
309
- )
310
-
311
-
312
- def test_v1_requires_duration():
313
- client = SeedanceClient(api_key="k", http_client=FakeHttp())
314
- with pytest.raises(
315
- ValidationError, match="duration_seconds is required"
316
- ):
317
- client.text_to_video.create(model="seedance-v1-pro", prompt="a serene lake at dawn")
318
-
319
-
320
- def test_v1_pro_fast_requires_first_frame():
321
- client = SeedanceClient(api_key="k", http_client=FakeHttp())
322
- with pytest.raises(
323
- ValidationError, match="first_frame_image_url is required"
324
- ):
325
- client.text_to_video.create(
326
- model="seedance-v1-pro-fast", prompt="a serene lake at dawn", duration_seconds=5
327
- )
328
-
329
-
330
- def test_v1_pro_fast_sends_seed():
331
- fake = FakeHttp({"id": "task_fast_seed", "status": "pending"})
332
- client = SeedanceClient(api_key="k", http_client=fake)
333
- client.text_to_video.create(
334
- model="seedance-v1-pro-fast",
335
- prompt="animate quickly",
336
- first_frame_image_url="https://cdn.runapi.ai/public/samples/image.jpg",
337
- output_resolution="720p",
338
- duration_seconds=5,
339
- seed=42,
340
- )
341
-
342
- assert fake.calls[0][2]["seed"] == 42
343
-
344
-
345
- def test_v1_image_mode_rejects_aspect_ratio():
346
- client = SeedanceClient(api_key="k", http_client=FakeHttp())
347
- with pytest.raises(
348
- ValidationError, match="aspect_ratio is not accepted in image-to-video mode"
349
- ):
350
- client.text_to_video.create(
351
- model="seedance-v1-pro",
352
- prompt="a serene lake at dawn",
353
- duration_seconds=5,
354
- first_frame_image_url="https://x/a.png",
355
- aspect_ratio="1:1",
356
- )
357
-
358
-
359
- def test_v1_seed_range():
360
- client = SeedanceClient(api_key="k", http_client=FakeHttp())
361
- with pytest.raises(
362
- ValidationError, match="seed must be an integer between -1 and 2147483647"
363
- ):
364
- client.text_to_video.create(
365
- model="seedance-v1-pro",
366
- prompt="a serene lake at dawn",
367
- duration_seconds=5,
368
- seed=-5,
369
- )
370
-
371
-
372
- def test_non_numeric_duration_raises_validation_error():
373
- # Regression: a non-numeric duration must raise the SDK's ValidationError,
374
- # not a bare ValueError from int(). duration_seconds is type: integer, so the
375
- # contract validator rejects it as a non-integer (mirroring the gateway)
376
- # before any int() coercion runs.
377
- client = SeedanceClient(api_key="k", http_client=FakeHttp())
378
- with pytest.raises(
379
- ValidationError, match="duration_seconds must be an integer between 4 and 15"
380
- ):
381
- client.text_to_video.create(
382
- model="seedance-2.0", prompt="a serene lake at dawn", duration_seconds="abc"
383
- )