Skip to content

Commit 9e17597

Browse files
Video API support
1 parent 5b93703 commit 9e17597

File tree

5 files changed

+405
-0
lines changed

5 files changed

+405
-0
lines changed

src/together/client.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class Together:
2626
batches: resources.Batches
2727
code_interpreter: CodeInterpreter
2828
evaluation: resources.Evaluation
29+
videos: resources.Videos
2930

3031
# client options
3132
client: TogetherClient
@@ -94,6 +95,7 @@ def __init__(
9495
self.code_interpreter = CodeInterpreter(self.client)
9596
self.batches = resources.Batches(self.client)
9697
self.evaluation = resources.Evaluation(self.client)
98+
self.videos = resources.Videos(self.client)
9799

98100

99101
class AsyncTogether:
@@ -109,6 +111,7 @@ class AsyncTogether:
109111
code_interpreter: CodeInterpreter
110112
batches: resources.AsyncBatches
111113
evaluation: resources.AsyncEvaluation
114+
videos: resources.AsyncVideos
112115
# client options
113116
client: TogetherClient
114117

@@ -175,6 +178,7 @@ def __init__(
175178
self.code_interpreter = CodeInterpreter(self.client)
176179
self.batches = resources.AsyncBatches(self.client)
177180
self.evaluation = resources.AsyncEvaluation(self.client)
181+
self.videos = resources.AsyncVideos(self.client)
178182

179183

180184
Client = Together

src/together/resources/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from together.resources.rerank import AsyncRerank, Rerank
1111
from together.resources.batch import Batches, AsyncBatches
1212
from together.resources.evaluation import Evaluation, AsyncEvaluation
13+
from together.resources.videos import AsyncVideos, Videos
1314

1415

1516
__all__ = [
@@ -37,4 +38,6 @@
3738
"AsyncBatches",
3839
"Evaluation",
3940
"AsyncEvaluation",
41+
"AsyncVideos",
42+
"Videos",
4043
]

src/together/resources/videos.py

Lines changed: 307 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,307 @@
1+
from __future__ import annotations
2+
3+
from typing import Any, Dict, List
4+
5+
from together.abstract import api_requestor
6+
from together.together_response import TogetherResponse
7+
from together.types import (
8+
TogetherClient,
9+
TogetherRequest,
10+
)
11+
from together.types.videos import (
12+
VideoGenerateResponse,
13+
VideoRequest,
14+
VideoStatusResponse,
15+
)
16+
17+
18+
class Videos:
19+
def __init__(self, client: TogetherClient) -> None:
20+
self._client = client
21+
22+
def generate(
23+
self,
24+
*,
25+
prompt: str,
26+
model: str,
27+
height: int | None = None,
28+
width: int | None = None,
29+
seconds: float | None = None,
30+
fps: int | None = None,
31+
steps: int | None = None,
32+
seed: int | None = None,
33+
guidance_scale: float | None = None,
34+
output_format: str | None = None,
35+
output_quality: int | None = None,
36+
negative_prompt: str | None = None,
37+
frame_images: List[Dict[str, Any]] | None = None,
38+
reference_images: List[Dict[str, Any]] | None = None,
39+
metadata: Dict[str, Any] | None = None,
40+
**kwargs: Any,
41+
) -> VideoGenerateResponse:
42+
"""
43+
Method to generate videos based on a given prompt using a specified model.
44+
45+
Args:
46+
prompt (str): A description of the desired video. Positive prompt for the generation.
47+
48+
model (str): The model to use for video generation (e.g., "google/veo-3.0-fast").
49+
50+
height (int, optional): Height of the video to generate in pixels.
51+
52+
width (int, optional): Width of the video to generate in pixels.
53+
54+
seconds (float, optional): Length of generated video in seconds. Min 1 max 10.
55+
56+
fps (int, optional): Frames per second, min 15 max 60. Defaults to 24.
57+
58+
steps (int, optional): The number of denoising steps the model performs during video
59+
generation. More steps typically result in higher quality output but require longer
60+
processing time. Min 10 max 50. Defaults to 20.
61+
62+
seed (int, optional): Seed to use in initializing the video generation. Using the same
63+
seed allows deterministic video generation. If not provided, a random seed is
64+
generated for each request. Note: When requesting multiple videos with the same
65+
seed, the seed will be incremented by 1 (+1) for each video generated.
66+
67+
guidance_scale (float, optional): Controls how closely the video generation follows your
68+
prompt. Higher values make the model adhere more strictly to your text description,
69+
while lower values allow more creative freedom. Recommended range is 6.0-10.0 for
70+
most video models. Values above 12 may cause over-guidance artifacts or unnatural
71+
motion patterns. Defaults to 8.
72+
73+
output_format (str, optional): Specifies the format of the output video. Either "MP4"
74+
or "WEBM". Defaults to "MP4".
75+
76+
output_quality (int, optional): Compression quality. Defaults to 20.
77+
78+
negative_prompt (str, optional): Similar to prompt, but specifies what to avoid instead
79+
of what to include. Defaults to None.
80+
81+
frame_images (List[Dict[str, Any]], optional): Array of images to guide video generation,
82+
like keyframes. If size 1, starting frame; if size 2, starting and ending frame;
83+
if more than 2 then frame must be specified. Defaults to None.
84+
85+
reference_images (List[Dict[str, Any]], optional): An array containing reference images
86+
used to condition the generation process. These images provide visual guidance to
87+
help the model generate content that aligns with the style, composition, or
88+
characteristics of the reference materials. Defaults to None.
89+
90+
metadata (Dict[str, Any], optional): Additional metadata for the request. Defaults to None.
91+
92+
Returns:
93+
VideoGenerateResponse: Object containing video generation job id
94+
"""
95+
96+
requestor = api_requestor.APIRequestor(
97+
client=self._client,
98+
)
99+
100+
parameter_payload = VideoRequest(
101+
prompt=prompt,
102+
model=model,
103+
height=height,
104+
width=width,
105+
seconds=seconds,
106+
fps=fps,
107+
steps=steps,
108+
seed=seed,
109+
guidance_scale=guidance_scale,
110+
output_format=output_format,
111+
output_quality=output_quality,
112+
negative_prompt=negative_prompt,
113+
frame_images=frame_images,
114+
reference_images=reference_images,
115+
metadata=metadata,
116+
**kwargs,
117+
).model_dump(exclude_none=True)
118+
119+
response, _, _ = requestor.request(
120+
options=TogetherRequest(
121+
method="POST",
122+
url="../v2/videos",
123+
params=parameter_payload,
124+
),
125+
stream=False,
126+
)
127+
128+
assert isinstance(response, TogetherResponse)
129+
130+
return VideoGenerateResponse(**response.data)
131+
132+
def status(
133+
self,
134+
*,
135+
id: str,
136+
) -> VideoStatusResponse:
137+
"""
138+
Method to check the status of a video generation job.
139+
140+
Args:
141+
id (str): The ID of the video generation job to check.
142+
143+
Returns:
144+
VideoStatusResponse: Object containing the current status and details of the video generation job
145+
"""
146+
147+
requestor = api_requestor.APIRequestor(
148+
client=self._client,
149+
)
150+
151+
response, _, _ = requestor.request(
152+
options=TogetherRequest(
153+
method="GET",
154+
url=f"../v2/videos/status?id={id}",
155+
),
156+
stream=False,
157+
)
158+
159+
assert isinstance(response, TogetherResponse)
160+
161+
return VideoStatusResponse(**response.data)
162+
163+
164+
class AsyncVideos:
165+
def __init__(self, client: TogetherClient) -> None:
166+
self._client = client
167+
168+
async def generate(
169+
self,
170+
*,
171+
prompt: str,
172+
model: str,
173+
height: int | None = None,
174+
width: int | None = None,
175+
seconds: float | None = None,
176+
fps: int | None = None,
177+
steps: int | None = None,
178+
seed: int | None = None,
179+
guidance_scale: float | None = None,
180+
output_format: str | None = None,
181+
output_quality: int | None = None,
182+
negative_prompt: str | None = None,
183+
frame_images: List[Dict[str, Any]] | None = None,
184+
reference_images: List[Dict[str, Any]] | None = None,
185+
metadata: Dict[str, Any] | None = None,
186+
**kwargs: Any,
187+
) -> VideoGenerateResponse:
188+
"""
189+
Async method to generate videos based on a given prompt using a specified model.
190+
191+
Args:
192+
prompt (str): A description of the desired video. Positive prompt for the generation.
193+
194+
model (str): The model to use for video generation (e.g., "google/veo-3.0-fast").
195+
196+
height (int, optional): Height of the video to generate in pixels.
197+
198+
width (int, optional): Width of the video to generate in pixels.
199+
200+
seconds (float, optional): Length of generated video in seconds. Min 1 max 10.
201+
202+
fps (int, optional): Frames per second, min 15 max 60. Defaults to 24.
203+
204+
steps (int, optional): The number of denoising steps the model performs during video
205+
generation. More steps typically result in higher quality output but require longer
206+
processing time. Min 10 max 50. Defaults to 20.
207+
208+
seed (int, optional): Seed to use in initializing the video generation. Using the same
209+
seed allows deterministic video generation. If not provided, a random seed is
210+
generated for each request. Note: When requesting multiple videos with the same
211+
seed, the seed will be incremented by 1 (+1) for each video generated.
212+
213+
guidance_scale (float, optional): Controls how closely the video generation follows your
214+
prompt. Higher values make the model adhere more strictly to your text description,
215+
while lower values allow more creative freedom. Recommended range is 6.0-10.0 for
216+
most video models. Values above 12 may cause over-guidance artifacts or unnatural
217+
motion patterns. Defaults to 8.
218+
219+
output_format (str, optional): Specifies the format of the output video. Either "MP4"
220+
or "WEBM". Defaults to "MP4".
221+
222+
output_quality (int, optional): Compression quality. Defaults to 20.
223+
224+
negative_prompt (str, optional): Similar to prompt, but specifies what to avoid instead
225+
of what to include. Defaults to None.
226+
227+
frame_images (List[Dict[str, Any]], optional): Array of images to guide video generation,
228+
like keyframes. If size 1, starting frame; if size 2, starting and ending frame;
229+
if more than 2 then frame must be specified. Defaults to None.
230+
231+
reference_images (List[Dict[str, Any]], optional): An array containing reference images
232+
used to condition the generation process. These images provide visual guidance to
233+
help the model generate content that aligns with the style, composition, or
234+
characteristics of the reference materials. Defaults to None.
235+
236+
metadata (Dict[str, Any], optional): Additional metadata for the request. Defaults to None.
237+
238+
Returns:
239+
VideoGenerateResponse: Object containing video generation job id
240+
"""
241+
242+
requestor = api_requestor.APIRequestor(
243+
client=self._client,
244+
)
245+
246+
parameter_payload = VideoRequest(
247+
prompt=prompt,
248+
model=model,
249+
height=height,
250+
width=width,
251+
seconds=seconds,
252+
fps=fps,
253+
steps=steps,
254+
seed=seed,
255+
guidance_scale=guidance_scale,
256+
output_format=output_format,
257+
output_quality=output_quality,
258+
negative_prompt=negative_prompt,
259+
frame_images=frame_images,
260+
reference_images=reference_images,
261+
metadata=metadata,
262+
**kwargs,
263+
).model_dump(exclude_none=True)
264+
265+
response, _, _ = await requestor.arequest(
266+
options=TogetherRequest(
267+
method="POST",
268+
url="../v2/videos",
269+
params=parameter_payload,
270+
),
271+
stream=False,
272+
)
273+
274+
assert isinstance(response, TogetherResponse)
275+
276+
return VideoGenerateResponse(**response.data)
277+
278+
async def status(
279+
self,
280+
*,
281+
id: str,
282+
) -> VideoStatusResponse:
283+
"""
284+
Async method to check the status of a video generation job.
285+
286+
Args:
287+
id (str): The ID of the video generation job to check.
288+
289+
Returns:
290+
VideoStatusResponse: Object containing the current status and details of the video generation job
291+
"""
292+
293+
requestor = api_requestor.APIRequestor(
294+
client=self._client,
295+
)
296+
297+
response, _, _ = await requestor.arequest(
298+
options=TogetherRequest(
299+
method="GET",
300+
url=f"../v2/videos/status?id={id}",
301+
),
302+
stream=False,
303+
)
304+
305+
assert isinstance(response, TogetherResponse)
306+
307+
return VideoStatusResponse(**response.data)

src/together/types/__init__.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,13 @@
7575
EvaluationJob,
7676
EvaluationStatusResponse,
7777
)
78+
from together.types.videos import (
79+
VideoRequest,
80+
VideoInputs,
81+
VideoOutputs,
82+
VideoGenerateResponse,
83+
VideoStatusResponse,
84+
)
7885

7986

8087
__all__ = [
@@ -152,4 +159,9 @@
152159
"EvaluationCreateResponse",
153160
"EvaluationJob",
154161
"EvaluationStatusResponse",
162+
"VideoRequest",
163+
"VideoInputs",
164+
"VideoOutputs",
165+
"VideoGenerateResponse",
166+
"VideoStatusResponse",
155167
]

0 commit comments

Comments
 (0)