Skip to content

Commit 68daed5

Browse files
authored
Merge pull request #41 from elevenlabs/angelo/envs-support
Add environment parameter support
2 parents f27c265 + 010913c commit 68daed5

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

elevenlabs-sdk/src/main/java/io/elevenlabs/ConversationClientImpl.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ internal object ConversationClientImpl {
4242
val tokenResponse = tokenService.fetchPublicAgentToken(
4343
config.agentId!!,
4444
config.overrides?.client?.source ?: "android_sdk",
45-
config.overrides?.client?.version ?: BuildConfig.SDK_VERSION
45+
config.overrides?.client?.version ?: BuildConfig.SDK_VERSION,
46+
config.environment
4647
)
4748
config.copy(conversationToken = tokenResponse.token, agentId = null)
4849
} else {

elevenlabs-sdk/src/main/java/io/elevenlabs/ConversationConfig.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import io.elevenlabs.models.DisconnectionDetails
2727
* @param audioInputSampleRate Sample rate for audio recording in Hz (default: 48000 for high quality)
2828
* @param apiEndpoint Base URL for ElevenLabs API (default: "https://api.elevenlabs.io")
2929
* @param websocketUrl WebSocket URL for LiveKit WebRTC connection (default: "wss://livekit.rtc.elevenlabs.io")
30+
* @param environment Optional environment name for the agent (defaults to "production" on the server)
3031
*/
3132
data class ConversationConfig(
3233
val agentId: String? = null,
@@ -36,6 +37,7 @@ data class ConversationConfig(
3637
val audioInputSampleRate: Int = 48000,
3738
val apiEndpoint: String = "https://api.elevenlabs.io",
3839
val websocketUrl: String = "wss://livekit.rtc.elevenlabs.io",
40+
val environment: String? = null,
3941
val overrides: Overrides? = null,
4042
val customLlmExtraBody: Map<String, Any>? = null,
4143
val dynamicVariables: Map<String, Any>? = null,

elevenlabs-sdk/src/main/java/io/elevenlabs/network/TokenService.kt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,12 @@ class TokenService(
2727
* @param agentId The ID of the public agent to get a token for
2828
* @param source Optional source identifier (defaults to "android_sdk")
2929
* @param version Optional version string (defaults to SDK version)
30+
* @param environment Optional environment name (defaults to "production" on the server)
3031
* @return TokenResponse containing the token and connection details
3132
* @throws TokenServiceException if the request fails or returns an error
3233
*/
33-
suspend fun fetchPublicAgentToken(agentId: String, source: String, version: String): TokenResponse = withContext(Dispatchers.IO) {
34-
val url = buildTokenUrl(agentId, source, version)
34+
suspend fun fetchPublicAgentToken(agentId: String, source: String, version: String, environment: String? = null): TokenResponse = withContext(Dispatchers.IO) {
35+
val url = buildTokenUrl(agentId, source, version, environment)
3536

3637
val request = Request.Builder()
3738
.url(url)
@@ -69,10 +70,13 @@ class TokenService(
6970
* Build the URL for fetching conversation tokens
7071
*
7172
* @param agentId The agent ID to include in the request
73+
* @param environment Optional environment name
7274
* @return Complete URL for the token request
7375
*/
74-
private fun buildTokenUrl(agentId: String, source: String, version: String): String {
75-
return "$baseUrl/v1/convai/conversation/token?agent_id=$agentId&source=$source&version=$version"
76+
private fun buildTokenUrl(agentId: String, source: String, version: String, environment: String? = null): String {
77+
var url = "$baseUrl/v1/convai/conversation/token?agent_id=$agentId&source=$source&version=$version"
78+
environment?.let { url += "&environment=$it" }
79+
return url
7680
}
7781
}
7882

0 commit comments

Comments
 (0)