Eelco
05/06/2025, 2:55 PMts
const payload = {
orgId: process.env.VAPI_ORG_ID,
// This is the scope of the token
token: {
tag: 'public',
restrictions: {
enabled: process.env.NODE_ENV !== 'development',
allowedOrigins: [process.env.NEXT_PUBLIC_APP_URL],
allowedAssistantIds: [assistant.vapiId],
allowTransientAssistant: false,
},
},
}
// Get the private key from environment variables
const key = new TextEncoder().encode(process.env.VAPI_PRIVATE_KEY)
// Generate the token using a JWT library or built-in functionality
const token = await new SignJWT(payload)
.setProtectedHeader({ alg: 'HS256' })
.setExpirationTime('1h')
.sign(key)
The JWT validates correctly using the private key, however from the vapi api we receive:
{
"message": "Couldn't verify JWT.",
"error": "Unauthorized",
"statusCode": 401
}Shubham Bajaj
05/06/2025, 5:02 PMKings_big💫
05/06/2025, 5:18 PM