---
"@context": https://schema.org
"@type": TechArticle
"@id": https://www.twilio.com/docs/api/errors/51131#article
headline: "51131: Twilsock: Authentication failed"
url: https://www.twilio.com/docs/api/errors/51131
inLanguage: en
dateModified: 2026-06-09T11:00:42.000Z
author:
  "@type": Organization
  name: Twilio Developer Education Team
publisher:
  "@type": Organization
  name: Twilio
---

# 51131: Twilsock: Authentication failed

Log Level: ERROR

## Description

This error occurs when Twilsock cannot authenticate the Access Token presented by a client SDK connection. Access Tokens are short-lived JWTs for Twilio client-side SDKs, and authentication failures are commonly caused by incorrect credentials, invalid token structure, or token timestamp issues.

### Possible causes

* The token was generated with an incorrect or mismatched `Account SID`, `API Key SID`, or `API Secret`. ([help.twilio.com](https://help.twilio.com/articles/115015890207-Troubleshooting-Invalid-Access-Tokens))
* Test credentials were used to create the token. Access Tokens must use live credentials. ([help.twilio.com](https://help.twilio.com/articles/115015890207-Troubleshooting-Invalid-Access-Tokens))
* The token was created for a different account or subaccount than the Conversations Chat Service or Sync Service the client is trying to use. ([help.twilio.com](https://help.twilio.com/articles/115015890207-Troubleshooting-Invalid-Access-Tokens))
* The token did not include the correct product grant for the SDK you are using. Conversations requires a `ChatGrant` with your Conversation Service SID. Sync requires a `SyncGrant` with your Sync `serviceSid`.
* The client sent the token in the wrong format, such as a JSON object instead of the raw JWT string. ([help.twilio.com](https://help.twilio.com/articles/115015890207-Troubleshooting-Invalid-Access-Tokens))
* The token is outside its valid time window. Access Tokens have a maximum lifetime of 24 hours. ([help.twilio.com](https://help.twilio.com/articles/115015890207-Troubleshooting-Invalid-Access-Tokens))

### Possible solutions

* Regenerate the token on your server with the correct live `Account SID`, `API Key SID`, and `API Secret` from the same Twilio account that owns the target service. ([help.twilio.com](https://help.twilio.com/articles/115015890207-Troubleshooting-Invalid-Access-Tokens))
* Use a Twilio server-side helper library to create the token and grants instead of building the JWT manually. ([help.twilio.com](https://help.twilio.com/articles/115015890207-Troubleshooting-Invalid-Access-Tokens))
* For Conversations, add a `ChatGrant` that includes the correct Conversation Service SID. For Sync, add a `SyncGrant` with the correct `serviceSid`.
* Return the token to the client as a plain JWT string and initialize the SDK with that value. ([help.twilio.com](https://help.twilio.com/articles/115015890207-Troubleshooting-Invalid-Access-Tokens))
* Reissue tokens before they expire. If your Conversations client enters the `Denied` connection state, fetch a new token and reconnect.
* Review the Twilio Console Debugger or Workbench to inspect related errors and identify any more specific token validation failures.

#### Additional resources

* [Access Tokens](/docs/iam/access-tokens)
* [Create Access Tokens for Conversations](/docs/conversations/create-tokens)
* [Issuing Sync Tokens](/docs/sync/identity-and-access-tokens)
