connect voice agent and twilio at scale
# support
v
We are building a single Vapi voice agent that uses a custom LLM URL to dynamically respond to incoming calls. The goal is to identify the caller's phone number and use it to determine which backend LLM instance should handle the conversation. This allows us to support multiple use cases through a single voice agent on the Vapi dashboard. To scale this setup, we plan to connect multiple Twilio phone numbers (potentially up to 1000) to this single Vapi agent. Each number represents a different use case or client, and the voice agent will route the call dynamically based on the incoming number. We have a few questions: Is there a limit to how many Twilio numbers can be connected to a single Vapi voice agent? If 1000 numbers is not feasible, what is the recommended architecture to support this kind of routing? Is ther a way to connect Twilio call to vapi passing through our own backend?
v
To support dynamic routing for many Twilio numbers, configure each number (or the assistant) with a server URL that points to your backend. Your backend can then use the incoming caller's number to select the correct LLM instance. Here’s a sample Express.js endpoint to handle this:
Copy code
js
app.post('/vapi-webhook', (req, res) => {
  const caller = req.body.customer?.number;
  // Lookup LLM instance based on caller
  // Route call logic here
  res.json({ assistantId: getLLMForCaller(caller) });
});
Set this endpoint as your assistant or phone number server URL in Vapi to enable scalable, dynamic routing. Sources: - [Setting server URLs](https://docs.vapi.ai/server-url/setting-server-urls) - [Import number from Twilio](https://docs.vapi.ai/phone-numbers/import-twilio)
v
but how does the call from Twilio gets connected to the voice agent? We are able to get the dynamic LLM instance working.
@Vapi Support Bot
v
To connect Twilio calls to your Vapi voice agent, set your Twilio number's webhook to your backend, then have your backend trigger a Vapi call. For example:
Copy code
js
// Twilio webhook handler
app.post('/twilio-incoming', async (req, res) => {
  const caller = req.body.From;
  // Call Vapi API to start the voice agent
  await axios.post('https://api.vapi.ai/call', {
    phoneNumberId: YOUR_VAPI_PHONE_NUMBER_ID,
    customer: { number: caller },
    assistantId: getLLMForCaller(caller)
  }, { headers: { Authorization: `Bearer ${VAPI_API_KEY}` } });
  res.send('<Response></Response>'); // TwiML response
});
Set
/twilio-incoming
as your Twilio number's webhook. This lets you scale and route calls dynamically through your backend. Reference: [Call Handling with Vapi and Twilio](https://docs.vapi.ai/calls/call-handling-with-vapi-and-twilio) Source: - [Call Handling with Vapi and Twilio](https://docs.vapi.ai/calls/call-handling-with-vapi-and-twilio)
v
@Vapi Support Bot Do i need to link all 1000 numbers on the vapi dashboard to get this id? phoneNumberId: YOUR_VAPI_PHONE_NUMBER_ID,
v
Yes, each Twilio number you want to use with Vapi must be imported and registered in the Vapi dashboard to obtain its unique
phoneNumberId
.
Once imported, you can use that
phoneNumberId
in your backend logic to trigger the Vapi agent for each incoming call:
Copy code
js
await axios.post('https://api.vapi.ai/call', {
  phoneNumberId: YOUR_VAPI_PHONE_NUMBER_ID, // unique for each imported number
  customer: { number: caller },
  assistantId: getLLMForCaller(caller)
}, { headers: { Authorization: `Bearer ${VAPI_API_KEY}` } });
For large-scale setups, consider automating the import process via the [Vapi API](https://docs.vapi.ai/api-reference/phone-numbers/create) to manage many numbers efficiently. Sources: - [Phone Calling](https://docs.vapi.ai/phone-calling) - [Call Handling with Vapi and Twilio](https://docs.vapi.ai/calls/call-handling-with-vapi-and-twilio)
v
@Vapi Support Bot is there a limit on how many numbers can be imported? we have 1000 of them
v
There is no documented hard limit on the number of Twilio numbers you can import into Vapi—only free Vapi numbers are limited to 10 per account. For large-scale imports (like 1000 numbers), automate the process using the Vapi API for efficiency. If you encounter any issues at this scale, it's best to reach out to Vapi support for guidance. Reference: [Phone Calling documentation](https://docs.vapi.ai/phone-calling) Source: - [Phone Calling](https://docs.vapi.ai/phone-calling)
v
Message marked as helpful by @VerveAI! 🎉
Message marked as helpful by @VerveAI! 🎉
Message marked as helpful by @VerveAI! 🎉
n
@VerveAI I think you're working the issue backwards. I wouldn't do that, as you will create a management hell on your VAPI account. We have a customer that created a similar thing, using a single number on VAPI, while there are 100 numbers in the front side. You can DM me and I'll explain.