Webhook Request Payload
Layercode sends different webhook event types to your backend. Each request body is JSON. All requests include:type(string): One ofmessage,data,session.start,session.end,session.update.session_id(string): Connection identifier for this session. Changes each reconnect.conversation_id(string): Stable conversation identifier.custom_metadata(object, optional): Custom metadata supplied during session authorization. See custom metadata and headers how-to.
custom_headers during session authorization, Layercode appends those headers to every webhook request. See custom metadata and headers how-to.
Additional fields vary by event type, as described below.
message
text(string): Transcribed user text.session_id(string): A unique identifier for the current session.conversation_id(string): A unique identifier for the conversation.turn_id(string): Unique ID for this turn.from_phone_number(string, optional): Caller phone number if Twilio is used.to_phone_number(string, optional): Agent phone number if Twilio is used.
data
Sent when your client emitsclient.response.data to pass structured JSON without interrupting speech.
data(object): The arbitrary JSON payload sent by the client.session_id(string): A unique identifier for the current session.conversation_id(string): A unique identifier for the conversation.turn_id(string): Unique ID for the current turn.from_phone_number(string, optional): Caller phone number if Twilio is used.to_phone_number(string, optional): Agent phone number if Twilio is used.
session.start
Sent when a new session begins and your agent should optionally speak first.session_id(string): A unique identifier for the current session.conversation_id(string): A unique identifier for the conversation.turn_id(string): Unique ID for the assistant welcome turn.from_phone_number(string, optional): Caller phone number if Twilio is used.to_phone_number(string, optional): Agent phone number if Twilio is used.
session.update
Sent when asynchronous session data becomes available (e.g., after a recording completes).session_id(string): A unique identifier for the current session.conversation_id(string): A unique identifier for the conversation.recording_status(string):completedorfailed.recording_url(string, optional): API URL to download WAV whencompleted.recording_duration(number, optional): Duration in seconds.error_message(string, optional): Error details whenfailed.metadata(object): Session metadata originally provided during authorization (if any).from_phone_number(string, optional): Caller phone number if Twilio is used.to_phone_number(string, optional): Agent phone number if Twilio is used.
session.end
Sent when the session finishes. Includes transcript and usage metrics.session_id(string): A unique identifier for the current session.conversation_id(string): A unique identifier for the conversation.agent_id(string): Agent ID.started_at/ended_at(string): ISO timestamps.duration(number|null): Total milliseconds (if available).transcription_duration_seconds(number|null)tts_duration_seconds(number|null)latency(number|null)ip_address(string|null)country_code(string|null)recording_status(string):enabledordisabled(org setting for session recording).transcript(array): Items of{ role: 'user' | 'assistant', text: string, timestamp: number }.from_phone_number(string, optional): Caller phone number if Twilio is used.to_phone_number(string, optional): Agent phone number if Twilio is used.
Webhook Response Events
When Layercode calls your webhook, your handler typically streams back Server-Sent Events (SSE) so the assistant can speak or update the UI. The following event types are recognized. Note: Forresponse.data, you may either include it in an SSE stream, or when responding to the incoming data webhook event type, return it as a regular JSON HTTP response (non‑SSE). All other webhook events should return SSE events.
response.tts
Send spoken content for the assistant turn. Layercode converts the provided text to speech and streams it to the user.response.data
Deliver JSON payloads to the frontend without speaking. Useful for updating dashboards or sending structured data.data webhook event). See docs page: Send JSON data from the client.
response.end
Signal that the assistant has finished generating its reply for the current turn. Always emit this once the turn is complete unless you are issuing aresponse.hangup.
response.hangup
Request that Layercode end the session after finishing playback of the current assistant audio. Provide a farewell in the requiredcontent field. You do not need to send a separate response.end; Layercode will flush remaining audio and end the session automatically.