Log inStart Free Trial
easyCoexistence Official APIs

TikTok error 40131: authentication error at the token endpoints

TikTok error 40131 is an authentication error from /tt_user/oauth2/token/ or /tt_user/oauth2/refresh_token/, the endpoints that issue and renew TikTok account tokens. TikTok names three causes: an incorrect app ID or secret, an expired authorization code, or a refresh token that is invalid or expired. The endpoint that returned it shows which input to check first.

easyCoexistence makes both token calls for you: it exchanges the authorization code as soon as TikTok sends you back from its login, and renews the 24-hour access token with the refresh token on its own.

40131

TikTok's return code for an authentication error at /tt_user/oauth2/token/ or /tt_user/oauth2/refresh_token/.

10 minutes

How long an Accounts API authorization code is valid; each code can be used only once.

1 year

How long a refresh token is valid; after it expires, the owner has to authorize the app again.

404

The HTTP error TikTok's appendix says can come from calling /tt_user/oauth2/refresh_token without its trailing slash.

What does error 40131 mean?

A request to get or renew a TikTok account token failed authentication. The return code appendix ties 40131 to two endpoints: /tt_user/oauth2/token/, which exchanges an authorization code for tokens, and /tt_user/oauth2/refresh_token/, which renews the access token. Its example message is "Authorization code is expired." It lists three common causes:

  • The app ID or secret is incorrect.
  • The authorization code has expired.
  • The refresh token is invalid or expired.

How do you fix it on /tt_user/oauth2/token/?

Check the three inputs TikTok names for this endpoint: the app ID, the secret and the authorization code. The ID and secret are in the TikTok API for Business portal under My Apps, App Detail, Basic Information. The code lasts 10 minutes and works once, so exchange it as soon as the redirect arrives, and start the authorization again if it is too old. The redirect_uri sent with it must also match the redirect URL set in the app.

How do you fix it on /tt_user/oauth2/refresh_token/?

Send a valid refresh token. Confirm the request carries the refresh token most recently stored for that account, along with the right app ID and secret. If the refresh token has expired or is no longer valid, TikTok's appendix says to have the user authorize the app again, which issues a new access token and a new refresh token.

Which related codes name a single cause?

The same appendix lists narrower codes for some of these cases, each with its own description:

  • 40103: the refresh token has expired, and the user has to authorize the app again.
  • 40107: the refresh token is invalid or incorrect.
  • 40110: the authorization code was cancelled, already used or has expired.
  • 40113: the app is blocked or does not exist, with an incorrect app ID or secret as the common causes.

Common mistakes

  • Dropping the trailing slash. TikTok's appendix notes that /tt_user/oauth2/refresh_token without the final / can return 404 page not found rather than a return code.
  • Exchanging an authorization code twice. It works once and for 10 minutes, so a reloaded or retried callback cannot use it again.
  • Asking the owner to authorize again before checking the app ID and secret. If those are wrong, a new authorization fails in the same place.
  • Using credentials from a different app. The app ID and secret must belong to the app the account owner authorized.
Doing this with EasyCoexistence

If TikTok refuses a renewal, the tool hands Claude, ChatGPT or your own code TikTok's code and message, and connecting the account again from the dashboard starts a new authorization. US$ 9 to US$ 0.75 per connection per month, falling as you add connections, with the first 3 days free.

easyCoexistence is a multichannel API and MCP server that connects AI agents such as Claude and ChatGPT to WhatsApp, Instagram, TikTok, Facebook and more. On WhatsApp it uses Coexistence: the business keeps using its number in the WhatsApp Business app while the AI works through Meta's official API.

Frequently asked questions

Which endpoints return TikTok error 40131?

/tt_user/oauth2/token/, which turns an authorization code into tokens, and /tt_user/oauth2/refresh_token/, which renews the access token.

Where are the TikTok app ID and secret?

In the TikTok API for Business portal, under My Apps, then App Detail, then Basic Information.

Does 40131 always mean the owner has to reconnect?

No. A wrong app ID or secret is fixed in the app's own settings. A new authorization is needed when the authorization code or the refresh token has expired.

How long does a TikTok authorization code last for the token request?

10 minutes, and only for one exchange. After that, TikTok's guidance is to start the authorization steps again.

Keep reading

Connect your first channel in two minutes.

No platform reviews to wait for. Connect WhatsApp, Instagram, TikTok or another channel, then ask your AI to post, reply or report, and watch it work.

  • 3 days free
  • Cancel any time
  • Official APIs only
  • Monitored 24/7

Verified on