Question about assistant-request webhook timing fo...
# support
w
I'm implementing a credit system in my web application that uses the @Vapi-ai/web SDK. I need to verify the exact sequence of events when initiating a call. Specifically, I need to know: 1. Can I use assistant-request webhook for web-calls? I want to have a assistantId already set when .start(). 2. When a user clicks to start a call and vapi.start() is executed, is the call completely on hold until AFTER my server responds to the assistant-request webhook? 3. If a user has insufficient credits and my server responds to the webhook with a configuration to reject the call, will this prevent any billable activity or connection from occurring, or is there billable activity between the vapi.start() and my servers' response? 4. What is the exact sequence of events from when vapi.start() is called to when the conversation actually begins? This information is critical for implementing a proper credit validation system where users without credits cannot initiate calls. I am passing userId from my frontend, via vapi webhook, to my server for verification, using assistantOverrides = { metadata: userId}. Thank you for your assistance
v
Hi there! I can help with your questions about the assistant-request webhook timing for web calls 👋 1. Yes, you can use the assistant-request webhook for web calls. When using the
.start()
function, you can either pass an assistantId directly or use an object with configurations. You can also pass assistantOverrides to include custom data like userId:
Copy code
javascript
const assistantOverrides = {
  variableValues: {
    userId: "yourUserIdHere"
  }
};
vapi.start("assistant_id_here", assistantOverrides);
This ensures your custom data is sent to the webhook during the call process [Vapi Web SDK Documentation](https://docs.vapi.ai/sdk/web). 2. The
vapi.start()
method does not explicitly hold the call
until the server responds to the assistant-request webhook. The method returns a promise that resolves to a call object, but the process is asynchronous. The call continues in a state of expectation for data from the server rather than "holding" until webhook feedback is received [VAPI Web SDK Documentation](https://docs.vapi.ai/sdk/web). 3. If your server responds to the assistant-request webhook with a rejection due to insufficient credits, this should prevent billable activity. When configured correctly, if the assistant request is not fulfilled due to insufficient credits, no billable activities such as connecting to a voice assistant or processing the call will occur. The system will reroute the call to a fallback and provide appropriate information to the user [Discord Link](https://discord.com/channels/1211482211119796234/1211483291191083018/threads/1341914745661554788).
4. Regarding the exact sequence of events from
vapi.start()
to conversation beginning, I wasn't able to find complete documentation on this specific flow. Based on the information available, when
vapi.start()
is called, it initiates a request to the server and triggers the assistant-request webhook, but the detailed step-by-step sequence isn't fully documented in the materials I have access to. For your credit validation system, you can implement a server response like:
Copy code
json
{
  "message": {
    "type": "assistant-request",
    "error": {
      "message": "Sorry, you do not have enough credits to process this request."
    }
  }
}
This should ensure users without credits cannot initiate billable calls. Sources: - [Vapi Web SDK Documentation](https://docs.vapi.ai/sdk/web) - [Discord Link](https://discord.com/channels/1211482211119796234/1211483291191083018/threads/1341914745661554788) - [Server URL documentation](https://docs.vapi.ai/server-url)
w
Can someone from the vapi team confirm. It needs to work for webcalls specifically @User
s
> Can I use assistant-request webhook for web-calls with assistantId already set? For web calls you don't need to set the assistantId in the webhook because the web SDK allows you to set an assistantId when calling .start() . > Is the call on hold until AFTER my server responds to the assistant-request webhook? yes the call is on hold until AFTER your server responds to the assistant-request webhook for phone calls. > Will responding with a rejection prevent any billable activity? No, if your server responds to the assistant-request webhook with an error configuration to reject the call, this will prevent any billable activity from occurring instead you will be charged a minimal negligible fee for the call.
k
For checking credits you have to do it before the vapi.start is called.
w
Okay, I am not using phone calls, only web calls. Is the assistant-request webhook not possible for my use case then? People pay for talking to my coach on my website. I need to restrict calls in a fail proof way. Meaning if some part of the security fails, I rather want an error than unlimited access to making calls, because someone could drain my whole Vapi account. I still can’t figure out exactly the best way of doing this with Vapi.
k
Hello Williham, for your case the best way in my opinion to go about this is when the call is started, use a function or server messages to grab the callers phone number, on your backend check the credit status, and then use live call control to end the call. You could use something like a say message to inform them and trigger the end call function:
w
Let me clarify, I am NOT using phone numbers. I have a web app that users make web calls to. I use the client web SDK.
k
Gotcha, you are going to have to replace that step with sending some sort of authenticated user id in your metadata. When you get the request you can follow the other steps. Let me know if you want me to explain more in depth.
w
Sure please do explain!
k
Glad to help! To start, when vapi.start() is triggered, you can include metadata in the configuration. In your case, when your trigger for vapi.start is hit, you can pass in dynamically the users ID as a key value pair. You then would need to obtain the URLs specific to the live call. These URLs can be retrieved by triggering a
/call
endpoint, which returns the
listenUrl
and
controlUrl
within the
monitor
object. Now that we have the user ID and a control URL, you can check the users credit status on your platform. If they are out of credits you could use the controlUrl to say a message and end the call.
2 Views