Skip to content

Commit 37bc9bf

Browse files
AngeloGiaccoclaude
andcommitted
Add environment parameter to conversational AI websocket, signed URL, and token routes
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 8303d37 commit 37bc9bf

File tree

3 files changed

+56
-4
lines changed

3 files changed

+56
-4
lines changed

src/elevenlabs/conversational_ai/conversation.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,7 @@ def __init__(
391391
config: Optional[ConversationInitiationData] = None,
392392
client_tools: Optional[ClientTools] = None,
393393
on_prem_config: Optional[OnPremInitiationData] = None,
394+
environment: Optional[str] = None,
394395
):
395396
self.client = client
396397
self.agent_id = agent_id
@@ -399,6 +400,7 @@ def __init__(
399400
self.config = config or ConversationInitiationData()
400401
self.client_tools = client_tools or ClientTools()
401402
self.on_prem_config = on_prem_config
403+
self.environment = environment
402404

403405
self.client_tools.start()
404406

@@ -418,10 +420,16 @@ def _get_wss_url(self):
418420
# Ensure base URL ends with '/' for proper joining
419421
if not base_ws_url.endswith("/"):
420422
base_ws_url += "/"
421-
return f"{base_ws_url}v1/convai/conversation?agent_id={self.agent_id}&source=python_sdk&version={__version__}"
423+
url = f"{base_ws_url}v1/convai/conversation?agent_id={self.agent_id}&source=python_sdk&version={__version__}"
424+
if self.environment:
425+
url += f"&environment={self.environment}"
426+
return url
422427

423428
def _get_signed_url(self):
424-
response = self.client.conversational_ai.conversations.get_signed_url(agent_id=self.agent_id)
429+
response = self.client.conversational_ai.conversations.get_signed_url(
430+
agent_id=self.agent_id,
431+
environment=self.environment,
432+
)
425433
signed_url = response.signed_url
426434
# Append source and version query parameters to the signed URL
427435
separator = "&" if "?" in signed_url else "?"
@@ -633,6 +641,7 @@ def __init__(
633641
callback_audio_alignment: Optional[Callable[[AudioEventAlignment], None]] = None,
634642
callback_end_session: Optional[Callable] = None,
635643
on_prem_config: Optional[OnPremInitiationData] = None,
644+
environment: Optional[str] = None,
636645
):
637646
"""Conversational AI session.
638647
@@ -654,6 +663,7 @@ def __init__(
654663
callback_user_transcript: Callback for user transcripts.
655664
callback_latency_measurement: Callback for latency measurements (in milliseconds).
656665
callback_audio_alignment: Callback for audio alignment data with character-level timing.
666+
environment: The environment to use. Defaults to "production" on the server.
657667
"""
658668

659669
super().__init__(
@@ -664,6 +674,7 @@ def __init__(
664674
config=config,
665675
client_tools=client_tools,
666676
on_prem_config=on_prem_config,
677+
environment=environment,
667678
)
668679

669680
self.audio_interface = audio_interface
@@ -925,6 +936,7 @@ def __init__(
925936
callback_audio_alignment: Optional[Callable[[AudioEventAlignment], Awaitable[None]]] = None,
926937
callback_end_session: Optional[Callable[[], Awaitable[None]]] = None,
927938
on_prem_config: Optional[OnPremInitiationData] = None,
939+
environment: Optional[str] = None,
928940
):
929941
"""Async Conversational AI session.
930942
@@ -947,6 +959,7 @@ def __init__(
947959
callback_latency_measurement: Async callback for latency measurements (in milliseconds).
948960
callback_audio_alignment: Async callback for audio alignment data with character-level timing.
949961
callback_end_session: Async callback for when session ends.
962+
environment: The environment to use. Defaults to "production" on the server.
950963
"""
951964

952965
super().__init__(
@@ -957,6 +970,7 @@ def __init__(
957970
config=config,
958971
client_tools=client_tools,
959972
on_prem_config=on_prem_config,
973+
environment=environment,
960974
)
961975

962976
self.audio_interface = audio_interface

src/elevenlabs/conversational_ai/conversations/client.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ def get_signed_url(
4848
agent_id: str,
4949
include_conversation_id: typing.Optional[bool] = None,
5050
branch_id: typing.Optional[str] = None,
51+
environment: typing.Optional[str] = None,
5152
request_options: typing.Optional[RequestOptions] = None,
5253
) -> ConversationSignedUrlResponseModel:
5354
"""
@@ -64,6 +65,9 @@ def get_signed_url(
6465
branch_id : typing.Optional[str]
6566
The ID of the branch to use
6667
68+
environment : typing.Optional[str]
69+
The environment to use. Defaults to "production" on the server.
70+
6771
request_options : typing.Optional[RequestOptions]
6872
Request-specific configuration.
6973
@@ -89,6 +93,7 @@ def get_signed_url(
8993
agent_id=agent_id,
9094
include_conversation_id=include_conversation_id,
9195
branch_id=branch_id,
96+
environment=environment,
9297
request_options=request_options,
9398
)
9499
return _response.data
@@ -99,6 +104,7 @@ def get_webrtc_token(
99104
agent_id: str,
100105
participant_name: typing.Optional[str] = None,
101106
branch_id: typing.Optional[str] = None,
107+
environment: typing.Optional[str] = None,
102108
request_options: typing.Optional[RequestOptions] = None,
103109
) -> TokenResponseModel:
104110
"""
@@ -115,6 +121,9 @@ def get_webrtc_token(
115121
branch_id : typing.Optional[str]
116122
The ID of the branch to use
117123
124+
environment : typing.Optional[str]
125+
The environment to use. Defaults to "production" on the server.
126+
118127
request_options : typing.Optional[RequestOptions]
119128
Request-specific configuration.
120129
@@ -137,7 +146,7 @@ def get_webrtc_token(
137146
)
138147
"""
139148
_response = self._raw_client.get_webrtc_token(
140-
agent_id=agent_id, participant_name=participant_name, branch_id=branch_id, request_options=request_options
149+
agent_id=agent_id, participant_name=participant_name, branch_id=branch_id, environment=environment, request_options=request_options
141150
)
142151
return _response.data
143152

@@ -412,6 +421,7 @@ async def get_signed_url(
412421
agent_id: str,
413422
include_conversation_id: typing.Optional[bool] = None,
414423
branch_id: typing.Optional[str] = None,
424+
environment: typing.Optional[str] = None,
415425
request_options: typing.Optional[RequestOptions] = None,
416426
) -> ConversationSignedUrlResponseModel:
417427
"""
@@ -428,6 +438,9 @@ async def get_signed_url(
428438
branch_id : typing.Optional[str]
429439
The ID of the branch to use
430440
441+
environment : typing.Optional[str]
442+
The environment to use. Defaults to "production" on the server.
443+
431444
request_options : typing.Optional[RequestOptions]
432445
Request-specific configuration.
433446
@@ -461,6 +474,7 @@ async def main() -> None:
461474
agent_id=agent_id,
462475
include_conversation_id=include_conversation_id,
463476
branch_id=branch_id,
477+
environment=environment,
464478
request_options=request_options,
465479
)
466480
return _response.data
@@ -471,6 +485,7 @@ async def get_webrtc_token(
471485
agent_id: str,
472486
participant_name: typing.Optional[str] = None,
473487
branch_id: typing.Optional[str] = None,
488+
environment: typing.Optional[str] = None,
474489
request_options: typing.Optional[RequestOptions] = None,
475490
) -> TokenResponseModel:
476491
"""
@@ -487,6 +502,9 @@ async def get_webrtc_token(
487502
branch_id : typing.Optional[str]
488503
The ID of the branch to use
489504
505+
environment : typing.Optional[str]
506+
The environment to use. Defaults to "production" on the server.
507+
490508
request_options : typing.Optional[RequestOptions]
491509
Request-specific configuration.
492510
@@ -517,7 +535,7 @@ async def main() -> None:
517535
asyncio.run(main())
518536
"""
519537
_response = await self._raw_client.get_webrtc_token(
520-
agent_id=agent_id, participant_name=participant_name, branch_id=branch_id, request_options=request_options
538+
agent_id=agent_id, participant_name=participant_name, branch_id=branch_id, environment=environment, request_options=request_options
521539
)
522540
return _response.data
523541

src/elevenlabs/conversational_ai/conversations/raw_client.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ def get_signed_url(
3030
agent_id: str,
3131
include_conversation_id: typing.Optional[bool] = None,
3232
branch_id: typing.Optional[str] = None,
33+
environment: typing.Optional[str] = None,
3334
request_options: typing.Optional[RequestOptions] = None,
3435
) -> HttpResponse[ConversationSignedUrlResponseModel]:
3536
"""
@@ -46,6 +47,9 @@ def get_signed_url(
4647
branch_id : typing.Optional[str]
4748
The ID of the branch to use
4849
50+
environment : typing.Optional[str]
51+
The environment to use. Defaults to "production" on the server.
52+
4953
request_options : typing.Optional[RequestOptions]
5054
Request-specific configuration.
5155
@@ -61,6 +65,7 @@ def get_signed_url(
6165
"agent_id": agent_id,
6266
"include_conversation_id": include_conversation_id,
6367
"branch_id": branch_id,
68+
"environment": environment,
6469
},
6570
request_options=request_options,
6671
)
@@ -96,6 +101,7 @@ def get_webrtc_token(
96101
agent_id: str,
97102
participant_name: typing.Optional[str] = None,
98103
branch_id: typing.Optional[str] = None,
104+
environment: typing.Optional[str] = None,
99105
request_options: typing.Optional[RequestOptions] = None,
100106
) -> HttpResponse[TokenResponseModel]:
101107
"""
@@ -112,6 +118,9 @@ def get_webrtc_token(
112118
branch_id : typing.Optional[str]
113119
The ID of the branch to use
114120
121+
environment : typing.Optional[str]
122+
The environment to use. Defaults to "production" on the server.
123+
115124
request_options : typing.Optional[RequestOptions]
116125
Request-specific configuration.
117126
@@ -127,6 +136,7 @@ def get_webrtc_token(
127136
"agent_id": agent_id,
128137
"participant_name": participant_name,
129138
"branch_id": branch_id,
139+
"environment": environment,
130140
},
131141
request_options=request_options,
132142
)
@@ -419,6 +429,7 @@ async def get_signed_url(
419429
agent_id: str,
420430
include_conversation_id: typing.Optional[bool] = None,
421431
branch_id: typing.Optional[str] = None,
432+
environment: typing.Optional[str] = None,
422433
request_options: typing.Optional[RequestOptions] = None,
423434
) -> AsyncHttpResponse[ConversationSignedUrlResponseModel]:
424435
"""
@@ -435,6 +446,9 @@ async def get_signed_url(
435446
branch_id : typing.Optional[str]
436447
The ID of the branch to use
437448
449+
environment : typing.Optional[str]
450+
The environment to use. Defaults to "production" on the server.
451+
438452
request_options : typing.Optional[RequestOptions]
439453
Request-specific configuration.
440454
@@ -450,6 +464,7 @@ async def get_signed_url(
450464
"agent_id": agent_id,
451465
"include_conversation_id": include_conversation_id,
452466
"branch_id": branch_id,
467+
"environment": environment,
453468
},
454469
request_options=request_options,
455470
)
@@ -485,6 +500,7 @@ async def get_webrtc_token(
485500
agent_id: str,
486501
participant_name: typing.Optional[str] = None,
487502
branch_id: typing.Optional[str] = None,
503+
environment: typing.Optional[str] = None,
488504
request_options: typing.Optional[RequestOptions] = None,
489505
) -> AsyncHttpResponse[TokenResponseModel]:
490506
"""
@@ -501,6 +517,9 @@ async def get_webrtc_token(
501517
branch_id : typing.Optional[str]
502518
The ID of the branch to use
503519
520+
environment : typing.Optional[str]
521+
The environment to use. Defaults to "production" on the server.
522+
504523
request_options : typing.Optional[RequestOptions]
505524
Request-specific configuration.
506525
@@ -516,6 +535,7 @@ async def get_webrtc_token(
516535
"agent_id": agent_id,
517536
"participant_name": participant_name,
518537
"branch_id": branch_id,
538+
"environment": environment,
519539
},
520540
request_options=request_options,
521541
)

0 commit comments

Comments
 (0)