LINE Messaging API · error code

LINE error 401: Authentication failed

ConfigurationHTTP 401401 and channel access token errors

Last verified against LINE Developers - Messaging API reference (error responses)

What LINE returns
Authentication failed due to the following reason: XXX <detail varies>

What error 401 means

The status codes table defines 401 Unauthorized on the Messaging API in one sentence: "Valid channel access token is not specified." The body carries the templated string "Authentication failed due to the following reason: XXX", where LINE substitutes the specific reason - a malformed authorization header, an invalid token, an expired token, a revoked token. Whatever the substitution says, the class of problem is constant: the Authorization: Bearer {channel access token} header on this request did not authenticate against this channel.

LINE has several token types, and knowing which one you hold determines the fix. Channel access tokens v2.1 are issued against a JWT assertion with a lifetime you choose, up to 30 days, and a cap of 30 valid tokens per channel. Short-lived tokens last 30 days, same 30-token cap. Stateless tokens last 15 minutes and can be issued without limit. Long-lived tokens are issued from the LINE Developers Console. All of them die - by expiry, by explicit revocation, or by being crowded out during rotation - so a 401 in a system that "worked yesterday" almost always means a token aged out or was rotated without a redeploy.

Channel identity is the other big trap. A token authenticates one channel; user IDs, rich menu IDs, and webhook events are scoped to that same channel. Pasting a token from a different channel (or from a LINE Login channel of the same provider) produces 401s or, worse, Failed to send messages on IDs that don't exist in the token's channel. Never debug a 401 without first answering: which channel issued this token, and is that the channel this bot belongs to?

Unlike a rate-limit 429, retrying a 401 without changing credentials is pointless - the request will fail identically until the token is replaced. Fail fast, alert, and rotate.

What it looks like

HTTP/1.1 401 Unauthorized

{
  "message": "Authentication failed due to the following reason: invalid token. Confirm that the access token in the authorization header is valid"
}

Why it happens

  • The channel access token expired - v2.1 and short-lived tokens have finite lifetimes (up to 30 days), stateless tokens last 15 minutes.
  • The token was revoked, or rotated by another deployment while this instance kept the old value.
  • The Authorization header is malformed: missing the Bearer prefix, carrying quotes or whitespace, or empty because an env var didn't load.
  • The token belongs to a different channel (staging, another bot, or a LINE Login channel) than the one you're calling on behalf of.
  • The channel secret used to mint v2.1 assertions was reset, so newly issued tokens come from a stale identity and fail.

How to fix LINE error 401

  1. 1Reproduce with curl using the exact header your service sends; confirm the format is Authorization: Bearer {token} with no quotes or trailing newline.
  2. 2Verify the token against the matching verify endpoint (/v2/oauth/verify or /oauth2/v2.1/verify) - it distinguishes expired, malformed, and non-existent tokens.
  3. 3Issue a fresh token for the correct channel and confirm one API call (e.g. GET /v2/bot/info) succeeds before redeploying everywhere.
  4. 4Check which channel the token came from in the LINE Developers Console and match it to the channel that owns the webhook and user IDs you're using.
  5. 5Search deploy history for secret rotation events - a reset channel secret silently invalidates the token pipeline built on it.
  6. 6Add startup validation: on boot, call a cheap authenticated endpoint and crash loudly on 401 instead of failing at first user message.

How to stop it recurring

Automate the token lifecycle: issue v2.1 or stateless tokens on a schedule, store them in a secrets manager keyed by channel and environment, and rotate with overlap (issue new, verify, switch, revoke old). Alert on the first 401 rather than the thousandth - authentication failures are binary, and every retried call is wasted. Keep per-channel labeling strict so a token can never be deployed against the wrong bot; see rate limits for the token-issuance ceilings that shape rotation design.

Official reference: LINE Developers - Messaging API reference (error responses). See all LINE error codes or the LINE limits and quotas.

Related codes

Error 401 - quick answers

What does LINE error 401 mean?

The status codes table defines 401 Unauthorized on the Messaging API in one sentence: "Valid channel access token is not specified." The body carries the templated string "Authentication failed due to the following reason: XXX" , where LINE substitutes the specific reason - a malformed authorization header, an invalid token, an expired token, a revoked token.

How do I fix LINE error 401?

1. Reproduce with curl using the exact header your service sends; confirm the format is Authorization: Bearer {token} with no quotes or trailing newline. 2. Verify the token against the matching verify endpoint (/v2/oauth/verify or /oauth2/v2.1/verify) - it distinguishes expired, malformed, and non-existent tokens. 3. Issue a fresh token for the correct channel and confirm one API call (e.g. GET /v2/bot/info) succeeds before redeploying everywhere. 4. Check which channel…

Stop debugging LINE by hand

Connect the channel through Conferbot: tokens, webhooks and retries are handled, failures show as readable status.