enforcing a maximum number of calls to a tool
# support
b
@Vapi we want to limit the number of times an assistant can call a function within a single call. Is this possible? #1211483291191083018
v
Vapi does not have a built-in setting to limit tool calls per call, but you can enforce this in your server logic. When handling tool calls at your server URL, track the number of times each tool is called for a given call ID. If the limit is reached, return an error or a custom message.
Copy code
js
// Example: Express handler for tool calls
const toolCallCounts = {}; // { callId: count }
app.post('/tool-calls', (req, res) => {
  const callId = req.headers['x-call-id'];
  toolCallCounts[callId] = (toolCallCounts[callId] || 0) + 1;
  if (toolCallCounts[callId] > MAX_CALLS) {
    return res.json({ error: "Tool call limit reached for this call." });
  }
  // ...handle tool call...
});
This approach gives you full control over tool call limits per session. For more details, see the [Vapi server events documentation](https://docs.vapi.ai/server-url/events). Source: - [Server events](https://docs.vapi.ai/server-url/events)
c
This is currently not a function included on our platform, but if you would like to see that feature on our platform, feel free to add it to the feature request list here -->
3 Views