Tools Response does not correspond to the response...
# support
g
I'm using a transport fare calculator API that returns the correct fare value in cents (e.g., 145 for $1.45). The API is triggered correctly, and the response back to VAPI is as such: { tripDetails: [ { tripNumber: 1, transportType: 2, details: [Object] } ], totalFare: 145, totalDistance: 5432, } however, the assistant response was $2. On top of that, when I chat the assistant directly, the message just says "Success" instead of returning the actual fare amount. Not sure if the issue is with: how the toolCall result is being parsed, the conversion logic (cents to dollars), or how the assistant handles the tool response. Has anyone faced this before or know where the breakdown might be?
v
Hi there! 👋 I see you're having an issue with your transport fare calculator API response. I'm unable to diagnose your specific implementation details, but I can definitely help with common issues related to toolCall result parsing and handling. Based on the information I found, there are several potential causes for your issue: ### 1. Incorrect Response Format The tool response format might not be following Vapi's expected structure. Vapi expects a specific JSON format:
Copy code
json
{
  "results": [
    {
      "toolCallId": "<your-tool-call-id>",
      "result": "Your actual result here"
    }
  ]
}
If you're just returning the raw API response or not formatting it correctly, the assistant might not be able to parse it properly. According to [documentation on tool responses](https://docs.vapi.ai/tools-calling), the
result
field should be a properly formatted string without nested JSON or unescaped line breaks. ### 2. The "Success" Message Issue When you see just "Success" instead of the actual fare amount, this is a common issue mentioned in the documentation. According to [information about common parsing issues](https://discord.com/channels/1211482211119796234/1211483291191083018/threads/1340737584309211136), the tool call result might show "Success" rather than the actual result if the response isn't being properly processed. ### 3. Currency Conversion Logic For the incorrect dollar amount ($2 instead of $1.45), this could be related to how the assistant is interpreting the cents value. The assistant might be: - Misinterpreting the value as dollars instead of cents - Rounding the value incorrectly - Not applying proper formatting for currency values ### Debugging Steps Here are some debugging techniques you can try: 1. **Verify your response format**: Ensure you're returning the correct JSON structure with the proper
toolCallId
from the incoming request.
2. **Check synchronous vs. asynchronous**: According to [debugging information](https://discord.com/channels/1211482211119796234/1211483291191083018/threads/1342315282198298729), ensure your tool is set to
synchronous
instead of
async
if you need immediate results. 3. **Implement explicit conversion logic**: Make sure you're explicitly converting cents to dollars in your response. For example:
Copy code
javascript
   const fareInDollars = (totalFare / 100).toFixed(2);
4. **Inspect the logs**: Look at the logs associated with your call ID to see exactly what's being sent and received. 5. **HTTP status code**: Always return a 200 status code to ensure the result is retrieved properly. Would you be able to share more details about how you're formatting the response from your API before sending it back to the assistant? That might help pinpoint the exact issue. Sources: - [Common issues with parsing toolCall results from APIs](https://discord.com/channels/1211482211119796234/1211483291191083018/threads/1340737584309211136) - [Debugging techniques for toolCall result parsing errors](https://discord.com/channels/1211482211119796234/1211483291191083018/threads/1342315282198298729) - [Tool response format documentation](https://docs.vapi.ai/tools-calling)
g
this is in my webhook log { "results": [ { "tool_call_id": "call_SLGFrl8QrHpT48y4mKGILlUu", "result": "The fare is $1.45 for the trip" } ] } . it still tells me $2.50
k
Verify the parsing logic, confirm the accurate conversion from cents to dollars, and ensure that the assistant effectively interprets and returns the fare from the API response.
g
hi @Kings_big💫 yes the conversion is accurate, the result is as shown above but it still returns success
k
Ensure your tool response includes a result field with the intended message, the Content-Type is set to application/json, and the assistant is correctly configured to extract and speak that result and also you can fix the result as "The total fare is $1.45.”
g
it still does not work. however i found something odd,when i tried to invoke the api in Test, it shows a CORS error. when i tried to talk to it, is able to trigger the API
hi @Kings_big💫 any updates?
k
To fix this is to enable CORS on your API server or test via server side calls