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

# 51130: Twilsock: Token is invalid!

Log Level: ERROR

## Description

This error occurs when your client tries to connect through Twilsock with an Access Token that is not a valid Twilio Access Token or cannot be parsed as one. Twilio Access Tokens are short-lived `JWT` credentials for client-side SDKs, and they must have a valid header, payload, signature, and product grant.

### Possible causes

* The value you passed is not a Twilio Access Token, such as a malformed `JWT` or a different credential type like an Auth Token or another token format.
* The token was generated with the wrong credential combination, such as an Account SID, API Key, or API Secret that do not belong together, or it was created with Test Credentials instead of Live Credentials. ([help.twilio.com](https://help.twilio.com/articles/115015890207-Troubleshooting-Invalid-Access-Tokens))
* The token was passed to the SDK as something other than a plain string, such as a JSON object. ([help.twilio.com](https://help.twilio.com/articles/115015890207-Troubleshooting-Invalid-Access-Tokens))
* The token payload is missing a valid `grants` object or the grant does not match the SDK you are initializing. For example, Conversations tokens need the chat grant, and Sync tokens need a `SyncGrant` with a `serviceSid`.
* If you are using Conversations, an invalid token can cause the client connection state to become `denied` until you provide a fresh valid token.

### Possible solutions

* Generate a new Access Token on your server with a Twilio helper library. Use your Live Account SID, a valid API Key SID, and the matching API Secret. ([help.twilio.com](https://help.twilio.com/articles/115015890207-Troubleshooting-Invalid-Access-Tokens))
* Verify the token structure before sending it to the client. The header must include `typ`=`"JWT"`, `alg`=`"HS256"`, and `cty`=`"twilio-fpa;v=1"`. The payload should include `iss`, `sub`, `iat`, `exp`, and at least one valid product grant.
* Pass the token to your SDK as the raw serialized `JWT` string, not as a wrapped JSON object or another credential type. ([help.twilio.com](https://help.twilio.com/articles/115015890207-Troubleshooting-Invalid-Access-Tokens))
* If you are connecting to Conversations, create the token with the correct chat grant, Chat Service SID, and `identity`. Avoid reserved characters in the `identity` value.
* If you are connecting to Sync, include a `SyncGrant` with the correct `serviceSid` for your Sync Service.
* Keep tokens short-lived. If your client is rotating tokens, fetch a fresh token from your server and update the client before the old token expires.
* Review the Twilio Debugger or Error Logs for the failing request so you can inspect the error code, description, and log properties tied to the connection attempt.

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