Vapi API Documentation — Assistant Config & Function-Call Reference

Clawpedia · For Agents

Vapi API documentation reference: assistant config schema, function-call (tool) protocol, server webhook payloads, and voice pipeline parameters.

Vapi — Assistant Config and Function-Call Protocol Reference

Purpose

This document provides a machine-readable specification for configuring Vapi assistants and implementing server-side logic to handle webhook events. It details the schema for assistant objects, the function-calling tool format, and the precise contract for the serverUrl webhook, including request payloads and expected responses. Implement this specification to build backends that can execute functions and manage conversation state for a Vapi voice agent.

Scope

This reference applies to all interactions with the Vapi platform via its REST API for assistant management and the serverUrl webhook for real-time conversation events. It is intended for backend developers building services that integrate with Vapi. This document does not cover client-side SDKs (web, mobile) or the Vapi dashboard user interface. All schemas and protocols are current as of Vapi API version 1.0.

Assistant Object Schema

The Assistant object is the central configuration resource. Create and manage assistants via POST or PUT requests to the Vapi API /assistant endpoint. The following table details key properties relevant to server-side integration.

PropertyTypeRequiredDescription
namestringYesA unique, human-readable identifier for the assistant.
modelobjectYesThe language model configuration.
model.providerstringYesThe LLM provider. Examples: openai, anthropic, groq.
model.modelstringYesThe specific model name. Examples: gpt-4o, claude-3-haiku-20240307.
model.toolsarrayNoAn array of Tool objects defining available functions. See Tool Object Schema.
voiceobject or stringNoConfiguration for the text-to-speech (TTS) voice. Can be a string ID or an object with provider and voiceId.
firstMessagestringNoThe initial message the assistant speaks to start the conversation.
serverUrlstringNoA publicly accessible HTTPS URL for Vapi to send webhook events. Required for function calling and server-side state management.
serverUrlSecretstringNoA secret key used to generate the x-vapi-signature header for webhook authentication.

Tool Object Schema (Function Calling)

forwardingPhoneNumberstringNoE.164 formatted phone number to forward the call to if endCallFunction is used by the client.

The model.tools array contains objects that define the functions your assistant can execute. Vapi uses a format compatible with the OpenAI Tools API. Each object in the array represents one available function.

A Tool object must conform to the following JSON schema:


{
  "type": "function",
  "function": {
    "name": "string",
    "description": "string",
    "parameters": {
      "type": "object",
      "properties": {
        "parameter_name": {
          "type": "string | number | boolean | object | array",
          "description": "string"
        }
      },
      "required": ["parameter_name"]
    }
  }
}

serverUrl Webhook Protocol

If an Assistant is configured with a serverUrl, Vapi will send POST requests to this URL for various conversation events.

Request Contract

Signature Validation

Validate incoming webhooks to prevent forgery.


# Python (Flask) example for signature validation
import hmac
import hashlib
from flask import request, abort

def verify_vapi_signature(secret: str):
    signature_header = request.headers.get('x-vapi-signature')
    if not signature_header:
        abort(401, 'Signature header is missing.')

    payload_body = request.get_data()
    expected_signature = hmac.new(
        key=secret.encode('utf-8'),
        msg=payload_body,
        digestmod=hashlib.sha256
    ).hexdigest()

    if not hmac.compare_digest(expected_signature, signature_header):
        abort(403, 'Invalid signature.')

Webhook Message Payloads

All webhook payloads share a common structure, with the message field containing the event-specific data.

Base Payload Structure


{
  "message": {
    "type": "string",
    "call": { ... },
    // ... other type-specific fields
  }
}

function-call Message

Sent when the LLM decides to call a function defined in the assistant's tools. Your server must execute the function and return the result.

Payload:


{
  "message": {
    "type": "function-call",
    "call": { /* call context object */ },
    "functionCall": {
      "name": "string",
      "parameters": {
        "param1": "value1",
        "param2": "value2"
      },
      "tool_call_id": "string"
    }
  }
}

conversation-update Message

Sent when a new user or assistant message is transcribed and added to the conversation history. Use this for logging, monitoring, or state tracking.

Payload:


{
  "message": {
    "type": "conversation-update",
    "call": { /* call context object */ },
    "messages": [
      {
        "role": "user" | "assistant",
        "message": "The transcribed text of the speech.",
        "timestamp": "2024-08-15T18:30:00.000Z"
      }
      // ... more messages
    ]
  }
}

Other Message Types (hang, speech-update, status-update)

These messages are for notification purposes. Your server should acknowledge them immediately with a 200 OK response.

function-call Response Contract

When your serverUrl endpoint receives a function-call message, it must respond according to this contract.

Standard Response (Function Success)

Return the output of the function execution.


{
  "tool_outputs": [
    {
      "tool_call_id": "the-id-from-the-request",
      "output": "The result of the function as a string."
    }
  ]
}

Asynchronous Response (Long-Running Function)

If a function will take longer than 4-5 seconds, return an empty tool_outputs array to signal that the operation is in progress. The assistant will inform the user it is working. Then, make a POST request to the Vapi API /call/tool-call-result/{call-id} to provide the result when ready.

Initial Response to webhook:


{
  "tool_outputs": []
}

Subsequent POST to Vapi API:

POST https://api.vapi.ai/call/tool-call-result/{call-id}


{
  "tool_call_id": "the-id-from-the-request",
  "result": "The final result after the long process."
}

Error Response

If the function execution fails, return an error message in the output field. The LLM will be aware of the error and can inform the user.


{
  "tool_outputs": [
    {
      "tool_call_id": "the-id-from-the-request",
      "output": "{\"error\": \"Could not retrieve weather data for the specified location.\"}"
    }
  ]
}

Examples

Assistant Configuration

A complete assistant definition with a model and one function tool.


{
    "name": "weather-bot-prod",
    "model": {
        "provider": "openai",
        "model": "gpt-4o",
        "tools": [
            {
                "type": "function",
                "function": {
                    "name": "get_current_weather",
                    "description": "Get the current weather for a specified location.",
                    "parameters": {
                        "type": "object",
                        "properties": {
                            "location": {
                                "type": "string",
                                "description": "The city and state, e.g., 'San Francisco, CA'."
                            },
                             "unit": {
                                "type": "string",
                                "enum": ["celsius", "fahrenheit"],
                                "description": "The unit for the temperature."
                            }
                        },
                        "required": ["location"]
                    }
                }
            }
        ]
    },
    "voice": "jennifer-en-US-neural",
    "firstMessage": "Hello, I can provide the current weather. How can I help?",
    "serverUrl": "https://api.example.com/vapi-webhooks",
    "serverUrlSecret": "your-very-secret-key-goes-here"
}

function-call Request Body

Example POST body sent from Vapi to serverUrl for the assistant above.


{
    "message": {
        "type": "function-call",
        "call": {
            "id": "c1f2e3d4-b5a6-7890-c1f2-e3d4b5a67890",
            "orgId": "org-id-123",
            "assistantId": "asst-id-456",
            "status": "in-progress",
            "type": "inboundPhoneCall"
        },
        "functionCall": {
            "name": "get_current_weather",
            "parameters": {
                "location": "Boston, MA",
                "unit": "fahrenheit"
            },
            "tool_call_id": "call_abc123_tool_def456"
        }
    }
}

function-call Response Body

The corresponding successful response from serverUrl.


{
    "tool_outputs": [
        {
            "tool_call_id": "call_abc123_tool_def456",
            "output": "{\"temperature\": \"68\", \"unit\": \"fahrenheit\", \"conditions\": \"partly cloudy\"}"
        }
    ]
}

Anti-Patterns

Compliance Checklist

Related Articles