All Articles/Troubleshooting

Fixing 'Invalid API Key' Authentication Errors

Resolve 401 errors from incorrect or expired API keys.


The Error

HTTP 401 with "Invalid API key" means the API key in your request doesn't match any active key in Lognitor.

Common Causes

1. Wrong Key

You may be using an API key from a different project or organization. Go to Projects → your project → API Keys and copy the correct key.

2. Key Was Revoked

If someone on your team revoked the key, it stops working immediately. Generate a new key from the project settings.

3. Environment Variable Not Loaded

Terminal
# Verify the variable is set
echo $LOGNITOR_API_KEY

# Common mistakes:
# - .env file not loaded (missing dotenv config)
# - Variable name typo
# - Deployed without the environment variable

4. Extra Characters

Check for trailing whitespace, newlines, or quotes in your API key. A common issue with copy-paste:

Terminal
# Bad (has a trailing space)
LOGNITOR_API_KEY="lk_abc123 "

# Good
LOGNITOR_API_KEY=lk_abc123

5. Using the Wrong Header

The REST API expects X-API-Key, not Authorization:

Terminal
# Correct
-H "X-API-Key: your-key"

# Wrong
-H "Authorization: Bearer your-key"

Debug Mode

Enable debug: true in your SDK config. It will print the API key length and first few characters to help verify the correct key is being used.