This documentation provides an overview of JWT (JSON Web Token) Authentication and demonstrates how to generate a JWT token and use it to authenticate API requests securely.
Before you proceed, ensure you have the following:
The following steps outline how to generate a JWT token:
orgId.expiresIn).The generated JWT token can have one of two scopes: private or public. The scope of the token will determine the actions that can be performed using the token.
For example, it can be used to restrict which API endpoints the token can access.
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.
orgId representing the organization ID and the token object with the scope of the token.expiresIn option specifies that the token will expire in 1 hour.generateJWT function (a placeholder for the actual JWT generation method) creates the token using the provided payload, key, and options.If you set the scope to private, you can use it to make authenticated API requests. The following steps outline how to make an authenticated request:
Content-Type and Authorization headers in your request. The Authorization header should include the generated JWT token prefixed with Bearer.Content-Type is set to application/json, and the Authorization header includes the generated JWT token.fetchData function makes an asynchronous GET request to the specified API endpoint and logs the response.If you set the scope to public, you can use it to make authenticated API requests using the Vapi Web Client.