still getting(venv) PS C:\Users\DELL\Desktop\gradio_project> python app.py๐งช Gradio version: 5.34.2๐งช Gradio version: 5.34.2๐ Vapi Client Initialized: Private Key: 76a7de02...1377 Public Key: 8aaf8680...c58d๐ Vapi Client Initialized: Private Key: 76a7de02...1377 Public Key: 8aaf8680...c58dโ
Enhanced AI Chat Handler initialized successfully๐ Loading all agents on startup...โ
Loaded 14 chat agentsโ
Found 24 voice agents in Vapiโ
Total voice agents loaded: 24๐ฏ Startup complete - Voice: 24, Chat: 14๐ DEBUG: Initializing app...๐ DEBUG: Checking database state...๐ Users in memory: 8๐ Users in database: 8 - John Doe (john@example.com) - Jane Smith (jane@example.com) - Mike Johnson (mike@example.com) - Sarah Wilson (sarah@example.com) - David Brown (david@example.com) - Haseeb (h@gmail.com) - Umer (umer@gmail.com) - haziqtest (haziqteset123)๐งช Testing Vapi connection with private key...๐ DEBUG: App initialized - Voice: 24, Chat: 14, Users: 8๐ DEBUG: Initial user choices: 8 users๐ DEBUG: Initial user choices: 8 users๐ DEBUG: Generated initial chat agents display๐ DEBUG: Initial chat agent choices: 15 agents๐ DEBUG: Initial user choices: 8 users๐ DEBUG: Initial user choices: 8 users๐ Starting AI Assistant Pro...๐ก Vapi Status: Connected โ
๐ Twilio Status: Checking...๐ค Voice Agents: 24๐ฌ Chat Agents: 14๐ฅ Users: 8 (from database)๐ Phone Numbers: 0 available of 11 total๐ Vapi API Key: 76a7de02...1377๐ค OpenAI API Key: sk-proj-...7OYA๐ Twilio SID: AC5e7180...2cf95561...7e58๐
Appointment Tool ID: e3e40541-8e94-45be-808f-472c61e8a5b2๐ง Email API URL: https://your-actual-domain.com/api/send-email๐ง Default Test Email: zohaib9856@gmail.com๐ Login required: admin123๐ Launching Gradio interface...* Running on local URL: http://0.0.0.0:7860* Running on public URL: https://ae92aac238e80b1116.gradio.liveThis share link expires in 1 week. For free permanent hosting and GPU upgrades, run gradio deploy from the terminal in the working directory to deploy to Hugging Face Spaces (https://huggingface.co/spaces)๐ DEBUG: Login attempt with password: admin123๐ DEBUG: Current login state: Falseโ
Login successful!๐ DEBUG: Rendering interface, logged in: True๐ DEBUG: create_agent_with_unique_phone called with enhanced phone manager - agent_name: f - selected_tools: [] - preferred_area_code: 323๐ค Creating Vapi agent with private key...๐ Agent config keys: ['name', 'voice', 'model', 'firstMessage', 'recordingEnabled', 'endCallMessage', 'endCallPhrases', 'backgroundSound', 'backchannelingEnabled', 'backgroundDenoisingEnabled', 'modelOutputInMessagesEnabled']๐ Making request to: https://api.vapi.ai/assistant๐ Using private key headers๐ Response status: 201โ
Agent created successfully! ID: 57489f6a-d717-400f-8afd-c3e902fc8c49๐ Searching for numbers in area code 323๐ Purchasing Twilio number: +13237680338๐ Registering +13237680338 with Vapi๐ Vapi registration payload: {'provider': 'twilio', 'number': '+13237680338', 'twilioAccountSid': 'AC5e71804264f898cfb1e5f41cc2cb1f87', 'twilioPhoneNumberId': 'PN731b061b981cabdb15e1306417eb8b48', 'name': 'Twilio-+13237680338', 'assistantId': '57489f6a-d717-400f-8afd-c3e902fc8c49'}๐ Vapi registration response: 400 - {"message":["property twilioPhoneNumberId should not exist"],"error":"Bad Request","statusCode":400}Twilio number purchased but Vapi registration failed for agent f
I see the issue! Vapi doesn't want twilioPhoneNumberId either. Let me check the correct Vapi API documentation format. It seems like Vapi expects a different field name. Let me fix this by using the correct field name:
The issue is that Vapi's API documentation might be inconsistent or the field name has changed. Let me create a version that tries different approaches:
Now I've updated the code to:
The key insight is that even if Vapi registration fails, the Twilio number will still work because:
Restart the app and try creating another agent. The system should now:
(venv) PS C:\Users\DELL\Desktop\gradio_project> python app.py๐งช Gradio version: 5.34.2๐งช Gradio version: 5.34.2๐ Vapi Client Initialized: Private Key: 76a7de02...1377 Public Key: 8aaf8680...c58d๐ Vapi Client Initialized: Private Key: 76a7de02...1377 Public Key: 8aaf8680...c58dโ
Enhanced AI Chat Handler initialized successfully๐ Loading all agents on startup...โ
Loaded 14 chat agentsโ
Found 26 voice agents in Vapiโ
Total voice agents loaded: 26๐ฏ Startup complete - Voice: 26, Chat: 14๐ DEBUG: Initializing app...๐ DEBUG: Checking database state...๐ Users in memory: 8๐ Users in database: 8 - John Doe (john@example.com) - Jane Smith (jane@example.com) - Mike Johnson (mike@example.com) - Sarah Wilson (sarah@example.com) - David Brown (david@example.com) - Haseeb (h@gmail.com) - Umer (umer@gmail.com) - haziqtest (haziqteset123)๐งช Testing Vapi connection with private key...๐ DEBUG: App initialized - Voice: 26, Chat: 14, Users: 8๐ DEBUG: Initial user choices: 8 users๐ DEBUG: Initial user choices: 8 users๐ DEBUG: Generated initial chat agents display๐ DEBUG: Initial chat agent choices: 15 agents๐ DEBUG: Initial user choices: 8 users๐ DEBUG: Initial user choices: 8 users๐ Starting AI Assistant Pro...๐ก Vapi Status: Connected โ
๐ Twilio Status: Checking...๐ค Voice Agents: 26๐ฌ Chat Agents: 14๐ฅ Users: 8 (from database)๐ Phone Numbers: 0 available of 13 total๐ Vapi API Key: 76a7de02...1377๐ค OpenAI API Key: sk-proj-...7OYA๐ Twilio SID: AC5e7180...2cf95561...7e58๐
Appointment Tool ID: e3e40541-8e94-45be-808f-472c61e8a5b2๐ง Email API URL: https://your-actual-domain.com/api/send-email๐ง Default Test Email: zohaib9856@gmail.com๐ Login required: admin123๐ Launching Gradio interface...* Running on local URL: http://0.0.0.0:7860* Running on public URL: https://f8544146c6c433fe1e.gradio.liveThis share link expires in 1 week. For free permanent hosting and GPU upgrades, run gradio deploy from the terminal in the working directory to deploy to Hugging Face Spaces (https://huggingface.co/spaces)๐ DEBUG: Login attempt with password: admin123๐ DEBUG: Current login state: Falseโ
Login successful!๐ DEBUG: Rendering interface, logged in: True๐ DEBUG: create_agent_with_unique_phone called with enhanced phone manager - agent_name: h - selected_tools: [] - preferred_area_code: 323๐ค Creating Vapi agent with private key...๐ Agent config keys: ['name', 'voice', 'model', 'firstMessage', 'recordingEnabled', 'endCallMessage', 'endCallPhrases', 'backgroundSound', 'backchannelingEnabled', 'backgroundDenoisingEnabled', 'modelOutputInMessagesEnabled']๐ Making request to: https://api.vapi.ai/assistant๐ Using private key headers๐ Response status: 201โ
Agent created successfully! ID: 10af0e52-b863-4f8f-a531-0a8c11e93243๐ Searching for numbers in area code 323๐ Purchasing Twilio number: +13239689145๐ Registering +13239689145 with Vapi๐ Trying Vapi registration format 1: {'provider': 'twilio', 'number': '+13239689145', 'twilioAccountSid': 'AC5e71804264f898cfb1e5f41cc2cb1f87', 'name': 'Twilio-+13239689145', 'assistantId': '10af0e52-b863-4f8f-a531-0a8c11e93243'}๐ Vapi registration response 1: 400 - {"message":"Number Not Found on Twilio.","error":"Bad Request","statusCode":400}โ ๏ธ Format 1 failed with 400, trying next format...๐ Trying Vapi registration format 2: {'provider': 'twilio', 'number': '+13239689145', 'twilioAccountSid': 'AC5e71804264f898cfb1e5f41cc2cb1f87', 'twilioPhoneNumberSid': 'PN48fea243166fde8f7bd3adef92e05a3b', 'name': 'Twilio-+13239689145', 'assistantId': '10af0e52-b863-4f8f-a531-0a8c11e93243'}๐ Vapi registration response 2: 400 - {"message":["property twilioPhoneNumberSid should not exist"],"error":"Bad Request","statusCode":400}โ ๏ธ Format 2 failed with 400, trying next format...๐ Trying Vapi registration format 3: {'provider': 'twilio', 'number': '+13239689145', 'twilioAccountSid': 'AC5e71804264f898cfb1e5f41cc2cb1f87', 'phoneNumberSid': 'PN48fea243166fde8f7bd3adef92e05a3b', 'name': 'Twilio-+13239689145', 'assistantId': '10af0e52-b863-4f8f-a531-0a8c11e93243'}๐ Vapi registration response 3: 400 - {"message":["property phoneNumberSid should not exist"],"error":"Bad Request","statusCode":400}โ ๏ธ Format 3 failed with 400, trying next format...Twilio number purchased but Vapi registration failed for agent h
Perfect! Now I can see the exact issue. The first error message is key: "Number Not Found on Twilio." This suggests that Vapi is trying to verify the number exists in Twilio, but there might be a timing issue or the number needs to be fully provisioned first.
Let me fix this by adding a delay and verification step:
The key improvements:
This should resolve the "Number Not Found on Twilio" error by ensuring the number is fully provisioned before attempting Vapi registration.
Restart the app and try creating another agent. The process should now:
(venv) PS C:\Users\DELL\Desktop\gradio_project> python app.py๐งช Gradio version: 5.34.2๐งช Gradio version: 5.34.2๐ Vapi Client Initialized: Private Key: 76a7de02...1377 Public Key: 8aaf8680...c58d๐ Vapi Client Initialized: Private Key: 76a7de02...1377 Public Key: 8aaf8680...c58dโ
Enhanced AI Chat Handler initialized successfully๐ Loading all agents on startup...โ
Loaded 14 chat agentsโ
Found 27 voice agents in Vapiโ
Total voice agents loaded: 27๐ฏ Startup complete - Voice: 27, Chat: 14๐ DEBUG: Initializing app...๐ DEBUG: Checking database state...๐ Users in memory: 8๐ Users in database: 8 - John Doe (john@example.com) - Jane Smith (jane@example.com) - Mike Johnson (mike@example.com) - Sarah Wilson (sarah@example.com) - David Brown (david@example.com) - Haseeb (h@gmail.com) - Umer (umer@gmail.com) - haziqtest (haziqteset123)๐งช Testing Vapi connection with private key...๐ DEBUG: App initialized - Voice: 27, Chat: 14, Users: 8๐ DEBUG: Initial user choices: 8 users๐ DEBUG: Initial user choices: 8 users๐ DEBUG: Generated initial chat agents display๐ DEBUG: Initial chat agent choices: 15 agents๐ DEBUG: Initial user choices: 8 users๐ DEBUG: Initial user choices: 8 users๐ Starting AI Assistant Pro...๐ก Vapi Status: Connected โ
๐ Twilio Status: Checking...๐ค Voice Agents: 27๐ฌ Chat Agents: 14๐ฅ Users: 8 (from database)๐ Phone Numbers: 0 available of 14 total๐ Vapi API Key: 76a7de02...1377๐ค OpenAI API Key: sk-proj-...7OYA๐ Twilio SID: AC5e7180...2cf95561...7e58๐
Appointment Tool ID: e3e40541-8e94-45be-808f-472c61e8a5b2๐ง Email API URL: https://your-actual-domain.com/api/send-email๐ง Default Test Email: zohaib9856@gmail.com๐ Login required: admin123๐ Launching Gradio interface...* Running on local URL: http://0.0.0.0:7860* Running on public URL: https://c884c154d6f143e04a.gradio.liveThis share link expires in 1 week. For free permanent hosting and GPU upgrades, run gradio deploy from the terminal in the working directory to deploy to Hugging Face Spaces (https://huggingface.co/spaces)๐ DEBUG: Login attempt with password: admin123๐ DEBUG: Current login state: Falseโ
Login successful!๐ DEBUG: Rendering interface, logged in: True๐ DEBUG: create_agent_with_unique_phone called with enhanced phone manager - agent_name: i - selected_tools: [] - preferred_area_code: 323๐ค Creating Vapi agent with private key...๐ Agent config keys: ['name', 'voice', 'model', 'firstMessage', 'recordingEnabled', 'endCallMessage', 'endCallPhrases', 'backgroundSound', 'backchannelingEnabled', 'backgroundDenoisingEnabled', 'modelOutputInMessagesEnabled']๐ Making request to: https://api.vapi.ai/assistant๐ Using private key headers๐ Response status: 201โ
Agent created successfully! ID: 79f7ab9e-913b-4f84-a49d-49f8ec7b3568๐ Searching for numbers in area code 323๐ Purchasing Twilio number: +13233103547โ
Number purchased successfully: +13233103547๐ Phone SID: PNd2e5e25b64950341a629a68ff37354da๐ Registering +13233103547 with Vapiโณ Waiting 3 seconds for Twilio provisioning...๐ Verifying number +13233103547 in Twilio (attempt 1)โ
Number +13233103547 verified in Twilio๐ Vapi registration payload: {'provider': 'twilio', 'number': '+13233103547', 'twilioAccountSid': 'AC5e71804264f898cfb1e5f41cc2cb1f87', 'name': 'Twilio-+13233103547', 'assistantId': '79f7ab9e-913b-4f84-a49d-49f8ec7b3568'}๐ Vapi registration response: 400 - {"message":"Number Not Found on Twilio.","error":"Bad Request","statusCode":400}โณ 'Number Not Found' error - waiting 5 more seconds and retrying...๐ Vapi registration retry response: 400 - {"message":"Number Not Found on Twilio.","error":"Bad Request","statusCode":400}Twilio number purchased but Vapi registration failed for agent i