# auth token expired: Auth token expired

> The JWT the connection presents passed its exp claim, so the server answers 401 until you mint a new token.

Source: https://sqlly.app/errors/libsql/token-expired
Last updated: 2026-11-30
License: Text and data [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/) (credit SQLly, sqlly.app); code and SQL snippets [MIT](https://opensource.org/license/mit). [Details](https://sqlly.app/license).
Note: Quoted error message text belongs to its database vendor.

- Error: `auth token expired`
- Category: Authentication and tokens

Error message:

```text
401 Unauthorized: auth token is invalid or expired
```

## What it means

Turso auth tokens are JWTs with an expiry. `turso db tokens create` tokens never expire by default: an expiry exists only when the token was minted with `--expiration` (or is a platform token with a built-in lifetime). When the `exp` claim passes, the server rejects the token with 401. The failure shows up as `SERVER_ERROR: Server returned HTTP status 401 Unauthorized`, and the cause is visible in the token itself.

## Common causes

- The token was minted with `--expiration` and aged past it, and the config was never refreshed.
- A CI secret stores a token with a short expiry and the job runs after it lapsed.
- A long-lived server process loaded a token at startup and never reloads it.

## How to fix it

1. Mint a fresh token and update the config:

   ```sql
   turso db tokens create mydb --expiration 30d
   ```
2. For services, refresh the token at startup and periodically instead of baking it in:

   ```sql
   // re-read env or re-mint on 401 before giving up
   if (String(err).includes('401')) token = await mintToken();
   ```
3. Check the expiry inside the current token:

   ```sql
   echo "$LIBSQL_TOKEN" | cut -d. -f2 | base64 -d 2>/dev/null | grep -o '"exp":[0-9]*'; date +%s
   ```

## Reproduce it safely

```sql
Honest repro needs a cloud database: create one with `turso db create repro-exp`, mint a token with `--expiration 1s`, wait a few seconds, then connect. The server answers 401. Offline you can verify only the decode step: a token with a past `exp` is demonstrably expired without any server.
```

## How SQLly helps

SQLly keeps the token beside the connection, so after re-minting you update it once in the connection settings and every later query runs with the new token, the same edit your app config needs, with immediate feedback that the new token works.

## Questions

### How long do Turso auth tokens last?

Database tokens from `turso db tokens create` never expire unless you pass `--expiration` when minting them. If a token has an `exp` claim that passed, it was minted with a deliberate expiry.

### How do I rotate an expired or leaked Turso token?

Mint a fresh one with `turso db tokens create mydb --expiration 30d`, update every consumer, then revoke the old one with `turso db tokens invalidate mydb` so copies in old configs stop working.

## Related errors

- [`401 Unauthorized`](https://sqlly.app/errors/libsql/unauthorized-401): 401 Unauthorized: bad or missing auth token
- [`403 Forbidden`](https://sqlly.app/errors/libsql/forbidden-403): 403 Forbidden: no permission for this resource

The code and message text are from the [libSQL / Turso documentation](https://docs.turso.tech/).
