Transport states
The client exposes astate string that tracks where you are in the lifecycle. States progress in order:
| State | What it means |
|---|---|
idle | No connection attempt has started |
authenticating | startBot() called; waiting for your server to start the bot |
authenticated | Server responded; bot is starting |
connecting | Transport is establishing the WebRTC/WebSocket connection |
connected | Transport is connected; bot pipeline is initializing |
ready | Bot pipeline is running and ready to receive audio/messages |
disconnecting | Disconnect in progress |
disconnected | Session has ended |
ready state is the one that matters most — it’s the gate before which you should not send messages or expect audio. The connected state means the transport is up but the bot’s pipeline may still be warming up.
Starting a session
There are three ways to start a session, depending on your architecture.Option 1: startBotAndConnect() (recommended)
The most common pattern. Calls your server endpoint to start the bot, then connects the transport with the credentials returned by your server:
Option 2: connect() with direct params
Pass connection parameters directly — useful when you’ve already obtained them out of band, or with SmallWebRTC where the transport URL is known at build time:
Option 3: startBot() + connect() separately
Gives you explicit control over each phase — useful if you need to inspect the server response before connecting:
ready. Wrap them in try/catch to handle startup errors.
Waiting for ready
await client.connect(...) (and startBotAndConnect) resolves only once the bot sends its BotReady signal, meaning the pipeline is fully initialized. You don’t need to poll or listen for a separate event — the promise resolves at the right time.
If you prefer event-driven code, or you call connect() without await:
Ending a session
Client-initiated disconnect
Calldisconnect() to end the session from the client side. The bot will typically shut down when the client disconnects:
Bot-initiated disconnect
The bot can end the session on its own — due to a pipeline error, session timeout, or intentional shutdown. By default, the client disconnects automatically when the bot disconnects. To keep the client connected after the bot disconnects, setdisconnectOnBotDisconnect: false in the constructor:
BotDisconnected to update your UI when this happens:
After a bot disconnect, you can call connect() again to start a new session.
Error handling
Two distinct error signals: Startup errors — thrown byconnect() / startBotAndConnect() if the server can’t be reached, credentials are invalid, or the transport can’t establish a connection:
fatal boolean: if true, the bot has already disconnected and the client will clean up automatically:
Reconnecting
The client does not automatically reconnect. After a disconnect (whether client-initiated, bot-initiated, or due to a fatal error), you need to callstartBotAndConnect() or connect() again to start a new session. The same PipecatClient instance can be reused.