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:

1{
2 "message": {
3 "type": "function-call",
4 "call": { Call Object },
5 ...other message properties
6 }
7}

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:

1{
2 "name": "Ryan's Assistant",
3 "model": {
4 "provider": "openai",
5 "model": "gpt-3.5-turbo",
6 "functions": [
7 {
8 "name": "sendEmail",
9 "description": "Used to send an email to a client.",
10 "parameters": {
11 "type": "object",
12 "properties": {
13 "color": { "type": "string" }
14 }
15 }
16 }
17 ]
18 }
19}

Once a function is triggered, the assistant will send a message to your Server URL with the following body:

1{
2 "message": {
3 "type": "function-call",
4 "call": { Call Object },
5 "functionCall": {
6 "name": "sendEmail",
7 "parameters": "{ \"emailAddress\": \"[email protected]\"}"
8 }
9 }
10}

Your server should respond with a JSON object containing the function’s response, like so:

1{ "result": "Your email has been sent." }

Or if it’s an object:

1{
2 "result": "{ \"message\": \"Your email has been sent.\", \"email\": \"[email protected]\" }"
3}

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.

1{
2 "message": {
3 "type": "assistant-request",
4 "call": { Call Object },
5 }
6}

Your server should respond with a JSON object containing the assistant, like so:

1{
2 "assistant": {
3 "firstMessage": "Hey Ryan, how are you?",
4 "model": {
5 "provider": "openai",
6 "model": "gpt-3.5-turbo",
7 "messages": [
8 {
9 "role": "system",
10 "content": "You're Ryan's assistant..."
11 }
12 ]
13 }
14 }
15}

If you’d like to play an error message instead, you can respond with:

1{ "error": "Sorry, not enough credits on your account, please refill." }

Call Status Updates

During the call, the assistant will make multiple POST requests to the Server URL with the following body:

1{
2 "message": {
3 "type": "status-update",
4 "call": { Call Object },
5 "status": "ended",
6 }
7}
Status Events
  • in-progress: The call has started. - forwarding: The call is about to be forwarded to forwardingPhoneNumber. - 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:

1{
2 "message": {
3 "type": "end-of-call-report",
4 "endedReason": "hangup",
5 "call": { Call Object },
6 "recordingUrl": "https://vapi-public.s3.amazonaws.com/recordings/1234.wav",
7 "summary": "The user picked up the phone then asked about the weather...",
8 "transcript": "AI: How can I help? User: What's the weather? ...",
9 "messages":[
10 {
11 "role": "assistant",
12 "message": "How can I help?",
13 },
14 {
15 "role": "user",
16 "message": "What's the weather?"
17 },
18 ...
19 ]
20 }
21}

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:

1{
2 "message": {
3 "type": "hang",
4 "call": { Call Object },
5 }
6}

You can use this to display an error message to the user, or to send a notification to your team.