Implement the custom endpoint
Vapi sends your server a request whenever the assistant needs information from the knowledge base. Your endpoint decides what comes back: a set of documents for the model to read, or a finished answer to speak.
Implementing the Custom Endpoint
Your custom knowledge base server must handle POST requests at the configured URL and return structured responses.
Request Structure
Vapi will send requests to your endpoint with the following structure:
Response Options
Your endpoint can respond in two ways:
Option 1: Return Documents for AI Processing
Return an array of relevant documents that the AI will use to formulate a response:
Option 2: Return Direct Response
Return a complete response that the assistant will speak directly:
Implementation Examples
Here are complete server implementations in different languages:
Advanced Implementation Patterns
Vector Database Integration
For production use, integrate with a proper vector database:
Security and Best Practices
Performance Optimization
Response time is critical: Your endpoint should respond in milliseconds (ideally under ~50ms) for optimal user experience. While Vapi allows up to 10 seconds timeout, slower responses will significantly affect your assistant’s conversational flow and response quality.
Cache frequently requested documents and implement request timeouts to ensure fast response times. Consider using in-memory caches, CDNs, or pre-computed embeddings for faster retrieval.
Error Handling
Always handle errors gracefully and return appropriate HTTP status codes: