Outbound Calls from Python 📞

Some sample code for placing an outbound call using Python

1import requests
2
3# Your Vapi API Authorization token
4auth_token = '<YOUR AUTH TOKEN>'
5# The Phone Number ID, and the Customer details for the call
6phone_number_id = '<PHONE NUMBER ID FROM DASHBOARD>'
7customer_number = "+14151231234"
8
9# Create the header with Authorization token
10headers = {
11 'Authorization': f'Bearer {auth_token}',
12 'Content-Type': 'application/json',
13}
14
15# Create the data payload for the API request
16data = {
17 'assistant': {
18 "firstMessage": "Hey, what's up?",
19 "model": {
20 "provider": "openai",
21 "model": "gpt-3.5-turbo",
22 "messages": [
23 {
24 "role": "system",
25 "content": "You are an assistant."
26 }
27 ]
28 },
29 "voice": "jennifer-playht"
30 },
31 'phoneNumberId': phone_number_id,
32 'customer': {
33 'number': customer_number,
34 },
35}
36
37# Make the POST request to Vapi to create the phone call
38response = requests.post(
39 'https://api.vapi.ai/call/phone', headers=headers, json=data)
40
41# Check if the request was successful and print the response
42if response.status_code == 201:
43 print('Call created successfully')
44 print(response.json())
45else:
46 print('Failed to create call')
47 print(response.text)