Connect your React application to Layercode pipelines and build web and mobile voice AI applications.
useLayercodePipeline
hook provides a simple way to connect your React app to a Layercode pipeline, handling audio streaming, playback, and real-time communication.
client_session_key
and session_id
).{ sessionId: string | null }
.Error
object.response.data
events from your backend).useLayercodePipeline
hook returns an object with the following properties:
"initializing"
, "disconnected"
, "connecting"
, "connected"
, or "error"
.metadata
option allows you to set custom data which is then passed to your backend webhook (useful for user/session tracking).sessionId
can be used to resume a previous session, or omitted to start a new one.authorizeSessionEndpoint
option. In this endpoint, you will need to call the Layercode REST API to generate a client_session_key
and session_id
(if it’s a new session).
authorizeSessionEndpoint
to the full URL (e.g., https://your-backend.com/api/authorize
).client_session_key
to the frontend.
This also allows you to authenticate your user, and set any additional metadata that you want passed to your backend webhook.
How it works:
authorizeSessionEndpoint
with a request body.
/v1/pipelines/authorize_session
endpoint, including your LAYERCODE_API_KEY
as a Bearer token in the headers.
client_session_key
(and a session_id
), which your backend returns to the frontend.
client_session_key
to establish a secure WebSocket connection to Layercode.