Skip to content

Commit 6fbe91a

Browse files
update
1 parent 2f48a26 commit 6fbe91a

File tree

2 files changed

+59
-7
lines changed

2 files changed

+59
-7
lines changed

fern/customization/jwt-authentication.mdx

Lines changed: 59 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,71 @@ Before you proceed, ensure you have the following:
1212

1313
- An environment that supports JWT generation and API calls (e.g., a programming language or framework)
1414
- An account with a service that requires JWT authentication
15-
- Environment variables set up for the necessary credentials (e.g., organization ID and private key, both can be found in your Vapi portal)
15+
- Environment variables set up for the necessary credentials (e.g., organization ID and Vapi API key, both can be found in your Vapi dashboard)
1616

1717
## Generating a JWT Token
1818

1919
The following steps outline how to generate a JWT token:
2020

2121
1. **Define the Payload**: The payload contains the data you want to include in the token. In this case, it includes an `orgId`.
22-
2. **Get the Private Key**: The private key (provided by Vapi) is used to sign the token. Ensure it is securely stored, often in environment variables.
22+
2. **Get a Vapi API Key**: A Vapi API key is used to sign the token. Ensure it is securely stored, often in environment variables.
2323
3. **Set Token Options**: Define options for the token, such as the expiration time (`expiresIn`).
2424
4. **Generate the Token**: Use a JWT library or built-in functionality to generate the token with the payload, key, and options.
2525

26+
### Creating a Vapi API Key
27+
28+
You can find your API keys in the Vapi dashboard. Head to the `ORG SETTINGS` section on the sidebar and click on the `API Keys` tab.
29+
30+
By default, Vapi creates a pair of private and public API keys for you. However, you may create new API keys at any time through the dashboard or API.
31+
32+
<Frame>
33+
<img src="../static/images/quickstart/dashboard/vapi-api-keys-tab.png" />
34+
</Frame>
35+
36+
Creating new API keys is straightforward through the Vapi API.
37+
38+
**Example (creating a private API key):**
39+
40+
```bash
41+
curl -X POST 'https://api.vapi.ai/token' \
42+
-H 'Content-Type: application/json' \
43+
-H 'Authorization: Bearer <YOUR_API_KEY>' \
44+
-d '{
45+
"name": "My Private Vapi API Key",
46+
"tag": "private"
47+
}'
48+
```
49+
50+
**Example (creating a public API key):**
51+
52+
<Note>
53+
The **restrictions** field is optional. All fields besides **enabled** are only relevant for **public** tokens.
54+
</Note>
55+
56+
```bash
57+
curl -X POST 'https://api.vapi.ai/token' \
58+
-H 'Content-Type: application/json' \
59+
-H 'Authorization: Bearer <YOUR_API_KEY>' \
60+
-d '{
61+
"name": "My Public Vapi API Key",
62+
"tag": "public",
63+
"restrictions": {
64+
"enabled": true,
65+
"allowedOrigins": ["https://example.vapi.ai"],
66+
"allowedAssistantIds": ["1cbf8c70-5fd7-4f61-a220-376ab35be1b0"],
67+
"allowTransientAssistant": false,
68+
}
69+
}'
70+
```
71+
72+
### Vapi API Key Scope
73+
74+
A Vapi API Key can have one of two scopes: Private or Public. The scope of the key will determine the actions that can be performed using the key.
75+
76+
For example, it can be used to restrict which API endpoints the key can access.
77+
2678
<Note>
27-
Without the private key, the JWT token's scope will be limited to web call creation.
79+
As of writing, the only publicly scoped API endpoint is https://api.vapi.ai//call/web, which is used for Web Call creation. All other endpoints are privately scoped.
2880
</Note>
2981

3082
### Example
@@ -35,8 +87,8 @@ const payload = {
3587
orgId: process.env.ORG_ID,
3688
};
3789

38-
// Get the private key from environment variables
39-
const key = process.env.PRIVATE_KEY;
90+
// Get the private (or public) Vapi API key from environment variables
91+
const key = process.env.VAPI_API_KEY;
4092

4193
// Define token options
4294
const options = {
@@ -50,7 +102,7 @@ const token = generateJWT(payload, key, options);
50102
### Explanation
51103

52104
- **Payload**: The payload includes the `orgId`, representing the organization ID.
53-
- **Key**: The private key is used to sign the token, ensuring its authenticity.
105+
- **Key**: The Vapi API key is used to sign the token, ensuring its authenticity.
54106
- **Options**: The `expiresIn` option specifies that the token will expire in 1 hour.
55107
- **Token Generation**: The `generateJWT` function (a placeholder for the actual JWT generation method) creates the token using the provided payload, key, and options.
56108

@@ -94,4 +146,4 @@ With the generated token, you can authenticate API requests to any endpoint requ
94146

95147
## Conclusion
96148

97-
This documentation covered the basics of generating a JWT token and demonstrated how to use the token to make authenticated API requests. Ensure that your environment variables (e.g., `ORG_ID` and `PRIVATE_KEY`) are correctly set up before running the code.
149+
This documentation covered the basics of generating a JWT token and demonstrated how to use the token to make authenticated API requests. Ensure that your environment variables (e.g., `ORG_ID` and ``VAPI_API_KEY``) are correctly set up before running the code.
251 KB
Loading

0 commit comments

Comments
 (0)