Skip to main content

Overview

Pipecat services emit events for connection lifecycle management and service-specific activity. These events let you monitor WebSocket connections, handle errors, and react to service behavior.

Connection Events

WebSocket-based STT and TTS services share a common set of connection events. Not every STT service emits all three: DeepgramSTTService emits only on_connection_error, SpeechmaticsSTTService doesn’t emit on_connected, and SarvamSTTService emits none.

Events Summary

on_connected

Fired when the service’s WebSocket connection is established. This is useful for logging, monitoring connection health, or triggering actions that depend on the service being ready.
Parameters:
Not all STT and TTS services use WebSocket connections. HTTP-based services (e.g., Azure TTS, Google TTS) do not emit connection events.

on_disconnected

Fired when the service’s WebSocket connection is closed, whether due to normal shutdown or an error.
Parameters:

on_connection_error

Fired when a WebSocket connection error occurs. The error is also pushed as an ErrorFrame through the pipeline.
Parameters:
WebSocket-based services automatically reconnect with exponential backoff (3 retries, 4-10s waits by default) when connection errors occur. The on_connection_error event fires for each failed attempt. Configure the wait times via reconnect_backoff_min_wait and reconnect_backoff_max_wait constructor parameters.Reconnection stops once the service can no longer do its job — credentials the provider has already rejected aren’t worth retrying, and exhausting the retries leaves the service unusable too. See Error Handling.

TTS Events

on_tts_request

Fired just before a TTS synthesis request is sent to the service. This is useful for logging, monitoring, or modifying behavior based on what text is being synthesized.
Parameters:

LLM Events

on_function_calls_started

Fired when the LLM starts making function (tool) calls. This event is emitted before the function calls are executed.
Parameters:

on_function_calls_cancelled

Fired after one or more in-progress function calls are cancelled: by an interruption (for calls registered with cancel_on_interruption=True), a function call timeout, the model cancelling a cancellable_by_llm=True call, or cancel_function_calls().
Parameters:

on_completion_timeout

Fired when an LLM completion request times out. This can happen with slow models or large context windows. The OpenAI-based and Google services also push the timeout as an error frame; AnthropicLLMService and AWSBedrockLLMService report it only through this event.
Parameters: