LifeAstroAPILifeAstroAPI

← Troubleshooting

How to fix unauthorized (HTTP 401)

The request reached the API but carried no usable key.

What the API returns

{
  "error": {
    "code": "unauthorized",
    "message": "missing or invalid Authorization header — expected: Bearer <key>",
    "request_id": "770372810e5f2a70"
  }
}

Why it happens

  • No Authorization header, or the header is "Authorization: <key>" without the word Bearer.
  • The value sent is not a key: a placeholder such as YOUR_API_KEY, a key wrapped in quotes, or a key cut off while copying. The message then reads "the value sent is not a LifeAstroAPI key".
  • The key was read from an environment variable that is empty in this environment (CI, serverless, a new shell).
  • The key was revoked or rotated in Dashboard → API Keys, or it belongs to a different account.
  • The key was sent in the query string; it is read only from the Authorization or X-API-Key header.

How to fix it

  1. Send: Authorization: Bearer dv_live_… (one space after Bearer). An X-API-Key: dv_live_… header is accepted too.
  2. Print the key length at startup; an empty string means the variable is not set where the code runs.
  3. Open Dashboard → API Keys and confirm the key is listed and not revoked; create a new one if unsure and update the variable.

Should your code retry?

No. The request is deterministically rejected; fix the key, IP or parameters and send it again.

Confirm the fix

This call returns 200 when the key and header are right, and 401 when they are not. It is billed like any other call:

curl -s -o /dev/null -w "%{http_code}\n" "https://api.lifeastroapi.com/v1/panchang/tithi?date=2026-04-19&tz=Asia/Kolkata&lat=28.61&lon=77.21" -H "Authorization: Bearer $LIFEASTRO_API_KEY"

See all codes on the troubleshooting index and the error envelope on Errors. Still stuck? Email [email protected] with the request_id.