20157: Expiration Time Exceeds Maximum Time Allowed
API, IAM
ERROR
This error occurs when the expiration time used while creating an Access Token JWT exceeds 24 hours, which is the maximum allowed lifetime. This behavior is documented on the error page and the Access Tokens overview, which states tokens are "configurable for up to 24 hours."
- The
ttlparameter provided when generating the Access Token is greater than 86400 seconds (24 hours). The Access Tokens overview sets a 24-hour maximum and specifiesttlis expressed in seconds. - The token's
expclaim is set so that its lifetime exceeds 24 hours relative to issuance; Access Tokens areJWTs that include anexpclaim as shown in Twilio's examples. - Passing time values in milliseconds instead of seconds for
ttl, inadvertently creating a value above the 24-hour maximum. Twilio materials indicatettlis in seconds and blog guidance notes the maximum must be given as 86400 seconds.
- Set the Access Token
ttlto a value at or below 86400 seconds, and in general keep it as short as feasible for your application (best practice noted by Twilio). - If you manually construct tokens, compute
expso that it does not exceed 24 hours after issuance, or rely on the helper to setexpbased onttl. Twilio's examples show theexpclaim and parameterization forttl. - Ensure you are providing
ttlin seconds, not milliseconds; for example, 3600 for one hour or 86400 for the maximum. Twilio documentation specifiesttlis in seconds, and the Twilio blog reiterates the 24-hour limit as 86400 seconds. - Implement short-lived tokens with periodic refresh in clients where applicable; Twilio recommends shorter token lifetimes and details token refresh patterns (for example, in Sync SDK guidance).