Voice Agent Development on the VAPI Platform VAPI (Voice API) is a developer-focused infrastructure platform for building AI voice agents. Unlike no-code solutions, VAPI provides full stack control: choice of STT provider (Deepgram, AssemblyAI), LLM (GPT-4o, Claude, Llama), TTS (Eleven
Labs, Azure, OpenAI), and transport layer (WebRTC, PSTN, SIP). ### VAPI Agent ArchitecturePhone Call / WebRTC ↓ [VAPI Transport Layer] ↓ [STT: Deepgram / Whisper] ↓ [LLM: GPT-4o / Claude] ←→ [Function Calls / Tools] ↓ [TTS: ElevenLabs / Azure] ↓ Audio Response### Creating an agent via the VAPI API```python
import requests
from typing import Optional
class VAPIAgentBuilder: """Конструктор голосовых агентов через VAPI API"""
def __init__(self, api_key: str):
self.api_key = api_key
self.base_url = "https://api.vapi.ai"
self.headers = {
"Authorization": f"Bearer {api_key}",
"Content-Type": "application/json"
}
def create_assistant(self, name: str,
system_prompt: str,
model: str = "gpt-4o",
voice_provider: str = "elevenlabs",
voice_id: str = "rachel",
tools: Optional[list] = None) -> dict:
"""
Создание голосового ассистента.
tools: функции для вызова во время разговора (получение данных, запись)
"""
assistant_config = {
"name": name,
"model": {
"provider": "openai" if "gpt" in model else "anthropic",
"model": model,
"systemPrompt": system_prompt,
"temperature": 0.7,
},
"voice": {
"provider": voice_provider,
"voiceId": voice_id,
"speed": 1.0,
"stability": 0.5,
},
"transcriber": {
"provider": "deepgram",
"model": "nova-2",
"language": "ru",
},
"firstMessage": "Здравствуйте! Чем могу помочь?",
"endCallMessage": "Спасибо за звонок. До свидания!",
"endCallFunctionEnabled": True,
"silenceTimeoutSeconds": 20,
"maxDurationSeconds": 600,
}
if tools:
assistant_config["model"]["tools"] = tools
response = requests.post(
f"{self.base_url}/assistant",
json=assistant_config,
headers=self.headers
)
return response.json()
def create_tool(self, name: str,
description: str,
parameters: dict,
server_url: str) -> dict:
"""
Инструмент для агента: HTTP-вызов во время разговора.
Типичные кейсы: проверка статуса, поиск в базе, запись заявки.
"""
return {
"type": "function",
"function": {
"name": name,
"description": description,
"parameters": {
"type": "object",
"properties": parameters,
"required": list(parameters.keys())
}
},
"server": {
"url": server_url,
"timeoutSeconds": 5,
}
}
def create_outbound_call(self, assistant_id: str,
phone_number: str,
customer_data: dict = None) -> dict:
"""Инициирование исходящего звонка с передачей контекста"""
payload = {
"assistantId": assistant_id,
"customer": {
"number": phone_number,
"name": customer_data.get("name", "") if customer_data else "",
},
}
if customer_data:
# Передаём данные о клиенте в контекст агента
payload["assistantOverrides"] = {
"variableValues": customer_data
}
response = requests.post(
f"{self.base_url}/call",
json=payload,
headers=self.headers
)
return response.json()
def setup_inbound_phone_number(self, phone_number: str,
assistant_id: str) -> dict:
"""Привязка входящего номера к ассистенту"""
payload = {
"number": phone_number,
"assistantId": assistant_id,
"fallbackDestination": {
"type": "number",
"number": "+1234567890" # Fallback на живого оператора
}
}
response = requests.post(
f"{self.base_url}/phone-number",
json=payload,
headers=self.headers
)
return response.json()
### Configuring interruptions and latency VAPI allows you to fine-tune parameters that affect the naturalness of the conversation: - **`interruptionsEnabled`** — allows the user to interrupt the agent. Critical for the naturalness of the dialogue. - **`backgroundDenoisingEnabled`** — background noise filtering via Krisp. - **`numWordsToInterruptAssistant`** — how many words the user needs to interrupt the agent (1-2 recommended). - **`backchannelingEnabled`** — the agent says "uh-huh" and "understood" during pauses. ### Integration with WebRTC for web callspython
Frontend пример (TypeScript/JavaScript)
VAPI_WEB_SDK_EXAMPLE = """ import Vapi from "@vapi-ai/web";
const vapi = new Vapi("YOUR_PUBLIC_KEY");
// Начало разговора vapi.start({ assistantId: "your-assistant-id", // Или inline конфигурация ассистента });
// Слушаем события vapi.on("call-start", () => console.log("Call started")); vapi.on("call-end", () => console.log("Call ended")); vapi.on("message", (message) => { if (message.type === "transcript") { console.log(message.role, message.transcript); } if (message.type === "function-call") { // Обработка tool call на стороне клиента console.log("Tool:", message.functionCall.name); } }); """







