gigo1980
03/09/2025, 6:59 PMShubham Bajaj
03/11/2025, 12:40 PMFUNCTION_TOOL
as your tool type
2. **Function Definition**: Define the JSON schema for your API using OpenAIFunction structure
Here's how you would define your appointment slots tool:
json
{
"type": "function",
"async": false,
"function": {
"name": "get_available_appointment_slots",
"description": "Retrieves a list of available appointment slots from the calendar",
"parameters": {
"type": "object",
"properties": {
"start_date": {
"type": "string",
"description": "Start date for appointment search in YYYY-MM-DD format"
},
"end_date": {
"type": "string",
"description": "End date for appointment search in YYYY-MM-DD format"
},
"timezone": {
"type": "string",
"description": "Timezone for the appointment search (e.g., Europe/Berlin)",
"default": "Europe/Berlin"
}
},
"required": ["start_date", "end_date"]
}
},
"server": {
"url": "https://your-api-endpoint.com/get-slots",
"method": "POST"
},
"messages": [
{
"type": "request-start",
"message": "Let me check the available appointment slots for you."
},
{
"type": "request-complete",
"message": "I've found several available appointment slots."
},
{
"type": "request-failed",
"message": "I'm sorry, I couldn't retrieve the appointment slots at this time."
}
]
}
### 2. Response Structure
For handling the response from your API, VAPI will automatically process the JSON response data. Your API should return a response in the format similar to the example you provided:
json
{
"results": [
{
"toolCallId": "call_test123456",
"result": "I've found several available appointment slots."
}
]
}
## Implementation Steps
1. **Create the Tool in VAPI Dashboard**:
- Go to the Tools section
- Create a new custom tool (Function Tool)
- Define the schema based on the examples above
- Set your API endpoint URL in the server configuration
2. **Implement Your API Endpoint**:
- Create an API that accepts the parameters defined in your schema
- Return the response in a structured format as shown above
- Ensure your API handles errors gracefully
3. **Test Your Tool**:
- Use the VAPI testing interface to verify your tool works
- Check that the response is properly structured and can be used in conversations
## Best Practices
1. **Keep Your Schema Simple**:
- Define only the fields you need
- Use clear descriptions for each parameter
2. **Structure Your Response for Conversation**:
- Format dates and times in a natural language friendly way
- Group related data for easier reference in conversations
- Include summary information (total slots, date ranges, etc.)
3. **Error Handling**:
- Provide meaningful error messages that can be communicated to users
- Include fallback options when appropriate
By following these guidelines, you'll be able to integrate your appointment slots API into VAPI conversations, allowing the AI to retrieve and discuss available appointment times with users effectively.