From 72640f5f3cc5da301cf8537d3dc4f6e2e3770af3 Mon Sep 17 00:00:00 2001 From: stlc-bot Date: Wed, 11 Nov 2026 17:26:52 +0000 Subject: [PATCH] feat: add image-to-vector and text-to-music methods Stainless-Generated-From: 7d2e30f8aa1255645cb699b023efd143967b359b --- .stats.yml | 2 +- api.md | 24 ++ src/runwayml/_client.py | 88 +++++++ src/runwayml/resources/__init__.py | 28 +++ src/runwayml/resources/image_to_vector.py | 223 +++++++++++++++++ src/runwayml/resources/text_to_music.py | 235 ++++++++++++++++++ src/runwayml/types/__init__.py | 4 + .../types/image_to_vector_create_params.py | 23 ++ .../types/image_to_vector_create_response.py | 28 +++ .../types/text_to_music_create_params.py | 31 +++ .../types/text_to_music_create_response.py | 28 +++ tests/api_resources/test_image_to_vector.py | 110 ++++++++ tests/api_resources/test_text_to_music.py | 112 +++++++++ tests/test_vector_music_polling.py | 93 +++++++ 14 files changed, 1028 insertions(+), 1 deletion(-) create mode 100644 src/runwayml/resources/image_to_vector.py create mode 100644 src/runwayml/resources/text_to_music.py create mode 100644 src/runwayml/types/image_to_vector_create_params.py create mode 100644 src/runwayml/types/image_to_vector_create_response.py create mode 100644 src/runwayml/types/text_to_music_create_params.py create mode 100644 src/runwayml/types/text_to_music_create_response.py create mode 100644 tests/api_resources/test_image_to_vector.py create mode 100644 tests/api_resources/test_text_to_music.py create mode 100644 tests/test_vector_music_polling.py diff --git a/.stats.yml b/.stats.yml index 8191416..ff3d4c6 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1 +1 @@ -configured_endpoints: 65 +configured_endpoints: 67 diff --git a/api.md b/api.md index 91729b7..c95cecd 100644 --- a/api.md +++ b/api.md @@ -83,6 +83,30 @@ Methods: - client.text_to_image.create(\*\*params) -> TextToImageCreateResponse +# ImageToVector + +Types: + +```python +from runwayml.types import ImageToVectorCreateResponse +``` + +Methods: + +- client.image_to_vector.create(\*\*params) -> ImageToVectorCreateResponse + +# TextToMusic + +Types: + +```python +from runwayml.types import TextToMusicCreateResponse +``` + +Methods: + +- client.text_to_music.create(\*\*params) -> TextToMusicCreateResponse + # CharacterPerformance Types: diff --git a/src/runwayml/_client.py b/src/runwayml/_client.py index 11ee112..cc3fabb 100644 --- a/src/runwayml/_client.py +++ b/src/runwayml/_client.py @@ -51,6 +51,7 @@ avatar_videos, image_upscale, text_to_image, + text_to_music, text_to_video, video_upscale, voice_dubbing, @@ -58,6 +59,7 @@ text_to_speech, video_to_audio, video_to_video, + image_to_vector, voice_isolation, speech_to_speech, realtime_sessions, @@ -78,6 +80,7 @@ from .resources.avatar_videos import AvatarVideosResource, AsyncAvatarVideosResource from .resources.image_upscale import ImageUpscaleResource, AsyncImageUpscaleResource from .resources.text_to_image import TextToImageResource, AsyncTextToImageResource + from .resources.text_to_music import TextToMusicResource, AsyncTextToMusicResource from .resources.text_to_video import TextToVideoResource, AsyncTextToVideoResource from .resources.video_upscale import VideoUpscaleResource, AsyncVideoUpscaleResource from .resources.voice_dubbing import VoiceDubbingResource, AsyncVoiceDubbingResource @@ -85,6 +88,7 @@ from .resources.text_to_speech import TextToSpeechResource, AsyncTextToSpeechResource from .resources.video_to_audio import VideoToAudioResource, AsyncVideoToAudioResource from .resources.video_to_video import VideoToVideoResource, AsyncVideoToVideoResource + from .resources.image_to_vector import ImageToVectorResource, AsyncImageToVectorResource from .resources.voice_isolation import VoiceIsolationResource, AsyncVoiceIsolationResource from .resources.speech_to_speech import SpeechToSpeechResource, AsyncSpeechToSpeechResource from .resources.generate.generate import GenerateResource, AsyncGenerateResource @@ -231,6 +235,20 @@ def text_to_image(self) -> TextToImageResource: return TextToImageResource(self) + @cached_property + def image_to_vector(self) -> ImageToVectorResource: + """These endpoints all kick off tasks to create generations.""" + from .resources.image_to_vector import ImageToVectorResource + + return ImageToVectorResource(self) + + @cached_property + def text_to_music(self) -> TextToMusicResource: + """These endpoints all kick off tasks to create generations.""" + from .resources.text_to_music import TextToMusicResource + + return TextToMusicResource(self) + @cached_property def character_performance(self) -> CharacterPerformanceResource: """These endpoints all kick off tasks to create generations.""" @@ -600,6 +618,20 @@ def text_to_image(self) -> AsyncTextToImageResource: return AsyncTextToImageResource(self) + @cached_property + def image_to_vector(self) -> AsyncImageToVectorResource: + """These endpoints all kick off tasks to create generations.""" + from .resources.image_to_vector import AsyncImageToVectorResource + + return AsyncImageToVectorResource(self) + + @cached_property + def text_to_music(self) -> AsyncTextToMusicResource: + """These endpoints all kick off tasks to create generations.""" + from .resources.text_to_music import AsyncTextToMusicResource + + return AsyncTextToMusicResource(self) + @cached_property def character_performance(self) -> AsyncCharacterPerformanceResource: """These endpoints all kick off tasks to create generations.""" @@ -905,6 +937,20 @@ def text_to_image(self) -> text_to_image.TextToImageResourceWithRawResponse: return TextToImageResourceWithRawResponse(self._client.text_to_image) + @cached_property + def image_to_vector(self) -> image_to_vector.ImageToVectorResourceWithRawResponse: + """These endpoints all kick off tasks to create generations.""" + from .resources.image_to_vector import ImageToVectorResourceWithRawResponse + + return ImageToVectorResourceWithRawResponse(self._client.image_to_vector) + + @cached_property + def text_to_music(self) -> text_to_music.TextToMusicResourceWithRawResponse: + """These endpoints all kick off tasks to create generations.""" + from .resources.text_to_music import TextToMusicResourceWithRawResponse + + return TextToMusicResourceWithRawResponse(self._client.text_to_music) + @cached_property def character_performance(self) -> character_performance.CharacterPerformanceResourceWithRawResponse: """These endpoints all kick off tasks to create generations.""" @@ -1095,6 +1141,20 @@ def text_to_image(self) -> text_to_image.AsyncTextToImageResourceWithRawResponse return AsyncTextToImageResourceWithRawResponse(self._client.text_to_image) + @cached_property + def image_to_vector(self) -> image_to_vector.AsyncImageToVectorResourceWithRawResponse: + """These endpoints all kick off tasks to create generations.""" + from .resources.image_to_vector import AsyncImageToVectorResourceWithRawResponse + + return AsyncImageToVectorResourceWithRawResponse(self._client.image_to_vector) + + @cached_property + def text_to_music(self) -> text_to_music.AsyncTextToMusicResourceWithRawResponse: + """These endpoints all kick off tasks to create generations.""" + from .resources.text_to_music import AsyncTextToMusicResourceWithRawResponse + + return AsyncTextToMusicResourceWithRawResponse(self._client.text_to_music) + @cached_property def character_performance(self) -> character_performance.AsyncCharacterPerformanceResourceWithRawResponse: """These endpoints all kick off tasks to create generations.""" @@ -1285,6 +1345,20 @@ def text_to_image(self) -> text_to_image.TextToImageResourceWithStreamingRespons return TextToImageResourceWithStreamingResponse(self._client.text_to_image) + @cached_property + def image_to_vector(self) -> image_to_vector.ImageToVectorResourceWithStreamingResponse: + """These endpoints all kick off tasks to create generations.""" + from .resources.image_to_vector import ImageToVectorResourceWithStreamingResponse + + return ImageToVectorResourceWithStreamingResponse(self._client.image_to_vector) + + @cached_property + def text_to_music(self) -> text_to_music.TextToMusicResourceWithStreamingResponse: + """These endpoints all kick off tasks to create generations.""" + from .resources.text_to_music import TextToMusicResourceWithStreamingResponse + + return TextToMusicResourceWithStreamingResponse(self._client.text_to_music) + @cached_property def character_performance(self) -> character_performance.CharacterPerformanceResourceWithStreamingResponse: """These endpoints all kick off tasks to create generations.""" @@ -1475,6 +1549,20 @@ def text_to_image(self) -> text_to_image.AsyncTextToImageResourceWithStreamingRe return AsyncTextToImageResourceWithStreamingResponse(self._client.text_to_image) + @cached_property + def image_to_vector(self) -> image_to_vector.AsyncImageToVectorResourceWithStreamingResponse: + """These endpoints all kick off tasks to create generations.""" + from .resources.image_to_vector import AsyncImageToVectorResourceWithStreamingResponse + + return AsyncImageToVectorResourceWithStreamingResponse(self._client.image_to_vector) + + @cached_property + def text_to_music(self) -> text_to_music.AsyncTextToMusicResourceWithStreamingResponse: + """These endpoints all kick off tasks to create generations.""" + from .resources.text_to_music import AsyncTextToMusicResourceWithStreamingResponse + + return AsyncTextToMusicResourceWithStreamingResponse(self._client.text_to_music) + @cached_property def character_performance(self) -> character_performance.AsyncCharacterPerformanceResourceWithStreamingResponse: """These endpoints all kick off tasks to create generations.""" diff --git a/src/runwayml/resources/__init__.py b/src/runwayml/resources/__init__.py index 63194fb..7210a0d 100644 --- a/src/runwayml/resources/__init__.py +++ b/src/runwayml/resources/__init__.py @@ -120,6 +120,14 @@ TextToImageResourceWithStreamingResponse, AsyncTextToImageResourceWithStreamingResponse, ) +from .text_to_music import ( + TextToMusicResource, + AsyncTextToMusicResource, + TextToMusicResourceWithRawResponse, + AsyncTextToMusicResourceWithRawResponse, + TextToMusicResourceWithStreamingResponse, + AsyncTextToMusicResourceWithStreamingResponse, +) from .text_to_video import ( TextToVideoResource, AsyncTextToVideoResource, @@ -176,6 +184,14 @@ VideoToVideoResourceWithStreamingResponse, AsyncVideoToVideoResourceWithStreamingResponse, ) +from .image_to_vector import ( + ImageToVectorResource, + AsyncImageToVectorResource, + ImageToVectorResourceWithRawResponse, + AsyncImageToVectorResourceWithRawResponse, + ImageToVectorResourceWithStreamingResponse, + AsyncImageToVectorResourceWithStreamingResponse, +) from .voice_isolation import ( VoiceIsolationResource, AsyncVoiceIsolationResource, @@ -268,6 +284,18 @@ "AsyncTextToImageResourceWithRawResponse", "TextToImageResourceWithStreamingResponse", "AsyncTextToImageResourceWithStreamingResponse", + "ImageToVectorResource", + "AsyncImageToVectorResource", + "ImageToVectorResourceWithRawResponse", + "AsyncImageToVectorResourceWithRawResponse", + "ImageToVectorResourceWithStreamingResponse", + "AsyncImageToVectorResourceWithStreamingResponse", + "TextToMusicResource", + "AsyncTextToMusicResource", + "TextToMusicResourceWithRawResponse", + "AsyncTextToMusicResourceWithRawResponse", + "TextToMusicResourceWithStreamingResponse", + "AsyncTextToMusicResourceWithStreamingResponse", "CharacterPerformanceResource", "AsyncCharacterPerformanceResource", "CharacterPerformanceResourceWithRawResponse", diff --git a/src/runwayml/resources/image_to_vector.py b/src/runwayml/resources/image_to_vector.py new file mode 100644 index 0000000..77273ea --- /dev/null +++ b/src/runwayml/resources/image_to_vector.py @@ -0,0 +1,223 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from __future__ import annotations + +from typing import Type, cast +from typing_extensions import Literal + +import httpx + +from ..types import image_to_vector_create_params +from .._types import Body, Omit, Query, Headers, NotGiven, omit, not_given +from .._utils import maybe_transform, async_maybe_transform +from .._compat import cached_property +from .._resource import SyncAPIResource, AsyncAPIResource +from .._response import ( + to_raw_response_wrapper, + to_streamed_response_wrapper, + async_to_raw_response_wrapper, + async_to_streamed_response_wrapper, +) +from ..lib.polling import ( + AwaitableTaskResponseMixin, + AsyncAwaitableTaskResponseMixin, + create_waitable_resource, + create_async_waitable_resource, +) +from .._base_client import make_request_options +from ..types.image_to_vector_create_response import ImageToVectorCreateResponse + +__all__ = [ + "ImageToVectorResource", + "AsyncImageToVectorResource", + "WaitableImageToVectorCreateResponse", + "AsyncWaitableImageToVectorCreateResponse", +] + + +class WaitableImageToVectorCreateResponse(ImageToVectorCreateResponse, AwaitableTaskResponseMixin): ... + + +class AsyncWaitableImageToVectorCreateResponse(ImageToVectorCreateResponse, AsyncAwaitableTaskResponseMixin): ... + + +class ImageToVectorResource(SyncAPIResource): + """These endpoints all kick off tasks to create generations.""" + + @cached_property + def with_raw_response(self) -> ImageToVectorResourceWithRawResponse: + """ + This property can be used as a prefix for any HTTP method call to return + the raw response object instead of the parsed content. + + For more information, see https://www.github.com/runwayml/sdk-python#accessing-raw-response-data-eg-headers + """ + return ImageToVectorResourceWithRawResponse(self) + + @cached_property + def with_streaming_response(self) -> ImageToVectorResourceWithStreamingResponse: + """ + An alternative to `.with_raw_response` that doesn't eagerly read the response body. + + For more information, see https://www.github.com/runwayml/sdk-python#with_streaming_response + """ + return ImageToVectorResourceWithStreamingResponse(self) + + def create( + self, + *, + image_uri: str, + model: Literal["ideogram_vector"], + vectorization_mode: Literal["simple", "default"] | Omit = omit, + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. + # The extra values given here take precedence over values defined on the client or passed to this method. + extra_headers: Headers | None = None, + extra_query: Query | None = None, + extra_body: Body | None = None, + timeout: float | httpx.Timeout | None | NotGiven = not_given, + ) -> WaitableImageToVectorCreateResponse: + """ + Convert a source image into a scalable SVG. + + Args: + image_uri: A HTTPS URL, Runway upload URI, or base64 data URI (e.g. + `data:image/png;base64,...`, up to 5MB) containing an encoded image. See + [our docs](/assets/inputs#images) on image inputs for more information. + + vectorization_mode: Use simple for fewer shapes, or default to retain more detail. + + extra_headers: Send extra headers + + extra_query: Add additional query parameters to the request + + extra_body: Add additional JSON properties to the request + + timeout: Override the client-level default timeout for this request, in seconds + """ + return self._post( + "/v1/image_to_vector", + body=maybe_transform( + { + "image_uri": image_uri, + "model": model, + "vectorization_mode": vectorization_mode, + }, + image_to_vector_create_params.ImageToVectorCreateParams, + ), + options=make_request_options( + extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout + ), + cast_to=cast( + Type[WaitableImageToVectorCreateResponse], + create_waitable_resource(WaitableImageToVectorCreateResponse, self._client), + ), + ) + + +class AsyncImageToVectorResource(AsyncAPIResource): + """These endpoints all kick off tasks to create generations.""" + + @cached_property + def with_raw_response(self) -> AsyncImageToVectorResourceWithRawResponse: + """ + This property can be used as a prefix for any HTTP method call to return + the raw response object instead of the parsed content. + + For more information, see https://www.github.com/runwayml/sdk-python#accessing-raw-response-data-eg-headers + """ + return AsyncImageToVectorResourceWithRawResponse(self) + + @cached_property + def with_streaming_response(self) -> AsyncImageToVectorResourceWithStreamingResponse: + """ + An alternative to `.with_raw_response` that doesn't eagerly read the response body. + + For more information, see https://www.github.com/runwayml/sdk-python#with_streaming_response + """ + return AsyncImageToVectorResourceWithStreamingResponse(self) + + async def create( + self, + *, + image_uri: str, + model: Literal["ideogram_vector"], + vectorization_mode: Literal["simple", "default"] | Omit = omit, + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. + # The extra values given here take precedence over values defined on the client or passed to this method. + extra_headers: Headers | None = None, + extra_query: Query | None = None, + extra_body: Body | None = None, + timeout: float | httpx.Timeout | None | NotGiven = not_given, + ) -> AsyncWaitableImageToVectorCreateResponse: + """ + Convert a source image into a scalable SVG. + + Args: + image_uri: A HTTPS URL, Runway upload URI, or base64 data URI (e.g. + `data:image/png;base64,...`, up to 5MB) containing an encoded image. See + [our docs](/assets/inputs#images) on image inputs for more information. + + vectorization_mode: Use simple for fewer shapes, or default to retain more detail. + + extra_headers: Send extra headers + + extra_query: Add additional query parameters to the request + + extra_body: Add additional JSON properties to the request + + timeout: Override the client-level default timeout for this request, in seconds + """ + return await self._post( + "/v1/image_to_vector", + body=await async_maybe_transform( + { + "image_uri": image_uri, + "model": model, + "vectorization_mode": vectorization_mode, + }, + image_to_vector_create_params.ImageToVectorCreateParams, + ), + options=make_request_options( + extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout + ), + cast_to=cast( + Type[AsyncWaitableImageToVectorCreateResponse], + create_async_waitable_resource(AsyncWaitableImageToVectorCreateResponse, self._client), + ), + ) + + +class ImageToVectorResourceWithRawResponse: + def __init__(self, image_to_vector: ImageToVectorResource) -> None: + self._image_to_vector = image_to_vector + + self.create = to_raw_response_wrapper( + image_to_vector.create, + ) + + +class AsyncImageToVectorResourceWithRawResponse: + def __init__(self, image_to_vector: AsyncImageToVectorResource) -> None: + self._image_to_vector = image_to_vector + + self.create = async_to_raw_response_wrapper( + image_to_vector.create, + ) + + +class ImageToVectorResourceWithStreamingResponse: + def __init__(self, image_to_vector: ImageToVectorResource) -> None: + self._image_to_vector = image_to_vector + + self.create = to_streamed_response_wrapper( + image_to_vector.create, + ) + + +class AsyncImageToVectorResourceWithStreamingResponse: + def __init__(self, image_to_vector: AsyncImageToVectorResource) -> None: + self._image_to_vector = image_to_vector + + self.create = async_to_streamed_response_wrapper( + image_to_vector.create, + ) diff --git a/src/runwayml/resources/text_to_music.py b/src/runwayml/resources/text_to_music.py new file mode 100644 index 0000000..5c50e03 --- /dev/null +++ b/src/runwayml/resources/text_to_music.py @@ -0,0 +1,235 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from __future__ import annotations + +from typing import Type, cast +from typing_extensions import Literal + +import httpx + +from ..types import text_to_music_create_params +from .._types import Body, Omit, Query, Headers, NotGiven, omit, not_given +from .._utils import maybe_transform, async_maybe_transform +from .._compat import cached_property +from .._resource import SyncAPIResource, AsyncAPIResource +from .._response import ( + to_raw_response_wrapper, + to_streamed_response_wrapper, + async_to_raw_response_wrapper, + async_to_streamed_response_wrapper, +) +from ..lib.polling import ( + AwaitableTaskResponseMixin, + AsyncAwaitableTaskResponseMixin, + create_waitable_resource, + create_async_waitable_resource, +) +from .._base_client import make_request_options +from ..types.text_to_music_create_response import TextToMusicCreateResponse + +__all__ = [ + "TextToMusicResource", + "AsyncTextToMusicResource", + "WaitableTextToMusicCreateResponse", + "AsyncWaitableTextToMusicCreateResponse", +] + + +class WaitableTextToMusicCreateResponse(TextToMusicCreateResponse, AwaitableTaskResponseMixin): ... + + +class AsyncWaitableTextToMusicCreateResponse(TextToMusicCreateResponse, AsyncAwaitableTaskResponseMixin): ... + + +class TextToMusicResource(SyncAPIResource): + """These endpoints all kick off tasks to create generations.""" + + @cached_property + def with_raw_response(self) -> TextToMusicResourceWithRawResponse: + """ + This property can be used as a prefix for any HTTP method call to return + the raw response object instead of the parsed content. + + For more information, see https://www.github.com/runwayml/sdk-python#accessing-raw-response-data-eg-headers + """ + return TextToMusicResourceWithRawResponse(self) + + @cached_property + def with_streaming_response(self) -> TextToMusicResourceWithStreamingResponse: + """ + An alternative to `.with_raw_response` that doesn't eagerly read the response body. + + For more information, see https://www.github.com/runwayml/sdk-python#with_streaming_response + """ + return TextToMusicResourceWithStreamingResponse(self) + + def create( + self, + *, + model: Literal["eleven_music_v2_5"], + prompt_text: str, + duration: int | Omit = omit, + instrumental: bool | Omit = omit, + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. + # The extra values given here take precedence over values defined on the client or passed to this method. + extra_headers: Headers | None = None, + extra_query: Query | None = None, + extra_body: Body | None = None, + timeout: float | httpx.Timeout | None | NotGiven = not_given, + ) -> WaitableTextToMusicCreateResponse: + """ + This endpoint will start a new task to generate a song or instrumental track + from a text description. + + Args: + prompt_text: A description of the track to generate, such as its genre, mood, instruments, + and vocals. Prompts that name specific artists or songs are rejected. + + duration: The length of the track in whole seconds. You are billed for the requested + length. + + instrumental: When true, the track has no vocals. When omitted, the model decides from the + prompt. + + extra_headers: Send extra headers + + extra_query: Add additional query parameters to the request + + extra_body: Add additional JSON properties to the request + + timeout: Override the client-level default timeout for this request, in seconds + """ + return self._post( + "/v1/text_to_music", + body=maybe_transform( + { + "model": model, + "prompt_text": prompt_text, + "duration": duration, + "instrumental": instrumental, + }, + text_to_music_create_params.TextToMusicCreateParams, + ), + options=make_request_options( + extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout + ), + cast_to=cast( + Type[WaitableTextToMusicCreateResponse], + create_waitable_resource(WaitableTextToMusicCreateResponse, self._client), + ), + ) + + +class AsyncTextToMusicResource(AsyncAPIResource): + """These endpoints all kick off tasks to create generations.""" + + @cached_property + def with_raw_response(self) -> AsyncTextToMusicResourceWithRawResponse: + """ + This property can be used as a prefix for any HTTP method call to return + the raw response object instead of the parsed content. + + For more information, see https://www.github.com/runwayml/sdk-python#accessing-raw-response-data-eg-headers + """ + return AsyncTextToMusicResourceWithRawResponse(self) + + @cached_property + def with_streaming_response(self) -> AsyncTextToMusicResourceWithStreamingResponse: + """ + An alternative to `.with_raw_response` that doesn't eagerly read the response body. + + For more information, see https://www.github.com/runwayml/sdk-python#with_streaming_response + """ + return AsyncTextToMusicResourceWithStreamingResponse(self) + + async def create( + self, + *, + model: Literal["eleven_music_v2_5"], + prompt_text: str, + duration: int | Omit = omit, + instrumental: bool | Omit = omit, + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. + # The extra values given here take precedence over values defined on the client or passed to this method. + extra_headers: Headers | None = None, + extra_query: Query | None = None, + extra_body: Body | None = None, + timeout: float | httpx.Timeout | None | NotGiven = not_given, + ) -> AsyncWaitableTextToMusicCreateResponse: + """ + This endpoint will start a new task to generate a song or instrumental track + from a text description. + + Args: + prompt_text: A description of the track to generate, such as its genre, mood, instruments, + and vocals. Prompts that name specific artists or songs are rejected. + + duration: The length of the track in whole seconds. You are billed for the requested + length. + + instrumental: When true, the track has no vocals. When omitted, the model decides from the + prompt. + + extra_headers: Send extra headers + + extra_query: Add additional query parameters to the request + + extra_body: Add additional JSON properties to the request + + timeout: Override the client-level default timeout for this request, in seconds + """ + return await self._post( + "/v1/text_to_music", + body=await async_maybe_transform( + { + "model": model, + "prompt_text": prompt_text, + "duration": duration, + "instrumental": instrumental, + }, + text_to_music_create_params.TextToMusicCreateParams, + ), + options=make_request_options( + extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout + ), + cast_to=cast( + Type[AsyncWaitableTextToMusicCreateResponse], + create_async_waitable_resource(AsyncWaitableTextToMusicCreateResponse, self._client), + ), + ) + + +class TextToMusicResourceWithRawResponse: + def __init__(self, text_to_music: TextToMusicResource) -> None: + self._text_to_music = text_to_music + + self.create = to_raw_response_wrapper( + text_to_music.create, + ) + + +class AsyncTextToMusicResourceWithRawResponse: + def __init__(self, text_to_music: AsyncTextToMusicResource) -> None: + self._text_to_music = text_to_music + + self.create = async_to_raw_response_wrapper( + text_to_music.create, + ) + + +class TextToMusicResourceWithStreamingResponse: + def __init__(self, text_to_music: TextToMusicResource) -> None: + self._text_to_music = text_to_music + + self.create = to_streamed_response_wrapper( + text_to_music.create, + ) + + +class AsyncTextToMusicResourceWithStreamingResponse: + def __init__(self, text_to_music: AsyncTextToMusicResource) -> None: + self._text_to_music = text_to_music + + self.create = async_to_streamed_response_wrapper( + text_to_music.create, + ) diff --git a/src/runwayml/types/__init__.py b/src/runwayml/types/__init__.py index d954707..6b4443b 100644 --- a/src/runwayml/types/__init__.py +++ b/src/runwayml/types/__init__.py @@ -50,6 +50,7 @@ from .recipe_product_ugc_response import RecipeProductUgcResponse as RecipeProductUgcResponse from .router_list_requests_params import RouterListRequestsParams as RouterListRequestsParams from .text_to_image_create_params import TextToImageCreateParams as TextToImageCreateParams +from .text_to_music_create_params import TextToMusicCreateParams as TextToMusicCreateParams from .text_to_video_create_params import TextToVideoCreateParams as TextToVideoCreateParams from .video_upscale_create_params import VideoUpscaleCreateParams as VideoUpscaleCreateParams from .voice_dubbing_create_params import VoiceDubbingCreateParams as VoiceDubbingCreateParams @@ -61,10 +62,12 @@ from .video_to_audio_create_params import VideoToAudioCreateParams as VideoToAudioCreateParams from .video_to_hdr_create_response import VideoToHdrCreateResponse as VideoToHdrCreateResponse from .video_to_video_create_params import VideoToVideoCreateParams as VideoToVideoCreateParams +from .image_to_vector_create_params import ImageToVectorCreateParams as ImageToVectorCreateParams from .image_upscale_create_response import ImageUpscaleCreateResponse as ImageUpscaleCreateResponse from .recipe_ad_localization_params import RecipeAdLocalizationParams as RecipeAdLocalizationParams from .router_list_requests_response import RouterListRequestsResponse as RouterListRequestsResponse from .text_to_image_create_response import TextToImageCreateResponse as TextToImageCreateResponse +from .text_to_music_create_response import TextToMusicCreateResponse as TextToMusicCreateResponse from .text_to_video_create_response import TextToVideoCreateResponse as TextToVideoCreateResponse from .video_upscale_create_response import VideoUpscaleCreateResponse as VideoUpscaleCreateResponse from .voice_dubbing_create_response import VoiceDubbingCreateResponse as VoiceDubbingCreateResponse @@ -78,6 +81,7 @@ from .video_to_audio_create_response import VideoToAudioCreateResponse as VideoToAudioCreateResponse from .video_to_video_create_response import VideoToVideoCreateResponse as VideoToVideoCreateResponse from .avatar_conversation_list_params import AvatarConversationListParams as AvatarConversationListParams +from .image_to_vector_create_response import ImageToVectorCreateResponse as ImageToVectorCreateResponse from .recipe_ad_localization_response import RecipeAdLocalizationResponse as RecipeAdLocalizationResponse from .voice_isolation_create_response import VoiceIsolationCreateResponse as VoiceIsolationCreateResponse from .realtime_session_create_response import RealtimeSessionCreateResponse as RealtimeSessionCreateResponse diff --git a/src/runwayml/types/image_to_vector_create_params.py b/src/runwayml/types/image_to_vector_create_params.py new file mode 100644 index 0000000..1edbe5d --- /dev/null +++ b/src/runwayml/types/image_to_vector_create_params.py @@ -0,0 +1,23 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from __future__ import annotations + +from typing_extensions import Literal, Required, Annotated, TypedDict + +from .._utils import PropertyInfo + +__all__ = ["ImageToVectorCreateParams"] + + +class ImageToVectorCreateParams(TypedDict, total=False): + image_uri: Required[Annotated[str, PropertyInfo(alias="imageUri")]] + """A HTTPS URL, Runway upload URI, or base64 data URI (e.g. + + `data:image/png;base64,...`, up to 5MB) containing an encoded image. See + [our docs](/assets/inputs#images) on image inputs for more information. + """ + + model: Required[Literal["ideogram_vector"]] + + vectorization_mode: Annotated[Literal["simple", "default"], PropertyInfo(alias="vectorizationMode")] + """Use simple for fewer shapes, or default to retain more detail.""" diff --git a/src/runwayml/types/image_to_vector_create_response.py b/src/runwayml/types/image_to_vector_create_response.py new file mode 100644 index 0000000..24330e8 --- /dev/null +++ b/src/runwayml/types/image_to_vector_create_response.py @@ -0,0 +1,28 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from pydantic import Field as FieldInfo + +from .._models import BaseModel + +__all__ = ["ImageToVectorCreateResponse", "EstimatedCost"] + + +class EstimatedCost(BaseModel): + """The maximum credits this task may charge. + + The final amount may be lower after the task completes. + """ + + credits: float + """Estimated cost of the generation in credits.""" + + +class ImageToVectorCreateResponse(BaseModel): + id: str + """The ID of the task that was created. Use this to retrieve the task later.""" + + estimated_cost: EstimatedCost = FieldInfo(alias="estimatedCost") + """The maximum credits this task may charge. + + The final amount may be lower after the task completes. + """ diff --git a/src/runwayml/types/text_to_music_create_params.py b/src/runwayml/types/text_to_music_create_params.py new file mode 100644 index 0000000..041281b --- /dev/null +++ b/src/runwayml/types/text_to_music_create_params.py @@ -0,0 +1,31 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from __future__ import annotations + +from typing_extensions import Literal, Required, Annotated, TypedDict + +from .._utils import PropertyInfo + +__all__ = ["TextToMusicCreateParams"] + + +class TextToMusicCreateParams(TypedDict, total=False): + model: Required[Literal["eleven_music_v2_5"]] + + prompt_text: Required[Annotated[str, PropertyInfo(alias="promptText")]] + """ + A description of the track to generate, such as its genre, mood, instruments, + and vocals. Prompts that name specific artists or songs are rejected. + """ + + duration: int + """The length of the track in whole seconds. + + You are billed for the requested length. + """ + + instrumental: bool + """When true, the track has no vocals. + + When omitted, the model decides from the prompt. + """ diff --git a/src/runwayml/types/text_to_music_create_response.py b/src/runwayml/types/text_to_music_create_response.py new file mode 100644 index 0000000..8f67bfd --- /dev/null +++ b/src/runwayml/types/text_to_music_create_response.py @@ -0,0 +1,28 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from pydantic import Field as FieldInfo + +from .._models import BaseModel + +__all__ = ["TextToMusicCreateResponse", "EstimatedCost"] + + +class EstimatedCost(BaseModel): + """The maximum credits this task may charge. + + The final amount may be lower after the task completes. + """ + + credits: float + """Estimated cost of the generation in credits.""" + + +class TextToMusicCreateResponse(BaseModel): + id: str + """The ID of the task that was created. Use this to retrieve the task later.""" + + estimated_cost: EstimatedCost = FieldInfo(alias="estimatedCost") + """The maximum credits this task may charge. + + The final amount may be lower after the task completes. + """ diff --git a/tests/api_resources/test_image_to_vector.py b/tests/api_resources/test_image_to_vector.py new file mode 100644 index 0000000..8ad5d39 --- /dev/null +++ b/tests/api_resources/test_image_to_vector.py @@ -0,0 +1,110 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from __future__ import annotations + +import os +from typing import Any, cast + +import pytest + +from runwayml import RunwayML, AsyncRunwayML +from tests.utils import assert_matches_type +from runwayml.types import ImageToVectorCreateResponse + +base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010") + + +class TestImageToVector: + parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"]) + + @parametrize + def test_method_create(self, client: RunwayML) -> None: + image_to_vector = client.image_to_vector.create( + image_uri="https://example.com/image.jpg", + model="ideogram_vector", + ) + assert_matches_type(ImageToVectorCreateResponse, image_to_vector, path=["response"]) + + @parametrize + def test_method_create_with_all_params(self, client: RunwayML) -> None: + image_to_vector = client.image_to_vector.create( + image_uri="https://example.com/image.jpg", + model="ideogram_vector", + vectorization_mode="simple", + ) + assert_matches_type(ImageToVectorCreateResponse, image_to_vector, path=["response"]) + + @parametrize + def test_raw_response_create(self, client: RunwayML) -> None: + response = client.image_to_vector.with_raw_response.create( + image_uri="https://example.com/image.jpg", + model="ideogram_vector", + ) + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + image_to_vector = response.parse() + assert_matches_type(ImageToVectorCreateResponse, image_to_vector, path=["response"]) + + @parametrize + def test_streaming_response_create(self, client: RunwayML) -> None: + with client.image_to_vector.with_streaming_response.create( + image_uri="https://example.com/image.jpg", + model="ideogram_vector", + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + image_to_vector = response.parse() + assert_matches_type(ImageToVectorCreateResponse, image_to_vector, path=["response"]) + + assert cast(Any, response.is_closed) is True + + +class TestAsyncImageToVector: + parametrize = pytest.mark.parametrize( + "async_client", [False, True, {"http_client": "aiohttp"}], indirect=True, ids=["loose", "strict", "aiohttp"] + ) + + @parametrize + async def test_method_create(self, async_client: AsyncRunwayML) -> None: + image_to_vector = await async_client.image_to_vector.create( + image_uri="https://example.com/image.jpg", + model="ideogram_vector", + ) + assert_matches_type(ImageToVectorCreateResponse, image_to_vector, path=["response"]) + + @parametrize + async def test_method_create_with_all_params(self, async_client: AsyncRunwayML) -> None: + image_to_vector = await async_client.image_to_vector.create( + image_uri="https://example.com/image.jpg", + model="ideogram_vector", + vectorization_mode="simple", + ) + assert_matches_type(ImageToVectorCreateResponse, image_to_vector, path=["response"]) + + @parametrize + async def test_raw_response_create(self, async_client: AsyncRunwayML) -> None: + response = await async_client.image_to_vector.with_raw_response.create( + image_uri="https://example.com/image.jpg", + model="ideogram_vector", + ) + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + image_to_vector = await response.parse() + assert_matches_type(ImageToVectorCreateResponse, image_to_vector, path=["response"]) + + @parametrize + async def test_streaming_response_create(self, async_client: AsyncRunwayML) -> None: + async with async_client.image_to_vector.with_streaming_response.create( + image_uri="https://example.com/image.jpg", + model="ideogram_vector", + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + image_to_vector = await response.parse() + assert_matches_type(ImageToVectorCreateResponse, image_to_vector, path=["response"]) + + assert cast(Any, response.is_closed) is True diff --git a/tests/api_resources/test_text_to_music.py b/tests/api_resources/test_text_to_music.py new file mode 100644 index 0000000..940a756 --- /dev/null +++ b/tests/api_resources/test_text_to_music.py @@ -0,0 +1,112 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from __future__ import annotations + +import os +from typing import Any, cast + +import pytest + +from runwayml import RunwayML, AsyncRunwayML +from tests.utils import assert_matches_type +from runwayml.types import TextToMusicCreateResponse + +base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010") + + +class TestTextToMusic: + parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"]) + + @parametrize + def test_method_create(self, client: RunwayML) -> None: + text_to_music = client.text_to_music.create( + model="eleven_music_v2_5", + prompt_text="x", + ) + assert_matches_type(TextToMusicCreateResponse, text_to_music, path=["response"]) + + @parametrize + def test_method_create_with_all_params(self, client: RunwayML) -> None: + text_to_music = client.text_to_music.create( + model="eleven_music_v2_5", + prompt_text="x", + duration=3, + instrumental=True, + ) + assert_matches_type(TextToMusicCreateResponse, text_to_music, path=["response"]) + + @parametrize + def test_raw_response_create(self, client: RunwayML) -> None: + response = client.text_to_music.with_raw_response.create( + model="eleven_music_v2_5", + prompt_text="x", + ) + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + text_to_music = response.parse() + assert_matches_type(TextToMusicCreateResponse, text_to_music, path=["response"]) + + @parametrize + def test_streaming_response_create(self, client: RunwayML) -> None: + with client.text_to_music.with_streaming_response.create( + model="eleven_music_v2_5", + prompt_text="x", + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + text_to_music = response.parse() + assert_matches_type(TextToMusicCreateResponse, text_to_music, path=["response"]) + + assert cast(Any, response.is_closed) is True + + +class TestAsyncTextToMusic: + parametrize = pytest.mark.parametrize( + "async_client", [False, True, {"http_client": "aiohttp"}], indirect=True, ids=["loose", "strict", "aiohttp"] + ) + + @parametrize + async def test_method_create(self, async_client: AsyncRunwayML) -> None: + text_to_music = await async_client.text_to_music.create( + model="eleven_music_v2_5", + prompt_text="x", + ) + assert_matches_type(TextToMusicCreateResponse, text_to_music, path=["response"]) + + @parametrize + async def test_method_create_with_all_params(self, async_client: AsyncRunwayML) -> None: + text_to_music = await async_client.text_to_music.create( + model="eleven_music_v2_5", + prompt_text="x", + duration=3, + instrumental=True, + ) + assert_matches_type(TextToMusicCreateResponse, text_to_music, path=["response"]) + + @parametrize + async def test_raw_response_create(self, async_client: AsyncRunwayML) -> None: + response = await async_client.text_to_music.with_raw_response.create( + model="eleven_music_v2_5", + prompt_text="x", + ) + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + text_to_music = await response.parse() + assert_matches_type(TextToMusicCreateResponse, text_to_music, path=["response"]) + + @parametrize + async def test_streaming_response_create(self, async_client: AsyncRunwayML) -> None: + async with async_client.text_to_music.with_streaming_response.create( + model="eleven_music_v2_5", + prompt_text="x", + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + text_to_music = await response.parse() + assert_matches_type(TextToMusicCreateResponse, text_to_music, path=["response"]) + + assert cast(Any, response.is_closed) is True diff --git a/tests/test_vector_music_polling.py b/tests/test_vector_music_polling.py new file mode 100644 index 0000000..c6df435 --- /dev/null +++ b/tests/test_vector_music_polling.py @@ -0,0 +1,93 @@ +from __future__ import annotations + +import json +from unittest.mock import AsyncMock, patch + +import httpx +import pytest + +from runwayml import RunwayML, AsyncRunwayML + + +@pytest.mark.parametrize("resource", ["image_to_vector", "text_to_music"]) +def test_new_resources_wait_for_created_task(resource: str) -> None: + paths: list[str] = [] + request_bodies: list[dict[str, object]] = [] + + def handler(request: httpx.Request) -> httpx.Response: + paths.append(request.url.path) + if request.method == "POST": + request_bodies.append(json.loads(request.read())) + return httpx.Response(200, json={"id": "task-1", "estimatedCost": {"credits": 2}}) + return httpx.Response( + 200, + json={ + "id": "task-1", + "createdAt": "2026-01-01T00:00:00Z", + "status": "SUCCEEDED", + "output": ["https://example.com/output"], + "cost": {"credits": 2}, + }, + ) + + with RunwayML(api_key="test", http_client=httpx.Client(transport=httpx.MockTransport(handler))) as client: + if resource == "image_to_vector": + response = client.image_to_vector.create(model="ideogram_vector", image_uri="https://example.com/input.png") + else: + response = client.text_to_music.create(model="eleven_music_v2_5", prompt_text="instrumental") + assert response.estimated_cost.credits == 2 + with patch("runwayml.lib.polling.time.sleep"): + result = response.wait_for_task_output() + assert result.status == "SUCCEEDED" + assert result.output == ["https://example.com/output"] + assert paths == [f"/v1/{resource}", "/v1/tasks/task-1"] + expected_body = ( + {"model": "ideogram_vector", "imageUri": "https://example.com/input.png"} + if resource == "image_to_vector" + else {"model": "eleven_music_v2_5", "promptText": "instrumental"} + ) + assert request_bodies == [expected_body] + + +@pytest.mark.parametrize("resource", ["image_to_vector", "text_to_music"]) +async def test_async_new_resources_wait_for_created_task(resource: str) -> None: + paths: list[str] = [] + request_bodies: list[dict[str, object]] = [] + + def handler(request: httpx.Request) -> httpx.Response: + paths.append(request.url.path) + if request.method == "POST": + request_bodies.append(json.loads(request.read())) + return httpx.Response(200, json={"id": "task-1", "estimatedCost": {"credits": 2}}) + return httpx.Response( + 200, + json={ + "id": "task-1", + "createdAt": "2026-01-01T00:00:00Z", + "status": "SUCCEEDED", + "output": ["https://example.com/output"], + "cost": {"credits": 2}, + }, + ) + + async with AsyncRunwayML( + api_key="test", http_client=httpx.AsyncClient(transport=httpx.MockTransport(handler)) + ) as client: + if resource == "image_to_vector": + response = await client.image_to_vector.create( + model="ideogram_vector", image_uri="https://example.com/input.png" + ) + else: + response = await client.text_to_music.create(model="eleven_music_v2_5", prompt_text="instrumental") + assert response.estimated_cost.credits == 2 + with patch("runwayml.lib.polling.anyio.sleep", new_callable=AsyncMock): + result = await response.wait_for_task_output() + assert result.status == "SUCCEEDED" + assert result.output == ["https://example.com/output"] + assert paths == [f"/v1/{resource}", "/v1/tasks/task-1"] + expected_body = ( + {"model": "ideogram_vector", "imageUri": "https://example.com/input.png"} + if resource == "image_to_vector" + else {"model": "eleven_music_v2_5", "promptText": "instrumental"} + ) + assert request_bodies == [expected_body]