Overview
The No Longer Evil API uses API key authentication with Bearer tokens. All requests must include a valid API key in theAuthorization header.
Secure
SHA-256 hashed keys with one-time display on generation
Scoped
Granular permissions with read and write scopes
API Key Authentication
All API requests require authentication using an API key. Keys are managed through the Settings page and support granular permissions.Getting an API Key
- Navigate to Settings: Go to https://nolongerevil.com/settings
- Click API Keys tab: Access the API key management interface
- Generate New Key: Click “Generate New Key”
- Configure the key:
- Name: Descriptive name (e.g., “Home Assistant”, “Python Script”)
- Scopes: Select
read,write, or bothread: View device status and settingswrite: Control devices (temperature, mode, fan, etc.)
- Copy the key immediately: The full key is shown only once!
API Key Format
API keys follow this format:nle_012e7ffdd4ac7b83848c849c8417d8b632f076c2c10e63ebf69aae3f16b9a914
Using Your API Key
Include the API key in theAuthorization header as a Bearer token:
API Key Scopes
Scopes control what actions an API key can perform:| Scope | Description | Example Endpoints |
|---|---|---|
read | View device status and settings | GET /devices, GET /thermostat/{id}/status |
write | Control devices | POST /thermostat/{id}/temperature, POST /thermostat/{id}/mode |
Device Restrictions
When creating an API key, you can optionally restrict access to specific devices:- No restrictions (default): Access all devices you own or have shared access to
- Specific devices: Limit access to selected device serial numbers only
- Sharing access with third parties for specific devices
- Creating keys for specific rooms or zones
- Limiting scope of potentially compromised keys
Security Best Practices
How are API keys stored?
How are API keys stored?
API keys are hashed using SHA-256 before storage. The server never stores the plaintext key - only the hash is kept in the database. This means even if the database is compromised, the actual keys cannot be recovered.
What if my key is compromised?
What if my key is compromised?
- Immediately revoke the compromised key in Settings → API Keys
- Generate a new key with the same or different permissions
- Update your applications with the new key
Can I rotate keys?
Can I rotate keys?
Yes! Best practice is to rotate API keys periodically:
- Generate a new key with the same permissions
- Update your applications to use the new key
- Monitor usage of the old key (check “last used” timestamp)
- Once confirmed the old key is unused, revoke it
Key expiration
Key expiration
API keys support optional expiration dates. When creating a key, you can set it to expire after a certain period. This is useful for:
- Temporary access grants
- Time-limited integrations
- Compliance requirements
Rate Limiting
API keys are subject to rate limiting to protect the service:| Authentication Type | Limit | Window |
|---|---|---|
| User accounts (Clerk) | 100 requests | Per minute |
| API keys | 20 requests | Per minute |
Rate Limit Headers
All API responses include rate limit headers:Rate Limit Exceeded
When you exceed the rate limit, you’ll receive a429 Too Many Requests response:
Common Errors
401 Unauthorized
- Missing API key in Authorization header
- Invalid or expired API key
- Malformed Authorization header
Authorization: Bearer nle_your_api_key_here
403 Forbidden
- API key doesn’t have permission to access the device
- Device serial not in API key’s allowed devices list
- Insufficient scope (e.g., write action with read-only key)
Summary
| Feature | Details |
|---|---|
| Authentication Method | API key with Bearer token |
| Key Format | nle_ + 64 hex characters |
| Storage | SHA-256 hashed, never stored in plaintext |
| Scopes | read (view) and write (control) |
| Rate Limits | 20 req/min (API keys), 100 req/min (user accounts) |
| Expiration | Optional, configurable per key |
| Tracking | Last used timestamp |