31205: JWT token has expired
VOICE
ERROR
Twilio Voice SDKs emit error 31205 when the Access Token used for authentication has expired. In the Voice SDK error catalog, 31205 is listed under authorization errors with the description JWT token has expired. The Voice JS SDK v1 notes that when the token expires, signaling, DTMF and Insights stop working until the application supplies a fresh token.
- The Access Token's configured lifetime elapsed and the token reached its exp timestamp, which limits tokens to short lifetimes up to 24 hours.
- The application didn't refresh and update the SDK with a new token before the old token expired, so the SDK reported 31205.
- The token was minted with a very short ttl, causing it to expire during or shortly after initialization.
- Long‑running sessions or backgrounded apps missed the recommended pre‑expiry refresh window provided by the SDK, leading to expiry during an active session.
- Implement an automatic token refresh flow. In the Voice JavaScript SDK, handle the tokenWillExpire event and call device.updateToken with a freshly minted server token before expiry.
- For applications using Voice JS SDK v1, create a new token on your server and reinitialize the device with the new token before the prior token expires.
- Mint tokens with an appropriate ttl that balances security and session length. Tokens can be configured up to 24 hours but should be as short as feasible for your use case.
- Verify your token generation uses the correct API key and secret, includes a VoiceGrant, and sets a nonempty identity to avoid related authorization issues when refreshing.