how to get assistand_id from apiRequest tool ?
# support
a
In my service, I have a buy_car function that is bound to assistants through the apiRequest tool. I have multiple assistants, and when these assistants call buy_car through apiRequest, how can I obtain the assistant_id to distinguish between different assistants?
v
To distinguish which assistant called your
buy_car
function via the apiRequest tool, inspect the payload your service receives—look for the
call
object, which typically includes an
assistantId
field. For example:
Copy code
json
{
  "message": {
    "type": "function-call",
    "call": {
      "assistantId": "your-assistant-id-here",
      // ...other call details
    },
    // ...other message fields
  }
}
Use
call.assistantId
in your handler to identify the calling assistant. Reference: [Outbound Sales Example – Handle function calls](https://docs.vapi.ai/examples/outbound-sales#handle-function-calls) Source: - [Outbound Sales Example – Handle function calls](https://docs.vapi.ai/examples/outbound-sales#handle-function-calls)
To identify which assistant triggered your
buy_car
function via the apiRequest tool, inspect the incoming payload for an assistant identifier.
Typically, the payload sent to your server includes a
call
object, which may contain an
assistantId
or related property. Here’s an example of how you might extract it in Node.js:
Copy code
js
const assistantId = req.body?.message?.call?.assistantId;
console.log('Assistant ID:', assistantId);
Note: The documentation does not explicitly confirm that
assistantId
is always present in the function-call payload. If you do not see it, you may need to include it in your assistant's configuration or contact Vapi support for further guidance.
[See reference](https://docs.vapi.ai/server-url/events) Source: - [Server Events Vapi Documentation](https://docs.vapi.ai/server-url/events)
4 Views