31207: JWT token expiration interval is too long
VOICE
ERROR
The Programmable Voice SDK emits this authorization error when the JWT Access Token presented to the SDK is created with an expiration interval that exceeds Twilio's allowed maximum. The Voice SDK error list defines 31207 as JWT token expiration interval is too long and Access Tokens have a maximum lifetime of 24 hours. Twilio recommends issuing tokens for the shortest feasible time.
- The Access Token ttl value or exp claim is set beyond Twilio's maximum of 24 hours.
- The effective expiration interval exceeds the limit because exp was computed more than 86,400 seconds from the token's issued at time. The Voice SDK FAQs note the maximum expiry duration allowed is 24 hours and advise keeping expiry less than or equal to 86,400 minus 1 second.
- Regenerate the Access Token with a ttl that doesn't exceed 24 hours, for example ensure ttl is less than or equal to 86,399 seconds.
- Follow Twilio guidance to keep Access Tokens short lived and refresh them as needed rather than extending their lifetime.
- Implement token refresh in your client by listening for the tokenWillExpire event and updating the token before it expires using device.updateToken, supported in the Voice JavaScript SDK. This enables shorter ttls without disrupting sessions.