Outbound Calls from Python 📞
Some sample code for placing an outbound call using Python
1 import requests 2 3 # Your Vapi API Authorization token 4 auth_token = '<YOUR AUTH TOKEN>' 5 # The Phone Number ID, and the Customer details for the call 6 phone_number_id = '<PHONE NUMBER ID FROM DASHBOARD>' 7 customer_number = "+14151231234" 8 9 # Create the header with Authorization token 10 headers = { 11 'Authorization': f'Bearer {auth_token}', 12 'Content-Type': 'application/json', 13 } 14 15 # Create the data payload for the API request 16 data = { 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 38 response = 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 42 if response.status_code == 201: 43 print('Call created successfully') 44 print(response.json()) 45 else: 46 print('Failed to create call') 47 print(response.text)