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

# 51215: Twilsock: Unauthorized

Log Level: ERROR

## Description

This error means Twilsock rejected the client connection because it could not authorize the Access Token you supplied. Use short-lived Access Tokens to authenticate client-side SDKs. If authorization fails, the token is usually missing, invalid, expired, or issued with the wrong credentials or grants.

### Possible causes

* Your application generated the token with the wrong Account SID, API Key SID, or API Secret, or mixed credentials from a different account or subaccount. ([help.twilio.com](https://help.twilio.com/articles/115015890207-Troubleshooting-Invalid-Access-Tokens))
* The token is expired, not yet valid, or your client continued using it after its lifetime ended. Access Tokens are short-lived and can be configured for up to 24 hours.
* The token does not include the correct grant or `identity` for the SDK you are initializing. Conversations and Sync both require you to issue the token on your server with the appropriate user identity and product grant.
* Your client passed the Access Token in the wrong format, such as a JSON object instead of the token string itself. ([help.twilio.com](https://help.twilio.com/articles/115015890207-Troubleshooting-Invalid-Access-Tokens))
* In Conversations, the token authorizes access to the underlying Chat Service. If you issued the token for the wrong service context or user, the connection can be denied.

### Possible solutions

* Generate a new Access Token on your server using your live Account SID, a valid API Key SID, and the matching API Secret. Do not use test credentials for Access Tokens. ([help.twilio.com](https://help.twilio.com/articles/115015890207-Troubleshooting-Invalid-Access-Tokens))
* Make sure the token includes the correct product grant and `identity` for the client you are connecting. For Conversations, use the correct Chat Service SID. For Sync, add the Sync grant before returning the token to the client.
* Pass the token to the SDK as the raw token string returned by your backend. If your backend responds with JSON, extract the token value before you initialize the client. ([help.twilio.com](https://help.twilio.com/articles/115015890207-Troubleshooting-Invalid-Access-Tokens))
* Refresh the token before it expires in long-running clients. Handle events such as `tokenAboutToExpire`, `tokenExpired`, or a `Denied` connection state, then request a fresh token and update the client.
* If the problem continues, verify that the user should be allowed to connect and that your backend is issuing a token for the correct account, service, and user identity.

#### 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)
