BAS014
03/17/2025, 11:03 PMtool-calls
webhook. Error: Request failed with status code 422"
I see the message logs shows gives : "result": "No result returned.",
In the documentation
https://docs.vapi.ai/tools/custom-tools
It refers to the "**toolCallId (X): This is a unique identifier included in the initial request from Vapi.**" so this I assume should be sent in the body to my server? but it isnt there, if I look at the webhook logs only id is there.
Maybe I'm not reading the docs correct but I dont see what the json body should look like that contains toolCallId so that my endpoint can read it and send it back. (I hope I understood that part...)
Also I dont know what this means in the docs: * "Make sure to add “Tools Calls” in both the Server and Client messages and remove the function calling from it."*
I've also tried enforcing strict parameter validation and async/sync options. still nothing.
I've even tried using the json format of the message....
Any help would be appreciated.Shubham Bajaj
03/18/2025, 2:58 PMjson
{
"message": {
"type": "tool-calls",
"toolWithToolCallList": [...],
"timestamp": "...",
"artifact": {...},
"assistant": {...},
"customer": {...},
"call": {...},
"toolCallList": [
{
"type": "function",
"function": {
"name": "your_function_name",
"arguments": {...}
},
"id": "call_xyz123..."
}
]
}
}
The important parts here are:
1. The message is nested under a "message" property
2. The toolCallId
you need to respond with is actually found as id
in the toolCallList
array
3. The entire assistant configuration is included as context
### What Your Server Should Respond With
Your server needs to respond with a specific JSON format:
json
{
"results": [
{
"toolCallId": "call_xyz123...", // The id from the toolCallList
"result": "Your result here" // The actual result of your function
}
]
}
### How to Fix It
1. Update your server endpoint code to properly parse the incoming request from Vapi:
- Extract the id
from message.toolCallList[0].id
to use as the toolCallId
in your response
- Process the function arguments from message.toolCallList[0].function.arguments
2. Ensure your response follows the exact format shown above with the results
array containing an object with toolCallId
and result
properties.
3. Make sure your content types are correct - your server should expect application/json
and respond with application/json
.
4. Check for proper field validation - Make sure your server doesn't throw validation errors on the incoming JSON structure.
### The Note in the Documentation
The documentation mentions "Make sure to add 'Tools Calls' in both the Server and Client messages and remove the function calling from it." This means:
1. You need to configure your assistant to receive "tool-calls" message type in the server messages settings
2. You should configure your assistant to handle tool calls properly in the UI
## Example Server Code (Pseudocode)
Here's a basic example of how your server endpoint should handle the request:
javascript
app.post('/api/get-questions', (req, res) => {
try {
// Extract the tool call ID from the request
const toolCallId = req.body.message?.toolCallList?.[0]?.id;
if (!toolCallId) {
console.error('No toolCallId found in request');
return res.status(400).json({ error: 'Missing toolCallId' });
}
// Extract the function arguments
const functionArgs = req.body.message?.toolCallList?.[0]?.function?.arguments;
// Process the function call with your business logic
// ...your logic here...
// Return the result in the expected format
return res.status(200).json({
results: [
{
toolCallId: toolCallId,
result: "Your processed result here"
}
]
});
} catch (error) {
console.error('Error processing tool call:', error);
return res.status(500).json({ error: 'Internal server error' });
}
});
This should help you resolve the 422 Unprocessable Entity error and get your custom tool working correctly with Vapi.BAS014
03/18/2025, 3:42 PMBAS014
03/20/2025, 9:35 AMAniah
03/22/2025, 4:06 AM