|
| 1 | +# Server Authentication |
| 2 | + |
| 3 | +When configuring webhooks for your assistant, you can authenticate your server endpoints using either a secret token, custom headers, or OAuth2. This ensures that only authorized requests from Vapi are processed by your server. |
| 4 | + |
| 5 | +## Credential Configuration |
| 6 | + |
| 7 | +Credentials can be configured at multiple levels: |
| 8 | + |
| 9 | +1. **Tool Call Level**: Create individual credentials for each tool call |
| 10 | +2. **Assistant Level**: Set credentials directly in the assistant configuration |
| 11 | +3. **Phone Number Level**: Configure credentials for specific phone numbers |
| 12 | +4. **Organization Level**: Manage credentials in the [API Keys page](https://dashboard.vapi.ai/keys) |
| 13 | + |
| 14 | +The order of precedence is: |
| 15 | +1. Tool call-level credentials |
| 16 | +2. Assistant-level credentials |
| 17 | +3. Phone number-level credentials |
| 18 | +4. Organization-level credentials from the API Keys page |
| 19 | + |
| 20 | +## Authentication Methods |
| 21 | + |
| 22 | +### Secret Token Authentication |
| 23 | + |
| 24 | +The simplest way to authenticate webhook requests is using a secret token. Vapi will include this token in the `X-Vapi-Signature` header of each request. |
| 25 | + |
| 26 | +#### Configuration |
| 27 | + |
| 28 | +```json |
| 29 | +{ |
| 30 | + "server": { |
| 31 | + "url": "https://your-server.com/webhook", |
| 32 | + "secret": "your-secret-token" |
| 33 | + } |
| 34 | +} |
| 35 | +``` |
| 36 | + |
| 37 | +### Custom Headers Authentication |
| 38 | + |
| 39 | +For more complex authentication scenarios, you can configure custom headers that Vapi will include with each webhook request. |
| 40 | + |
| 41 | +#### Configuration |
| 42 | + |
| 43 | +```json |
| 44 | +{ |
| 45 | + "server": { |
| 46 | + "url": "https://your-server.com/webhook", |
| 47 | + "headers": { |
| 48 | + "Authorization": "Bearer your-api-key", |
| 49 | + "Custom-Header": "custom-value" |
| 50 | + } |
| 51 | + } |
| 52 | +} |
| 53 | +``` |
| 54 | + |
| 55 | +### OAuth2 Authentication |
| 56 | + |
| 57 | +For OAuth2-protected webhook endpoints, you can configure OAuth2 credentials that Vapi will use to obtain and refresh access tokens. |
| 58 | + |
| 59 | +#### Configuration |
| 60 | + |
| 61 | +```json |
| 62 | +{ |
| 63 | + "server": { |
| 64 | + "url": "https://your-server.com/webhook" |
| 65 | + }, |
| 66 | + "credentials": { |
| 67 | + "webhook": { |
| 68 | + "type": "oauth2", |
| 69 | + "clientId": "your-client-id", |
| 70 | + "clientSecret": "your-client-secret", |
| 71 | + "tokenUrl": "https://your-server.com/oauth/token", |
| 72 | + "scope": "optional, only needed to specify which scopes to request access for" |
| 73 | + } |
| 74 | + } |
| 75 | +} |
| 76 | +``` |
| 77 | + |
| 78 | +#### OAuth2 Flow |
| 79 | + |
| 80 | +1. Vapi makes a request to your token endpoint with client credentials |
| 81 | +2. Your server validates the credentials and returns an access token |
| 82 | +3. Vapi includes the access token in the Authorization header for webhook requests |
| 83 | +4. Your server validates the access token before processing the webhook |
| 84 | +5. When the token expires, Vapi automatically requests a new one |
0 commit comments