Kotlin SDK
Agents Platform SDK: deploy customized, interactive voice agents in minutes for Android apps.
Refer to the Agents Platform overview for an explanation of how Agents Platform works.
Installation
Add the ElevenLabs SDK to your Android project by including the following dependency in your app-level build.gradle
file:
An example Android app using this SDK can be found here
Requirements
- Android API level 21 (Android 5.0) or higher
- Internet permission for API calls
- Microphone permission for voice input
- Network security configuration for HTTPS calls
Setup
Manifest Configuration
Add the necessary permissions to your AndroidManifest.xml
:
Runtime Permissions
For Android 6.0 (API level 23) and higher, you must request microphone permission at runtime:
Network Security Configuration
For apps targeting Android 9 (API level 28) or higher, ensure your network security configuration allows clear text traffic if needed:
Usage
Initialize the ElevenLabs SDK in your Application
class or main activity:
Start a conversation session with either:
- Public agent: pass
agentId
- Private agent: pass
conversationToken
provisioned from your backend (never expose your API key to the client).
Note that Agents Platform requires microphone access. Consider explaining and requesting permissions in your app’s UI before the conversation starts, especially on Android 6.0+ where runtime permissions are required.
If a tool is configured with expects_response=false
on the server, return null
from execute
to skip sending a tool result back to the agent.
Public vs Private Agents
- Public agents (no auth): Initialize with
agentId
inConversationConfig
. The SDK requests a conversation token from ElevenLabs without needing an API key on device. - Private agents (auth): Initialize with
conversationToken
inConversationConfig
. Your server requests a conversation token from ElevenLabs using your ElevenLabs API key.
Client Tools
Register client tools to allow the agent to call local capabilities on the device.
When the agent issues a client_tool_call
, the SDK executes the matching tool and responds with a client_tool_result
. If the tool is not registered, onUnhandledClientToolCall
is invoked and a failure result is returned to the agent (if a response is expected).
Callbacks Overview
- onConnect - Called when the WebRTC connection is established. Returns the conversation ID.
- onMessage - Called when a new message is received. These can be tentative or final transcriptions of user voice, replies produced by LLM, or debug messages. Provides source (
"ai"
or"user"
) and raw JSON message. - onModeChange - Called when the conversation mode changes. This is useful for indicating whether the agent is speaking (
"speaking"
) or listening ("listening"
). - onStatusChange - Called when the conversation status changes (
"connected"
,"connecting"
, or"disconnected"
). - onCanSendFeedbackChange - Called when the ability to send feedback changes. Enables/disables feedback buttons.
- onUnhandledClientToolCall - Called when the agent requests a client tool that is not registered on the device.
- onVadScore - Called when the voice activity detection score changes. Range from 0 to 1 where higher values indicate higher confidence of speech.
Not all client events are enabled by default for an agent. If you have enabled a callback but aren’t seeing events come through, ensure that your ElevenLabs agent has the corresponding event enabled. You can do this in the “Advanced” tab of the agent settings in the ElevenLabs dashboard.
Methods
startSession
The startSession
method initiates the WebRTC connection and starts using the microphone to communicate with the ElevenLabs Agents agent.
Public agents
For public agents (i.e. agents that don’t have authentication enabled), only the agentId
is required. The Agent ID can be acquired through the ElevenLabs UI.
Private agents
For private agents, you must pass in a conversationToken
obtained from the ElevenLabs API. Generating this token requires an ElevenLabs API key.
conversationToken
is valid for 10 minutes.Then, pass the token to the startSession
method. Note that only the conversationToken
is required for private agents.
You can optionally pass a user ID to identify the user in the conversation. This can be your own customer identifier. This will be included in the conversation initiation data sent to the server.
endSession
A method to manually end the conversation. The method will disconnect and end the conversation.
sendUserMessage
Send a text message to the agent during an active conversation. This will trigger a response from the agent.
sendContextualUpdate
Sends contextual information to the agent that won’t trigger a response.
sendFeedback
Provide feedback on the conversation quality. This helps improve the agent’s performance. Use onCanSendFeedbackChange
to enable your thumbs up/down UI when feedback is allowed.
sendUserActivity
Notifies the agent about user activity to prevent interruptions. Useful for when the user is actively using the app and the agent should pause speaking, i.e. when the user is typing in a chat.
The agent will pause speaking for ~2 seconds after receiving this signal.
getId
Get the conversation ID.
Mute/ Unmute
Observe session.isMuted
to update the UI label between “Mute” and “Unmute”.
Properties
status
Get the current status of the conversation.
ProGuard / R8
If you shrink/obfuscate, ensure Gson models and LiveKit are kept. Example rules (adjust as needed):
Troubleshooting
- Ensure microphone permission is granted at runtime
- If reconnect hangs, verify your app calls
session.endSession()
and that you start a new session instance before reconnecting - For emulators, verify audio input/output routes are working; physical devices tend to behave more reliably
Example Implementation
For an example implementation, see the example app in the ElevenLabs Android SDK repository. The app demonstrates:
- One‑tap connect/disconnect
- Speaking/listening indicator
- Feedback buttons with UI enable/disable
- Typing indicator via
sendUserActivity()
- Contextual and user messages from an input
- Microphone mute/unmute button