Back to Blog
Error-Code Fixes

Twilio Error 31202: JWT Token Expired Voice SDK: Causes and How to Fix It

The access token used to initialise the Voice SDK has expired. Error 31202 drops active calls and blocks new ones. Here is the token refresh fix.

DA
Danial A
Senior Twilio Consultant, Telphi Consulting
June 21, 2026
6 min read
Twilio
Error
Voice
SIP
Troubleshooting
Twilio Error 31202: JWT Token Expired Voice SDK: Causes and How to Fix It

Twilio error 31202 means the Twilio access token used to initialize or update the Voice SDK has passed its expiry time, and the SDK can no longer authenticate its signaling connection to Twilio's infrastructure. This error can fire at SDK registration time if an expired token is passed on initialization, or during an active session when a token expires while the Device is registered and mid-call. A well-implemented token refresh strategy prevents 31202 entirely.

What Causes This Error

The access token's exp (expiration) JWT claim has passed the current UTC time when Twilio validates it against the Twilio infrastructure, meaning the token was either generated too far in the past or the TTL (time-to-live) value used when generating it was too short. A TTL of 3600 seconds (1 hour) is Twilio's default recommendation, but applications that cache the token client-side for longer than that, or applications where the user has the page open across multiple hours without a token refresh cycle, will eventually hit 31202. Clock skew between the server generating the token and Twilio's validation servers is a less common but real cause: if the generating server's system clock is more than 5 minutes behind UTC, the token may appear expired to Twilio immediately after generation. Generating tokens with a TTL of 0 or with an exp value set to a past timestamp due to a bug in the token generation code is an edge case that also immediately produces 31202 on the first SDK initialization.

How to Fix It Step by Step

Generate a new access token server-side using the Twilio AccessToken helper class with a fresh ttl value of 3600 seconds, ensuring the generating server's system clock is synchronized to NTP. Pass the fresh token to the already-initialized Device using Device.updateToken(newToken) rather than creating a new Device instance, which updates the token in place without dropping existing calls or re-establishing the signaling connection. Implement a client-side token refresh timer that fires at 80 percent of the token's TTL (for a 3600-second TTL, refresh at 2880 seconds), fetching a new token from your server-side token endpoint and calling Device.updateToken() with the response. Add error handling in your Device.on('error') handler for the 31202 code that immediately fetches a fresh token and calls Device.updateToken(), providing a fallback recovery path for cases where the proactive refresh timer missed a cycle.

How to Prevent It from Recurring

Use the Twilio AccessToken class in your server-side token generation code with an explicit ttl of 3600 and verify the token's exp claim after generation by decoding the JWT payload (base64 decode the second segment) to confirm the exp timestamp is correctly set to the current time plus TTL. Implement the token refresh endpoint as an authenticated route in your backend that returns a fresh AccessToken with a Voice grant and the correct identity claim, callable by the client without page reload. Store the token expiry time client-side when the token is issued (currentTime + TTL * 1000 in milliseconds) and use setInterval or setTimeout to schedule a refresh call 300 seconds before expiry, ensuring the Device always has a valid token regardless of how long the user session runs. Monitor your token generation endpoint's response times and error rates: a slow or failing token endpoint during a refresh cycle will cause the refresh to fail silently, ultimately leading to a 31202 when the current token expires.

When to Call a Specialist

If your token refresh logic is implemented correctly but 31202 errors still appear, a specialist can decode the JWT tokens being passed to the SDK and compare the exp timestamp against the actual call timestamp to confirm whether the token is genuinely expired or whether Twilio's validation is rejecting it for another reason such as an incorrect AccountSid in the iss claim. You should also seek specialist help if you are building a long-session application (such as a contact center agent desktop that stays open for 8-hour shifts) and need to design a token lifecycle management system that handles continuous refreshes, re-registration, and mid-call token updates without service interruption. Clock synchronization issues on your token generation servers are subtle and can cause intermittent 31202 errors: a specialist can audit your server time configuration and recommend a monitoring approach to detect clock drift before it starts affecting token validity.

Conclusion

Error 31202 is a token expiry issue that is permanently resolved by implementing a proactive token refresh cycle that calls Device.updateToken() before the current token reaches its expiry. If this error is blocking your production system, contact our team and we will diagnose and fix it within the hour.

Share this article:
0 views

Ready to Transform Your Business Communications?

Get a free consultation with our VoIP experts and discover how we can help you save costs, improve efficiency, and scale your business.

Comments (0)

Join the discussion and share your thoughts (AI-moderated for quality)

Protected by AI moderation

Be the first to comment

No comments yet. Share your thoughts below.