Dynamically Header passing to a Tool
# support
a
I am building a voice bot using VAPI. I would like to dynamically pass the header to the tool. How can I achieve this? Since each user has a different token that I need to pass to the tool as a header, I’m unable to set it directly from the Vapi Dashboard.
v
Vapi currently supports setting static headers for tools, but does not document a way to dynamically inject per-user headers (like a user token) directly from the Dashboard. The typical approach is to have Vapi send the payload to your backend, where you add the dynamic header before calling the actual tool. Clarifying question: Are you able to route tool calls through your own backend, so you can programmatically add the user-specific token to the headers before forwarding the request to the tool? Sources: - [Custom Tools Documentation](https://docs.vapi.ai/tools/custom-tools) - [Tool Calling Integration](https://docs.vapi.ai/customization/tool-calling-integration) - [API Reference: Update Tool](https://docs.vapi.ai/api-reference/tools/update?explorer=true)
a
I need a way to pass the authentication token of a specific user to the tool, so that I can identify which user is making the tool call. Can't I do it using crendentials endpoint, if yes, can you explain how.
v
You should route tool calls through your own backend, where you can inject the user-specific authentication token into the headers before forwarding the request to the actual tool. Here’s a simple Node.js/Express example:
Copy code
js
app.post('/vapi-tool-proxy', async (req, res) => {
  const userToken = /* logic to get user token from session/context */;
  const response = await fetch('https://your-tool-endpoint', {
    method: 'POST',
    headers: {
      'Authorization': `Bearer ${userToken}`,
      'Content-Type': 'application/json'
    },
    body: JSON.stringify(req.body)
  });
  res.status(response.status).send(await response.text());
});
Set your tool's server URL in Vapi to this proxy endpoint. This is the standard way to handle dynamic per-user headers in Vapi. Sources: - [Custom Tools Documentation](https://docs.vapi.ai/tools/custom-tools) - [Tool Calling Integration](https://docs.vapi.ai/customization/tool-calling-integration)
a
I want to do it in python. Moreover, "how can I get user token from session/context"?
v
To dynamically pass a user-specific token as a header in Python, set your tool's server URL in Vapi to a proxy endpoint on your backend. In your Flask app, inject the token before forwarding the request:
Copy code
python
from flask import Flask, request
import requests

app = Flask(__name__)

@app.route('/vapi-tool-proxy', methods=['POST'])
def proxy():
    user_token = "EXTRACTED_USER_TOKEN"  # Implement your logic here
    resp = requests.post(
        'https://your-tool-endpoint',
        headers={'Authorization': f'Bearer {user_token}', 'Content-Type': 'application/json'},
        json=request.get_json()
    )
    return (resp.text, resp.status_code, resp.headers.items())

# Run your Flask app as usual
How to get the user token: You must design your system to make the token available (e.g., include it in the payload or retrieve it from your own session/context), as Vapi does not provide it automatically in the request. Sources: - [Custom Tools Documentation](https://docs.vapi.ai/tools/custom-tools) - [Tool Calling Integration](https://docs.vapi.ai/customization/tool-calling-integration)
k
Include the token in assistantOverrides.variableValues when initiating the call, then reference it in the tool’s headers using {{userToken}}.