Skip to content

Commit 7f4d06d

Browse files
authored
update docs for server and custom-llm auth (#448)
1 parent 4ccb865 commit 7f4d06d

File tree

4 files changed

+65
-13
lines changed

4 files changed

+65
-13
lines changed

fern/customization/custom-llm/using-your-server.mdx

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,43 @@ Paste the public URL generated by ngrok (e.g., https://your-unique-id.ngrok.io)
6363
**4. Test the Connection:**
6464
Send a test message through the Vapi interface to ensure it reaches your local server and receives a response from the OpenAI API. Verify that the response is displayed correctly in Vapi.
6565

66+
## Authentication (Optional)
67+
68+
For production deployments, you can secure your custom LLM endpoint using authentication. This ensures only authorized requests from Vapi can access your LLM server.
69+
70+
![Custom LLM authentication configuration](../../static/images/server-url/authentication/custom-llm.png)
71+
72+
### Configuration Options
73+
74+
Vapi supports two authentication methods for custom LLMs:
75+
76+
1. **API Key**: Simple authentication where Vapi includes a static API key in request headers. Your server validates this key to authorize requests.
77+
78+
2. **OAuth2 Credentials**: More secure authentication using OAuth2 client credentials flow with automatic token refresh.
79+
80+
### API Key Authentication
81+
82+
When using API Key authentication:
83+
- Vapi sends your API key in the Authorization header to your custom LLM endpoint
84+
- Your server validates the API key before processing the request
85+
- Simple to implement and suitable for basic security requirements
86+
87+
### OAuth2 Authentication
88+
89+
When configuring OAuth2 in the Vapi dashboard:
90+
91+
1. **OAuth2 URL**: Enter your OAuth2 token endpoint (e.g., `https://your-server.com/oauth/token`)
92+
2. **OAuth2 Client ID**: Your OAuth2 client identifier
93+
3. **OAuth2 Client Secret**: Your OAuth2 client secret
94+
95+
### How OAuth2 Works
96+
97+
1. Vapi requests an access token from your OAuth2 endpoint using client credentials
98+
2. Your server validates the credentials and returns an access token
99+
3. Vapi includes the token in the Authorization header for LLM requests
100+
4. Your server validates the token before processing requests
101+
5. Tokens automatically refresh when they expire
102+
66103
## Step 3: Understanding the Communication Flow
67104
**1. Vapi Sends POST Request:**
68105
When a user interacts with your Vapi application, Vapi sends a POST request containing conversation context and metadata to the configured endpoint (your ngrok URL).

fern/server-url/server-authentication.mdx

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -61,28 +61,43 @@ This could include short lived JWTs/API Keys passed along via the Authorization
6161

6262
For OAuth2-protected webhook endpoints, you can configure OAuth2 credentials that Vapi will use to obtain and refresh access tokens.
6363

64-
#### Configuration
64+
#### Configuration (at the assistant-level)
6565

6666
```json
6767
{
6868
"server": {
6969
"url": "https://your-server.com/webhook"
7070
},
71-
"credentials": {
72-
"webhook": {
73-
"type": "oauth2",
74-
"clientId": "your-client-id",
75-
"clientSecret": "your-client-secret",
76-
"tokenUrl": "https://your-server.com/oauth/token",
77-
"scope": "optional, only needed to specify which scopes to request access for"
71+
"credentials": [
72+
{
73+
"provider": "webhook",
74+
"authenticationPlan": {
75+
"type": "oauth2",
76+
"url": "https://your-server.com/oauth/token",
77+
"clientId": "your-client-id",
78+
"clientSecret": "your-client-secret",
79+
"scope": "optional, only needed to specify which scopes to request access for"
80+
}
7881
}
79-
}
82+
]
8083
}
8184
```
8285

86+
#### Configuration (via our Dashboard)
87+
88+
<Steps>
89+
<Step title="Visit the API Keys page">
90+
Go to [https://dashboard.vapi.ai/keys](https://dashboard.vapi.ai/keys) to manage your OAuth2 credentials.
91+
</Step>
92+
</Steps>
93+
94+
<Frame caption="OAuth2 configuration in the Vapi dashboard">
95+
<img src="../static/images/server-url/authentication/webhook.png" />
96+
</Frame>
97+
8398
#### OAuth2 Flow
8499

85-
1. Vapi makes a request to your token endpoint with client credentials
100+
1. Vapi makes a request to your token endpoint with client credentials (Content-Type `application/x-www-form-urlencoded`)
86101
2. Your server validates the credentials and returns an access token
87102
3. Vapi includes the access token in the Authorization header for webhook requests
88103
4. Your server validates the access token before processing the webhook
@@ -96,9 +111,7 @@ Your server should return a JSON response with the following format:
96111
{
97112
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
98113
"token_type": "Bearer",
99-
"expires_in": 3600,
100-
"refresh_token": "tGzv3JOkF0XG5Qx2TlKWIA", // Optional
101-
"scope": "read write" // Optional, only if scope was requested
114+
"expires_in": 3600
102115
}
103116
```
104117

@@ -116,3 +129,5 @@ Common error types:
116129
- `invalid_grant`: Invalid or expired refresh token
117130
- `invalid_scope`: Invalid scope requested
118131
- `unauthorized_client`: Client not authorized for this grant type
132+
133+
<Note> If using the OAuth2 flow for authenticating tool calls, make sure the server for the tool is the URL that should be hit *after* we have completed the token exchange. </Note>
Loading
Loading

0 commit comments

Comments
 (0)