Server Events
Learn about different events that can be sent to a Server URL.
All messages sent to your Server URL will be POST
requests with the following body:
They include the type of message, the call object, and any other properties that are relevant to the message type. Below are the different types of messages that can be sent to your Server URL.
Function Calling
Vapi fully supports OpenAI’s function calling API, so you can have assistants ping your server to perform actions like sending emails, retrieve information, and more.
With each response, the assistant will automatically determine what functions to call based on the directions provided in the system message in messages
. Here’s an example of what the assistant might look like:
Once a function is triggered, the assistant will send a message to your Server URL with the following body:
Your server should respond with a JSON object containing the function’s response, like so:
Or if it’s an object:
The result will be appended to the conversation, and the assistant will decide what to do with the response based on its system prompt.
If you don’t need to return a response, you can use the async: true
parameter in your assitant’s
function configuration. This will prevent the assistant from waiting for a response from your
server.
Retrieving Assistants
For inbound phone calls, you may want to specify the assistant based on the caller’s phone number. If a PhoneNumber doesn’t have an assistantId
, Vapi will attempt to retrieve the assistant from your server.
Your server should respond with a JSON object containing the assistant, like so:
If you’d like to play an error message instead, you can respond with:
Call Status Updates
During the call, the assistant will make multiple POST
requests to the Server URL with the following body:
in-progress
: The call has started. -forwarding
: The call is about to be forwarded toforwardingPhoneNumber
. -ended
: The call has ended.
End of Call Report
When a call ends, the assistant will make a POST
request to the Server URL with the following body:
endedReason
can be any of the options defined on the Call Object.
Hang Notifications
Whenever the assistant fails to respond for 5+ seconds, the assistant will make a POST
requests to the Server URL with the following body:
You can use this to display an error message to the user, or to send a notification to your team.