Getting an API Key
API keys are created and managed from the AuditRails Dashboard:- Sign in at app.auditrails.io.
- Click API Keys in the left sidebar.
- Click Create API Key, enter a descriptive name, and select the project to scope it to.
- Copy the key from the confirmation screen immediately.
Key Formats
AuditRails issues two distinct key formats with different behaviors:Making Authenticated Requests
Pass your API key in theAuthorization header as a Bearer token on every request:
curl Example
SDK Initialization
All official SDKs accept the API key at client construction time. Use an environment variable rather than hardcoding the key in source code.Security Best Practices
-
Use environment variables. Never hardcode an API key in source code, config files committed to version control, or client-side bundles. Use your platform’s secrets management system (e.g. AWS Secrets Manager, GitHub Actions secrets, Doppler,
.envfiles excluded from git). -
One key per environment. Create separate keys for production, staging, and development. Use
at_live_keys only for production andat_test_keys for development and CI. This limits the blast radius if a key is leaked. - Rotate keys periodically. Generate a new key before revoking the old one to achieve zero-downtime rotation. Update your secrets store, deploy the new key, then revoke the old one from the Dashboard.
- Revoke immediately if compromised. If you suspect a key has been exposed — in logs, a repository, or a leaked environment — revoke it from Dashboard → API Keys immediately. The SHA-256-hashed storage model means the raw key is not in AuditRails’ database, but revocation blocks any further use.
-
Never use test keys in production.
at_test_keys are throttled and share a separate rate-limit pool. They should never receive real user traffic.
Authentication Error Responses
All authentication failures return HTTP401 Unauthorized with a JSON body. The code field tells you exactly what went wrong:
Example Error Response
All five error codes return the same HTTP status (
401). Use the error.code field in your error handling logic to distinguish between a missing header (likely a misconfiguration) and a revoked key (likely a security event that requires immediate attention).