Overview
ThunderPhone runs voice agents that handle speech recognition, the language model, the voice, and turn-taking in a single service. Use the ThunderPhone plugin to run a ThunderPhone voice agent as the realtime model in an AgentSession, while LiveKit handles the room, transport, and telephony.
Installation
Install the ThunderPhone plugin:
uv add "livekit-agents[thunderphone]~=1.8"
Authentication
The ThunderPhone plugin requires a secret API key that starts with sk_live_. To create one, see ThunderPhone's API keys guide . Set THUNDERPHONE_API_KEY as a variable in your .env file:
THUNDERPHONE_API_KEY=<your-thunderphone-api-key>
Usage
Use ThunderPhone in an AgentSession. For example, you can use it in the Voice AI quickstart.
A ThunderPhone session runs either a saved agent that you configure on ThunderPhone, or an inline session that you configure from your LiveKit agent.
Saved agent
Pass the ID of a saved ThunderPhone agent with agent_id. The saved agent's prompt, voice, engine, languages, tools, and greeting come from ThunderPhone. The plugin doesn't send your LiveKit agent's instructions or tools.
from livekit.agents import AgentSessionfrom livekit.plugins import thunderphonesession = AgentSession(llm=thunderphone.RealtimeModel(agent_id=12),)
Inline session
Omit agent_id and choose an engine with model and a voice with voice. Instructions and tools come from your LiveKit agent, and function tools run in your agent.
from livekit.agents import AgentSessionfrom livekit.plugins import thunderphonesession = AgentSession(llm=thunderphone.RealtimeModel(model="bolt", voice="olivia"),)
ThunderPhone fixes an inline session's instructions and tools when the call starts. If your agent hands off to an agent with different instructions or tools, the plugin ends the ThunderPhone call and starts a new one with the new configuration. With a saved agent, handoffs keep the same call.
Parameters
This section describes some of the available parameters. For a complete reference of all available parameters, see the plugin reference.
agent_idint | strID of a saved ThunderPhone agent. You can't combine it with the model or voice parameter. The saved agent sets its own engine and voice.
modelstrEngine to use for an inline session.
Valid values are: spark, bolt, storm.
voicestrThunderPhone voice for an inline session. For available voices, see ThunderPhone's voice library .
languagestrPrimary language hint for an inline session, such as es. For available languages, see ThunderPhone's supported languages .
caller_numberstrPhone number the call came from, when the session handles a phone call. ThunderPhone shows it as the "from" number in its call history.
callee_numberstrPhone number the caller dialed. ThunderPhone shows it as the "to" number in its call history.
live_transcriptsboolDefault: FalseEnables streaming transcript fragments while the caller is still speaking. ThunderPhone bills live transcripts separately. When set to False, the plugin produces one transcript per caller turn.
Call events
The ThunderPhone realtime session emits events from the ThunderPhone call, in addition to the standard session events:
- The
thunderphone_call_eventevent fires for every ThunderPhone call event, such as a transfer, a keypad press, or ignored speech. - The
thunderphone_call_endedevent fires when the call ends. The session then closes.
Each event handler receives the raw ThunderPhone event. After the session connects, the call_id attribute of the session holds the ThunderPhone call ID. Use it to look up the recording and transcript for the call on ThunderPhone.
To subscribe to call events, use the agent's realtime_llm_session property:
import loggingfrom typing import Anyfrom livekit.agents import Agentfrom livekit.plugins import thunderphonelogger = logging.getLogger("agent")class Assistant(Agent):def __init__(self) -> None:super().__init__(instructions="You are a helpful voice AI assistant.")async def on_enter(self) -> None:rt_session = self.realtime_llm_sessionif not isinstance(rt_session, thunderphone.RealtimeSession):returndef on_call_ended(event: dict[str, Any]) -> None:logger.info("ThunderPhone call %s ended: %s", rt_session.call_id, event)rt_session.on("thunderphone_call_ended", on_call_ended)
Considerations
ThunderPhone has some differences from other realtime model plugins:
- Turn detection runs on ThunderPhone and is always on. You can't turn it off or replace it with LiveKit turn detection.
- Replies always use the instructions and tools set for the session. ThunderPhone ignores per-reply instructions, so a call to
generate_reply()with theinstructionsparameter generates a normal reply, and the plugin logs a warning. - The session doesn't reconnect after the connection closes, because each connection is a separately billed ThunderPhone call.
Additional resources
The following resources provide more information about using ThunderPhone with LiveKit Agents.
Python package
The livekit-plugins-thunderphone package on PyPI.
Plugin reference
Reference for the ThunderPhone realtime model.
GitHub repo
View the source or contribute to the LiveKit ThunderPhone plugin.
ThunderPhone docs
ThunderPhone's guide to using ThunderPhone with LiveKit.
Voice AI quickstart
Get started with LiveKit Agents and ThunderPhone.