20151: Authentication Failed
API
ERROR
This error indicates that authentication with the provided JWT failed when Twilio attempted to validate the token for an API/SDK request. It is listed in Twilio's Error and Warning Dictionary as Authentication Failed under API errors. Twilio Access Tokens are JWTs used to authenticate client-side SDKs, and incorrect or invalid tokens will fail authentication.
- Invalid
JWTheader. - Invalid
issorsubvalues in the token. - Invalid claim set in the token payload.
- Token time-related issues, such as expiration set in the future, expired or invalid expiration, or expiration exceeding the maximum allowed lifetime.
- Re-generate the Access Token on your server using the correct API Key SID and secret, and ensure the token header and payload are properly formed:
typmust beJWT,algmust beHS256, andctymust betwilio-fpa;v=1; include required claims likeiss(API Key SID),sub(Account SID),iat, and appropriategrants. - Verify token lifetime settings: set
expwithin the permitted window (tokens are short‑lived and have a maximum age of 24 hours) and avoid settingnbfin the future relative to the server time. If needed, reissue a fresh token. - Use the Twilio Console Debugger and error logs to inspect the specific event and any accompanying, more granular token error codes to pinpoint the underlying cause.