From 9e17597fdfb3df628a0876fe501ef2b2b94dc6c3 Mon Sep 17 00:00:00 2001 From: Rishabh Bhargava Date: Thu, 16 Oct 2025 03:51:19 +0530 Subject: [PATCH 1/6] Video API support --- src/together/client.py | 4 + src/together/resources/__init__.py | 3 + src/together/resources/videos.py | 307 +++++++++++++++++++++++++++++ src/together/types/__init__.py | 12 ++ src/together/types/videos.py | 79 ++++++++ 5 files changed, 405 insertions(+) create mode 100644 src/together/resources/videos.py create mode 100644 src/together/types/videos.py diff --git a/src/together/client.py b/src/together/client.py index d84e10d..eeb2f34 100644 --- a/src/together/client.py +++ b/src/together/client.py @@ -26,6 +26,7 @@ class Together: batches: resources.Batches code_interpreter: CodeInterpreter evaluation: resources.Evaluation + videos: resources.Videos # client options client: TogetherClient @@ -94,6 +95,7 @@ def __init__( self.code_interpreter = CodeInterpreter(self.client) self.batches = resources.Batches(self.client) self.evaluation = resources.Evaluation(self.client) + self.videos = resources.Videos(self.client) class AsyncTogether: @@ -109,6 +111,7 @@ class AsyncTogether: code_interpreter: CodeInterpreter batches: resources.AsyncBatches evaluation: resources.AsyncEvaluation + videos: resources.AsyncVideos # client options client: TogetherClient @@ -175,6 +178,7 @@ def __init__( self.code_interpreter = CodeInterpreter(self.client) self.batches = resources.AsyncBatches(self.client) self.evaluation = resources.AsyncEvaluation(self.client) + self.videos = resources.AsyncVideos(self.client) Client = Together diff --git a/src/together/resources/__init__.py b/src/together/resources/__init__.py index 53c52e0..ed2129b 100644 --- a/src/together/resources/__init__.py +++ b/src/together/resources/__init__.py @@ -10,6 +10,7 @@ from together.resources.rerank import AsyncRerank, Rerank from together.resources.batch import Batches, AsyncBatches from together.resources.evaluation import Evaluation, AsyncEvaluation +from together.resources.videos import AsyncVideos, Videos __all__ = [ @@ -37,4 +38,6 @@ "AsyncBatches", "Evaluation", "AsyncEvaluation", + "AsyncVideos", + "Videos", ] diff --git a/src/together/resources/videos.py b/src/together/resources/videos.py new file mode 100644 index 0000000..784b68c --- /dev/null +++ b/src/together/resources/videos.py @@ -0,0 +1,307 @@ +from __future__ import annotations + +from typing import Any, Dict, List + +from together.abstract import api_requestor +from together.together_response import TogetherResponse +from together.types import ( + TogetherClient, + TogetherRequest, +) +from together.types.videos import ( + VideoGenerateResponse, + VideoRequest, + VideoStatusResponse, +) + + +class Videos: + def __init__(self, client: TogetherClient) -> None: + self._client = client + + def generate( + self, + *, + prompt: str, + model: str, + height: int | None = None, + width: int | None = None, + seconds: float | None = None, + fps: int | None = None, + steps: int | None = None, + seed: int | None = None, + guidance_scale: float | None = None, + output_format: str | None = None, + output_quality: int | None = None, + negative_prompt: str | None = None, + frame_images: List[Dict[str, Any]] | None = None, + reference_images: List[Dict[str, Any]] | None = None, + metadata: Dict[str, Any] | None = None, + **kwargs: Any, + ) -> VideoGenerateResponse: + """ + Method to generate videos based on a given prompt using a specified model. + + Args: + prompt (str): A description of the desired video. Positive prompt for the generation. + + model (str): The model to use for video generation (e.g., "google/veo-3.0-fast"). + + height (int, optional): Height of the video to generate in pixels. + + width (int, optional): Width of the video to generate in pixels. + + seconds (float, optional): Length of generated video in seconds. Min 1 max 10. + + fps (int, optional): Frames per second, min 15 max 60. Defaults to 24. + + steps (int, optional): The number of denoising steps the model performs during video + generation. More steps typically result in higher quality output but require longer + processing time. Min 10 max 50. Defaults to 20. + + seed (int, optional): Seed to use in initializing the video generation. Using the same + seed allows deterministic video generation. If not provided, a random seed is + generated for each request. Note: When requesting multiple videos with the same + seed, the seed will be incremented by 1 (+1) for each video generated. + + guidance_scale (float, optional): Controls how closely the video generation follows your + prompt. Higher values make the model adhere more strictly to your text description, + while lower values allow more creative freedom. Recommended range is 6.0-10.0 for + most video models. Values above 12 may cause over-guidance artifacts or unnatural + motion patterns. Defaults to 8. + + output_format (str, optional): Specifies the format of the output video. Either "MP4" + or "WEBM". Defaults to "MP4". + + output_quality (int, optional): Compression quality. Defaults to 20. + + negative_prompt (str, optional): Similar to prompt, but specifies what to avoid instead + of what to include. Defaults to None. + + frame_images (List[Dict[str, Any]], optional): Array of images to guide video generation, + like keyframes. If size 1, starting frame; if size 2, starting and ending frame; + if more than 2 then frame must be specified. Defaults to None. + + reference_images (List[Dict[str, Any]], optional): An array containing reference images + used to condition the generation process. These images provide visual guidance to + help the model generate content that aligns with the style, composition, or + characteristics of the reference materials. Defaults to None. + + metadata (Dict[str, Any], optional): Additional metadata for the request. Defaults to None. + + Returns: + VideoGenerateResponse: Object containing video generation job id + """ + + requestor = api_requestor.APIRequestor( + client=self._client, + ) + + parameter_payload = VideoRequest( + prompt=prompt, + model=model, + height=height, + width=width, + seconds=seconds, + fps=fps, + steps=steps, + seed=seed, + guidance_scale=guidance_scale, + output_format=output_format, + output_quality=output_quality, + negative_prompt=negative_prompt, + frame_images=frame_images, + reference_images=reference_images, + metadata=metadata, + **kwargs, + ).model_dump(exclude_none=True) + + response, _, _ = requestor.request( + options=TogetherRequest( + method="POST", + url="../v2/videos", + params=parameter_payload, + ), + stream=False, + ) + + assert isinstance(response, TogetherResponse) + + return VideoGenerateResponse(**response.data) + + def status( + self, + *, + id: str, + ) -> VideoStatusResponse: + """ + Method to check the status of a video generation job. + + Args: + id (str): The ID of the video generation job to check. + + Returns: + VideoStatusResponse: Object containing the current status and details of the video generation job + """ + + requestor = api_requestor.APIRequestor( + client=self._client, + ) + + response, _, _ = requestor.request( + options=TogetherRequest( + method="GET", + url=f"../v2/videos/status?id={id}", + ), + stream=False, + ) + + assert isinstance(response, TogetherResponse) + + return VideoStatusResponse(**response.data) + + +class AsyncVideos: + def __init__(self, client: TogetherClient) -> None: + self._client = client + + async def generate( + self, + *, + prompt: str, + model: str, + height: int | None = None, + width: int | None = None, + seconds: float | None = None, + fps: int | None = None, + steps: int | None = None, + seed: int | None = None, + guidance_scale: float | None = None, + output_format: str | None = None, + output_quality: int | None = None, + negative_prompt: str | None = None, + frame_images: List[Dict[str, Any]] | None = None, + reference_images: List[Dict[str, Any]] | None = None, + metadata: Dict[str, Any] | None = None, + **kwargs: Any, + ) -> VideoGenerateResponse: + """ + Async method to generate videos based on a given prompt using a specified model. + + Args: + prompt (str): A description of the desired video. Positive prompt for the generation. + + model (str): The model to use for video generation (e.g., "google/veo-3.0-fast"). + + height (int, optional): Height of the video to generate in pixels. + + width (int, optional): Width of the video to generate in pixels. + + seconds (float, optional): Length of generated video in seconds. Min 1 max 10. + + fps (int, optional): Frames per second, min 15 max 60. Defaults to 24. + + steps (int, optional): The number of denoising steps the model performs during video + generation. More steps typically result in higher quality output but require longer + processing time. Min 10 max 50. Defaults to 20. + + seed (int, optional): Seed to use in initializing the video generation. Using the same + seed allows deterministic video generation. If not provided, a random seed is + generated for each request. Note: When requesting multiple videos with the same + seed, the seed will be incremented by 1 (+1) for each video generated. + + guidance_scale (float, optional): Controls how closely the video generation follows your + prompt. Higher values make the model adhere more strictly to your text description, + while lower values allow more creative freedom. Recommended range is 6.0-10.0 for + most video models. Values above 12 may cause over-guidance artifacts or unnatural + motion patterns. Defaults to 8. + + output_format (str, optional): Specifies the format of the output video. Either "MP4" + or "WEBM". Defaults to "MP4". + + output_quality (int, optional): Compression quality. Defaults to 20. + + negative_prompt (str, optional): Similar to prompt, but specifies what to avoid instead + of what to include. Defaults to None. + + frame_images (List[Dict[str, Any]], optional): Array of images to guide video generation, + like keyframes. If size 1, starting frame; if size 2, starting and ending frame; + if more than 2 then frame must be specified. Defaults to None. + + reference_images (List[Dict[str, Any]], optional): An array containing reference images + used to condition the generation process. These images provide visual guidance to + help the model generate content that aligns with the style, composition, or + characteristics of the reference materials. Defaults to None. + + metadata (Dict[str, Any], optional): Additional metadata for the request. Defaults to None. + + Returns: + VideoGenerateResponse: Object containing video generation job id + """ + + requestor = api_requestor.APIRequestor( + client=self._client, + ) + + parameter_payload = VideoRequest( + prompt=prompt, + model=model, + height=height, + width=width, + seconds=seconds, + fps=fps, + steps=steps, + seed=seed, + guidance_scale=guidance_scale, + output_format=output_format, + output_quality=output_quality, + negative_prompt=negative_prompt, + frame_images=frame_images, + reference_images=reference_images, + metadata=metadata, + **kwargs, + ).model_dump(exclude_none=True) + + response, _, _ = await requestor.arequest( + options=TogetherRequest( + method="POST", + url="../v2/videos", + params=parameter_payload, + ), + stream=False, + ) + + assert isinstance(response, TogetherResponse) + + return VideoGenerateResponse(**response.data) + + async def status( + self, + *, + id: str, + ) -> VideoStatusResponse: + """ + Async method to check the status of a video generation job. + + Args: + id (str): The ID of the video generation job to check. + + Returns: + VideoStatusResponse: Object containing the current status and details of the video generation job + """ + + requestor = api_requestor.APIRequestor( + client=self._client, + ) + + response, _, _ = await requestor.arequest( + options=TogetherRequest( + method="GET", + url=f"../v2/videos/status?id={id}", + ), + stream=False, + ) + + assert isinstance(response, TogetherResponse) + + return VideoStatusResponse(**response.data) diff --git a/src/together/types/__init__.py b/src/together/types/__init__.py index b1904d6..eefa412 100644 --- a/src/together/types/__init__.py +++ b/src/together/types/__init__.py @@ -75,6 +75,13 @@ EvaluationJob, EvaluationStatusResponse, ) +from together.types.videos import ( + VideoRequest, + VideoInputs, + VideoOutputs, + VideoGenerateResponse, + VideoStatusResponse, +) __all__ = [ @@ -152,4 +159,9 @@ "EvaluationCreateResponse", "EvaluationJob", "EvaluationStatusResponse", + "VideoRequest", + "VideoInputs", + "VideoOutputs", + "VideoGenerateResponse", + "VideoStatusResponse", ] diff --git a/src/together/types/videos.py b/src/together/types/videos.py new file mode 100644 index 0000000..036cb2b --- /dev/null +++ b/src/together/types/videos.py @@ -0,0 +1,79 @@ +from __future__ import annotations + +from typing import Any, Dict, List, Literal, Optional + +from together.types.abstract import BaseModel + + +class VideoRequest(BaseModel): + """Request model for video generation""" + + # Required parameters + model: str + prompt: str + + # Optional dimension parameters + height: int | None = None + width: int | None = None + + # Optional generation parameters + seconds: float | None = None # Min 1 max 10 + fps: int | None = None # Frames per second, min 15 max 60, default 24 + steps: int | None = None # Denoising steps, min 10 max 50, default 20 + seed: int | None = None + guidance_scale: float | None = None # Default 8, recommended 6.0-10.0 + output_format: str | None = None # "MP4" or "WEBM", default "MP4" + output_quality: int | None = None # Compression quality, default 20 + negative_prompt: str | None = None + + # Advanced parameters + frame_images: List[Dict[str, Any]] | None = None # Array of keyframe images + reference_images: List[Dict[str, Any]] | None = None # Array of reference images + metadata: Dict[str, Any] | None = None + + +class VideoInputs(BaseModel): + """Input parameters used for video generation""" + + model: str + prompt: str + height: int + width: int + seconds: float + seed: int | None = None + fps: int | None = None + steps: int | None = None + guidance_scale: float | None = None + output_quality: int | None = None + output_format: str | None = None + negative_prompt: str | None = None + frame_images: List[Dict[str, Any]] | None = None + reference_images: List[Dict[str, Any]] | None = None + metadata: Dict[str, Any] | None = None + + +class VideoOutputs(BaseModel): + """Output information for completed video generation""" + + cost: float + video_url: str + + +class VideoGenerateResponse(BaseModel): + """Response from video generation request""" + + id: str + + +class VideoStatusResponse(BaseModel): + """Response from video status check""" + + id: str + model: str + status: Literal["queued", "in_progress", "completed", "failed", "cancelled"] + info: Dict[str, Any] | None = None + inputs: VideoInputs + outputs: VideoOutputs | None = None + created_at: str + claimed_at: str + done_at: str From 474d848d2995bdfe3cff0846a068d5474ed2b1f6 Mon Sep 17 00:00:00 2001 From: Rishabh Bhargava Date: Thu, 16 Oct 2025 03:53:33 +0530 Subject: [PATCH 2/6] Small change --- src/together/resources/videos.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/together/resources/videos.py b/src/together/resources/videos.py index 784b68c..190313e 100644 --- a/src/together/resources/videos.py +++ b/src/together/resources/videos.py @@ -45,7 +45,7 @@ def generate( Args: prompt (str): A description of the desired video. Positive prompt for the generation. - model (str): The model to use for video generation (e.g., "google/veo-3.0-fast"). + model (str): The model to use for video generation. height (int, optional): Height of the video to generate in pixels. @@ -191,7 +191,7 @@ async def generate( Args: prompt (str): A description of the desired video. Positive prompt for the generation. - model (str): The model to use for video generation (e.g., "google/veo-3.0-fast"). + model (str): The model to use for video generation. height (int, optional): Height of the video to generate in pixels. From 6b2e177d516358575db402814a0bbd8495451e65 Mon Sep 17 00:00:00 2001 From: Blaine Kasten Date: Thu, 16 Oct 2025 14:12:05 -0500 Subject: [PATCH 3/6] Update Video API PR with requested changes (#378) * Update Video API PR with requested changes * change retrieve api to not use named arguments --- src/together/resources/videos.py | 69 ++++++++++++++------------------ src/together/types/__init__.py | 16 +++----- src/together/types/videos.py | 51 ++++++++++------------- 3 files changed, 57 insertions(+), 79 deletions(-) diff --git a/src/together/resources/videos.py b/src/together/resources/videos.py index 190313e..49aa655 100644 --- a/src/together/resources/videos.py +++ b/src/together/resources/videos.py @@ -9,9 +9,9 @@ TogetherRequest, ) from together.types.videos import ( - VideoGenerateResponse, - VideoRequest, - VideoStatusResponse, + CreateVideoResponse, + CreateVideoBody, + VideoResource, ) @@ -19,7 +19,7 @@ class Videos: def __init__(self, client: TogetherClient) -> None: self._client = client - def generate( + def create( self, *, prompt: str, @@ -31,14 +31,13 @@ def generate( steps: int | None = None, seed: int | None = None, guidance_scale: float | None = None, - output_format: str | None = None, + output_format: Literal["MP4", "WEBM"] | None = None, output_quality: int | None = None, negative_prompt: str | None = None, frame_images: List[Dict[str, Any]] | None = None, - reference_images: List[Dict[str, Any]] | None = None, - metadata: Dict[str, Any] | None = None, + reference_images: List[str] | None = None, **kwargs: Any, - ) -> VideoGenerateResponse: + ) -> CreateVideoResponse: """ Method to generate videos based on a given prompt using a specified model. @@ -82,22 +81,20 @@ def generate( like keyframes. If size 1, starting frame; if size 2, starting and ending frame; if more than 2 then frame must be specified. Defaults to None. - reference_images (List[Dict[str, Any]], optional): An array containing reference images + reference_images (List[str], optional): An array containing reference images used to condition the generation process. These images provide visual guidance to help the model generate content that aligns with the style, composition, or characteristics of the reference materials. Defaults to None. - metadata (Dict[str, Any], optional): Additional metadata for the request. Defaults to None. - Returns: - VideoGenerateResponse: Object containing video generation job id + CreateVideoResponse: Object containing video generation job id """ requestor = api_requestor.APIRequestor( client=self._client, ) - parameter_payload = VideoRequest( + parameter_payload = CreateVideoBody( prompt=prompt, model=model, height=height, @@ -112,7 +109,6 @@ def generate( negative_prompt=negative_prompt, frame_images=frame_images, reference_images=reference_images, - metadata=metadata, **kwargs, ).model_dump(exclude_none=True) @@ -127,21 +123,20 @@ def generate( assert isinstance(response, TogetherResponse) - return VideoGenerateResponse(**response.data) + return CreateVideoResponse(**response.data) - def status( + def retrieve( self, - *, id: str, - ) -> VideoStatusResponse: + ) -> VideoResource: """ - Method to check the status of a video generation job. + Method to retrieve a video creation job. Args: - id (str): The ID of the video generation job to check. + id (str): The ID of the video creation job to retrieve. Returns: - VideoStatusResponse: Object containing the current status and details of the video generation job + VideoResource: Object containing the current status and details of the video creation job """ requestor = api_requestor.APIRequestor( @@ -158,14 +153,14 @@ def status( assert isinstance(response, TogetherResponse) - return VideoStatusResponse(**response.data) + return VideoResource(**response.data) class AsyncVideos: def __init__(self, client: TogetherClient) -> None: self._client = client - async def generate( + async def create( self, *, prompt: str, @@ -177,16 +172,15 @@ async def generate( steps: int | None = None, seed: int | None = None, guidance_scale: float | None = None, - output_format: str | None = None, + output_format: Literal["MP4", "WEBM"] | None = None, output_quality: int | None = None, negative_prompt: str | None = None, frame_images: List[Dict[str, Any]] | None = None, - reference_images: List[Dict[str, Any]] | None = None, - metadata: Dict[str, Any] | None = None, + reference_images: List[str] | None = None, **kwargs: Any, - ) -> VideoGenerateResponse: + ) -> CreateVideoResponse: """ - Async method to generate videos based on a given prompt using a specified model. + Async method to create videos based on a given prompt using a specified model. Args: prompt (str): A description of the desired video. Positive prompt for the generation. @@ -216,7 +210,7 @@ async def generate( most video models. Values above 12 may cause over-guidance artifacts or unnatural motion patterns. Defaults to 8. - output_format (str, optional): Specifies the format of the output video. Either "MP4" + output_format (Literal["MP4", "WEBM"], optional): Specifies the format of the output video. Either "MP4" or "WEBM". Defaults to "MP4". output_quality (int, optional): Compression quality. Defaults to 20. @@ -228,22 +222,20 @@ async def generate( like keyframes. If size 1, starting frame; if size 2, starting and ending frame; if more than 2 then frame must be specified. Defaults to None. - reference_images (List[Dict[str, Any]], optional): An array containing reference images + reference_images (List[str], optional): An array containing reference images used to condition the generation process. These images provide visual guidance to help the model generate content that aligns with the style, composition, or characteristics of the reference materials. Defaults to None. - metadata (Dict[str, Any], optional): Additional metadata for the request. Defaults to None. - Returns: - VideoGenerateResponse: Object containing video generation job id + CreateVideoResponse: Object containing video creation job id """ requestor = api_requestor.APIRequestor( client=self._client, ) - parameter_payload = VideoRequest( + parameter_payload = CreateVideoBody( prompt=prompt, model=model, height=height, @@ -258,7 +250,6 @@ async def generate( negative_prompt=negative_prompt, frame_images=frame_images, reference_images=reference_images, - metadata=metadata, **kwargs, ).model_dump(exclude_none=True) @@ -273,13 +264,13 @@ async def generate( assert isinstance(response, TogetherResponse) - return VideoGenerateResponse(**response.data) + return CreateVideoResponse(**response.data) async def status( self, *, id: str, - ) -> VideoStatusResponse: + ) -> VideoResource: """ Async method to check the status of a video generation job. @@ -287,7 +278,7 @@ async def status( id (str): The ID of the video generation job to check. Returns: - VideoStatusResponse: Object containing the current status and details of the video generation job + VideoResource: Object containing the current status and details of the video generation job """ requestor = api_requestor.APIRequestor( @@ -304,4 +295,4 @@ async def status( assert isinstance(response, TogetherResponse) - return VideoStatusResponse(**response.data) + return VideoResource(**response.data) diff --git a/src/together/types/__init__.py b/src/together/types/__init__.py index eefa412..164cc04 100644 --- a/src/together/types/__init__.py +++ b/src/together/types/__init__.py @@ -76,11 +76,9 @@ EvaluationStatusResponse, ) from together.types.videos import ( - VideoRequest, - VideoInputs, - VideoOutputs, - VideoGenerateResponse, - VideoStatusResponse, + CreateVideoBody, + CreateVideoResponse, + VideoResource, ) @@ -159,9 +157,7 @@ "EvaluationCreateResponse", "EvaluationJob", "EvaluationStatusResponse", - "VideoRequest", - "VideoInputs", - "VideoOutputs", - "VideoGenerateResponse", - "VideoStatusResponse", + "CreateVideoBody", + "CreateVideoResponse", + "VideoResource", ] diff --git a/src/together/types/videos.py b/src/together/types/videos.py index 036cb2b..92880db 100644 --- a/src/together/types/videos.py +++ b/src/together/types/videos.py @@ -5,8 +5,8 @@ from together.types.abstract import BaseModel -class VideoRequest(BaseModel): - """Request model for video generation""" +class CreateVideoBody(BaseModel): + """Request model for video creation""" # Required parameters model: str @@ -22,57 +22,48 @@ class VideoRequest(BaseModel): steps: int | None = None # Denoising steps, min 10 max 50, default 20 seed: int | None = None guidance_scale: float | None = None # Default 8, recommended 6.0-10.0 - output_format: str | None = None # "MP4" or "WEBM", default "MP4" + output_format: Literal["MP4", "WEBM"] | None = None # "MP4" or "WEBM", default "MP4" output_quality: int | None = None # Compression quality, default 20 negative_prompt: str | None = None # Advanced parameters frame_images: List[Dict[str, Any]] | None = None # Array of keyframe images - reference_images: List[Dict[str, Any]] | None = None # Array of reference images - metadata: Dict[str, Any] | None = None - - -class VideoInputs(BaseModel): - """Input parameters used for video generation""" - - model: str - prompt: str - height: int - width: int - seconds: float - seed: int | None = None - fps: int | None = None - steps: int | None = None - guidance_scale: float | None = None - output_quality: int | None = None - output_format: str | None = None - negative_prompt: str | None = None - frame_images: List[Dict[str, Any]] | None = None - reference_images: List[Dict[str, Any]] | None = None - metadata: Dict[str, Any] | None = None + reference_images: List[str] | None = None # Array of reference images class VideoOutputs(BaseModel): - """Output information for completed video generation""" + """Response from video creation request""" cost: float video_url: str +class VideoInfoError(BaseModel): + """Error about the video creation request""" + + code: str + message: str + +class VideoInfo(BaseModel): + """Info about the video creation request""" + + user_id: str + errors: List[VideoInfoError] | None = None + -class VideoGenerateResponse(BaseModel): +class CreateVideoResponse(BaseModel): """Response from video generation request""" id: str -class VideoStatusResponse(BaseModel): +class VideoResource(BaseModel): """Response from video status check""" id: str model: str status: Literal["queued", "in_progress", "completed", "failed", "cancelled"] - info: Dict[str, Any] | None = None - inputs: VideoInputs + info: VideoInfo | None = None + inputs: Dict[str, Any] outputs: VideoOutputs | None = None created_at: str claimed_at: str From 0e7ba25c3520772eac8884e32bcdc209df727914 Mon Sep 17 00:00:00 2001 From: Blaine Kasten Date: Thu, 16 Oct 2025 14:15:47 -0500 Subject: [PATCH 4/6] fix formatting --- src/together/resources/videos.py | 6 ++++++ src/together/types/videos.py | 6 +++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/together/resources/videos.py b/src/together/resources/videos.py index 49aa655..e9bb0e9 100644 --- a/src/together/resources/videos.py +++ b/src/together/resources/videos.py @@ -1,6 +1,7 @@ from __future__ import annotations from typing import Any, Dict, List +import sys from together.abstract import api_requestor from together.together_response import TogetherResponse @@ -14,6 +15,11 @@ VideoResource, ) +if sys.version_info >= (3, 8): + from typing import Literal +else: + from typing_extensions import Literal + class Videos: def __init__(self, client: TogetherClient) -> None: diff --git a/src/together/types/videos.py b/src/together/types/videos.py index 92880db..02a26a8 100644 --- a/src/together/types/videos.py +++ b/src/together/types/videos.py @@ -22,7 +22,9 @@ class CreateVideoBody(BaseModel): steps: int | None = None # Denoising steps, min 10 max 50, default 20 seed: int | None = None guidance_scale: float | None = None # Default 8, recommended 6.0-10.0 - output_format: Literal["MP4", "WEBM"] | None = None # "MP4" or "WEBM", default "MP4" + output_format: Literal["MP4", "WEBM"] | None = ( + None # "MP4" or "WEBM", default "MP4" + ) output_quality: int | None = None # Compression quality, default 20 negative_prompt: str | None = None @@ -37,12 +39,14 @@ class VideoOutputs(BaseModel): cost: float video_url: str + class VideoInfoError(BaseModel): """Error about the video creation request""" code: str message: str + class VideoInfo(BaseModel): """Info about the video creation request""" From b037ca2fe23abba37142946b83b00976dff00f19 Mon Sep 17 00:00:00 2001 From: Blaine Kasten Date: Mon, 20 Oct 2025 09:59:24 -0500 Subject: [PATCH 5/6] change to the openai compatible api --- src/together/resources/videos.py | 25 ++++++++++++------------- src/together/types/__init__.py | 4 ++-- src/together/types/videos.py | 31 +++++++++++++------------------ 3 files changed, 27 insertions(+), 33 deletions(-) diff --git a/src/together/resources/videos.py b/src/together/resources/videos.py index e9bb0e9..d4e75e8 100644 --- a/src/together/resources/videos.py +++ b/src/together/resources/videos.py @@ -12,7 +12,7 @@ from together.types.videos import ( CreateVideoResponse, CreateVideoBody, - VideoResource, + VideoJob, ) if sys.version_info >= (3, 8): @@ -134,7 +134,7 @@ def create( def retrieve( self, id: str, - ) -> VideoResource: + ) -> VideoJob: """ Method to retrieve a video creation job. @@ -142,7 +142,7 @@ def retrieve( id (str): The ID of the video creation job to retrieve. Returns: - VideoResource: Object containing the current status and details of the video creation job + VideoJob: Object containing the current status and details of the video creation job """ requestor = api_requestor.APIRequestor( @@ -152,14 +152,14 @@ def retrieve( response, _, _ = requestor.request( options=TogetherRequest( method="GET", - url=f"../v2/videos/status?id={id}", + url=f"../v2/videos/{id}", ), stream=False, ) assert isinstance(response, TogetherResponse) - return VideoResource(**response.data) + return VideoJob(**response.data) class AsyncVideos: @@ -272,19 +272,18 @@ async def create( return CreateVideoResponse(**response.data) - async def status( + async def retrieve( self, - *, id: str, - ) -> VideoResource: + ) -> VideoJob: """ - Async method to check the status of a video generation job. + Async method to retrieve a video creation job. Args: - id (str): The ID of the video generation job to check. + id (str): The ID of the video creation job to retrieve. Returns: - VideoResource: Object containing the current status and details of the video generation job + VideoJob: Object containing the current status and details of the video creation job """ requestor = api_requestor.APIRequestor( @@ -294,11 +293,11 @@ async def status( response, _, _ = await requestor.arequest( options=TogetherRequest( method="GET", - url=f"../v2/videos/status?id={id}", + url=f"../v2/videos/{id}", ), stream=False, ) assert isinstance(response, TogetherResponse) - return VideoResource(**response.data) + return VideoJob(**response.data) diff --git a/src/together/types/__init__.py b/src/together/types/__init__.py index 164cc04..e30fe1b 100644 --- a/src/together/types/__init__.py +++ b/src/together/types/__init__.py @@ -78,7 +78,7 @@ from together.types.videos import ( CreateVideoBody, CreateVideoResponse, - VideoResource, + VideoJob, ) @@ -159,5 +159,5 @@ "EvaluationStatusResponse", "CreateVideoBody", "CreateVideoResponse", - "VideoResource", + "VideoJob", ] diff --git a/src/together/types/videos.py b/src/together/types/videos.py index 02a26a8..aaad3b2 100644 --- a/src/together/types/videos.py +++ b/src/together/types/videos.py @@ -34,41 +34,36 @@ class CreateVideoBody(BaseModel): class VideoOutputs(BaseModel): - """Response from video creation request""" + """Artifacts generated from video creation job""" cost: float video_url: str -class VideoInfoError(BaseModel): - """Error about the video creation request""" +class Error(BaseModel): + """Error information about the video job""" - code: str + code: str | None = None message: str -class VideoInfo(BaseModel): - """Info about the video creation request""" - - user_id: str - errors: List[VideoInfoError] | None = None - - class CreateVideoResponse(BaseModel): """Response from video generation request""" id: str -class VideoResource(BaseModel): - """Response from video status check""" +class VideoJob(BaseModel): + """Structured information describing a generated video job.""" id: str model: str + object: Literal["video"] status: Literal["queued", "in_progress", "completed", "failed", "cancelled"] - info: VideoInfo | None = None - inputs: Dict[str, Any] + seconds: str + size: str + created_at: int + + error: Error | None = None outputs: VideoOutputs | None = None - created_at: str - claimed_at: str - done_at: str + completed_at: int | None = None From 40bfbcf701240756d635d5eb8b8ed23097a43505 Mon Sep 17 00:00:00 2001 From: Blaine Kasten Date: Mon, 20 Oct 2025 10:20:00 -0500 Subject: [PATCH 6/6] Update create api to have optional prompt and use string for seconds --- src/together/resources/videos.py | 10 +++++----- src/together/types/videos.py | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/together/resources/videos.py b/src/together/resources/videos.py index d4e75e8..d2c8dbb 100644 --- a/src/together/resources/videos.py +++ b/src/together/resources/videos.py @@ -28,11 +28,11 @@ def __init__(self, client: TogetherClient) -> None: def create( self, *, - prompt: str, model: str, + prompt: str | None = None, height: int | None = None, width: int | None = None, - seconds: float | None = None, + seconds: str | None = None, fps: int | None = None, steps: int | None = None, seed: int | None = None, @@ -48,15 +48,15 @@ def create( Method to generate videos based on a given prompt using a specified model. Args: - prompt (str): A description of the desired video. Positive prompt for the generation. - model (str): The model to use for video generation. + prompt (str): A description of the desired video. Positive prompt for the generation. + height (int, optional): Height of the video to generate in pixels. width (int, optional): Width of the video to generate in pixels. - seconds (float, optional): Length of generated video in seconds. Min 1 max 10. + seconds (str, optional): Length of generated video in seconds. Min 1 max 10. fps (int, optional): Frames per second, min 15 max 60. Defaults to 24. diff --git a/src/together/types/videos.py b/src/together/types/videos.py index aaad3b2..4cd959c 100644 --- a/src/together/types/videos.py +++ b/src/together/types/videos.py @@ -10,14 +10,14 @@ class CreateVideoBody(BaseModel): # Required parameters model: str - prompt: str # Optional dimension parameters + prompt: str | None = None height: int | None = None width: int | None = None # Optional generation parameters - seconds: float | None = None # Min 1 max 10 + seconds: str | None = None # Min 1 max 10 fps: int | None = None # Frames per second, min 15 max 60, default 24 steps: int | None = None # Denoising steps, min 10 max 50, default 20 seed: int | None = None