Skip to content

Commit 4f5bc06

Browse files
[music] support new params and surfacing song id
1 parent 5c03b50 commit 4f5bc06

File tree

1 file changed

+33
-14
lines changed

1 file changed

+33
-14
lines changed

src/elevenlabs/music_custom.py

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class MultipartResponse:
3030
json: typing.Dict[str, typing.Any] # Contains compositionPlan and songMetadata
3131
audio: bytes
3232
filename: str
33+
song_id: typing.Optional[str] = None
3334

3435

3536
class MusicClient(AutogeneratedMusicClient):
@@ -46,26 +47,35 @@ def compose_detailed( # type: ignore[override]
4647
composition_plan: typing.Optional[MusicPrompt] = OMIT,
4748
music_length_ms: typing.Optional[int] = OMIT,
4849
model_id: typing.Optional[typing.Literal["music_v1"]] = OMIT,
50+
force_instrumental: typing.Optional[bool] = OMIT,
51+
store_for_inpainting: typing.Optional[bool] = OMIT,
52+
with_timestamps: typing.Optional[bool] = OMIT,
53+
sign_with_c_2_pa: typing.Optional[bool] = OMIT,
4954
request_options: typing.Optional[RequestOptions] = None,
5055
) -> MultipartResponse:
5156
"""
5257
Compose a song from a prompt or a composition plan with detailed response parsing.
5358
This method calls the original compose_detailed and then parses the stream response.
5459
55-
Returns a MultipartResponse containing parsed JSON metadata, audio bytes, and filename.
60+
Returns a MultipartResponse containing parsed JSON metadata, audio bytes, filename,
61+
and song_id (if store_for_inpainting was True).
5662
"""
57-
# Call the parent method to get the stream
58-
stream = super().compose_detailed(
63+
# Use the raw client directly to access response headers (for song_id)
64+
with self._raw_client.compose_detailed(
5965
output_format=output_format,
6066
prompt=prompt,
6167
composition_plan=composition_plan,
6268
music_length_ms=music_length_ms,
6369
model_id=model_id,
70+
force_instrumental=force_instrumental,
71+
store_for_inpainting=store_for_inpainting,
72+
with_timestamps=with_timestamps,
73+
sign_with_c_2_pa=sign_with_c_2_pa,
6474
request_options=request_options,
65-
)
66-
67-
# Parse the stream using the parsing method
68-
return self._parse_multipart(stream)
75+
) as r:
76+
result = self._parse_multipart(r.data)
77+
result.song_id = r.headers.get("song-id")
78+
return result
6979

7080
def _parse_multipart(self, stream: typing.Iterator[bytes]) -> MultipartResponse:
7181
"""
@@ -172,26 +182,35 @@ async def compose_detailed( # type: ignore[override]
172182
composition_plan: typing.Optional[MusicPrompt] = OMIT,
173183
music_length_ms: typing.Optional[int] = OMIT,
174184
model_id: typing.Optional[typing.Literal["music_v1"]] = OMIT,
185+
force_instrumental: typing.Optional[bool] = OMIT,
186+
store_for_inpainting: typing.Optional[bool] = OMIT,
187+
with_timestamps: typing.Optional[bool] = OMIT,
188+
sign_with_c_2_pa: typing.Optional[bool] = OMIT,
175189
request_options: typing.Optional[RequestOptions] = None,
176190
) -> MultipartResponse:
177191
"""
178192
Compose a song from a prompt or a composition plan with detailed response parsing.
179193
This method calls the original compose_detailed and then parses the stream response.
180194
181-
Returns a MultipartResponse containing parsed JSON metadata, audio bytes, and filename.
195+
Returns a MultipartResponse containing parsed JSON metadata, audio bytes, filename,
196+
and song_id (if store_for_inpainting was True).
182197
"""
183-
# Call the parent method to get the stream
184-
stream = super().compose_detailed(
198+
# Use the raw client directly to access response headers (for song_id)
199+
async with self._raw_client.compose_detailed(
185200
output_format=output_format,
186201
prompt=prompt,
187202
composition_plan=composition_plan,
188203
music_length_ms=music_length_ms,
189204
model_id=model_id,
205+
force_instrumental=force_instrumental,
206+
store_for_inpainting=store_for_inpainting,
207+
with_timestamps=with_timestamps,
208+
sign_with_c_2_pa=sign_with_c_2_pa,
190209
request_options=request_options,
191-
)
192-
193-
# Parse the stream using the parsing method
194-
return await self._parse_multipart_async(stream)
210+
) as r:
211+
result = await self._parse_multipart_async(r.data)
212+
result.song_id = r.headers.get("song-id")
213+
return result
195214

196215
async def _parse_multipart_async(self, stream: typing.AsyncIterator[bytes]) -> MultipartResponse:
197216
"""

0 commit comments

Comments
 (0)