| Method | Security Level | Use Case | Complexity |
|---|---|---|---|
| None | ⚠️ None | Development, testing, high-margin pricing | None |
| API Key | Basic | Internal apps, trusted clients | Low |
| HMAC | High | Public APIs, untrusted networks | Medium |
| Both | Maximum | High-security environments | Medium |
kora.toml file in the [kora.auth]
section.
In this document:
- API Key Authentication
- HMAC Authentication
- Combined Authentication
- Security Best Practices
- Exempt Endpoints
- Troubleshooting
API Key Authentication
Simple shared secret authentication using HTTP headers. You can generate a new API key using theopenssl command (or a similar command) in your terminal:
Server Configuration
- Add a
KORA_API_KEYto your .env (environment variables) (has priority) or - Add an
api_keyto yourkora.toml:
Client Implementation
Include the API key in thex-api-key header with every request:
cURL Example:
await. Save them as .mjs files, or set "type": "module" in your
package.json.
JavaScript Example using Kora SDK:
HMAC Authentication
Instead of sending an API key with every request, HMAC creates a unique cryptographic signature that proves you know a secret without revealing it. Each signature includes a timestamp and expires after 5 minutes, so intercepted requests can’t be replayed. Attackers can’t create new requests because they don’t have your secret key.Server Configuration
- Add
KORA_HMAC_SECRETto your .env (environment variables) (has priority) or - Add a global
hmac_secretto yourkora.toml(minimum 32 characters—you can generate one withopenssl rand -hex 32or similar):
How HMAC Works
- Client creates a message by concatenating:
{timestamp}{request_body} - Client signs the message using HMAC-SHA256 with the shared secret
- Client sends the request with timestamp and signature headers
- Server validates the signature and timestamp (must be within 5 minutes)
Client Implementation
To use HMAC client-side, you can use the Kora SDK or thecrypto library in
JavaScript:
- Create a timestamp
- Create the request body
- Create a message by concatenating the timestamp and body (e.g.,
message = timestamp + body) - Create a signature by signing the message with the HMAC secret (using the
crypto.createHmacmethod) - Send the request with the timestamp (
x-timestamp) and signature (x-hmac-signature) headers
crypto library:
Combined Authentication
You can enable both authentication methods simultaneously for maximum security:x-api-key, x-timestamp, and
x-hmac-signature headers.
Security Best Practices
- Use strong, random keys: Minimum 32 characters with high entropy
- Rotate regularly: Change keys periodically (monthly/quarterly)
- Secure storage: Use environment variables or secrets management (Railway secrets, AWS Secrets Manager, etc.)
- Never hardcode: Keep keys out of source code and logs
- Use HTTPS: Always use TLS in production to protect keys in transit
- Monitor access: Watch for unusual authentication patterns or repeated failures
Exempt Endpoints
Health checks are exempt from authentication. Kora exposesliveness as a
JSON-RPC method, and also serves it as a plain HTTP GET /liveness path that
the server converts into a liveness JSON-RPC call. The API key and HMAC
checks skip any request whose JSON-RPC method is liveness, so both forms work
without auth headers:
liveness method must stay enabled in
[kora.enabled_methods]
(it is enabled by default). If you disable it, both forms are rejected. Rate
limiting still applies to health checks.
Troubleshooting
A 401 response has an empty body, soresponse.json() and the Kora SDK fail
with SyntaxError: Unexpected end of JSON input. Check response.status before
parsing when you call Kora with fetch.
401 Unauthorized with API Key:
- Verify the API key is correct and matches server configuration
- Check that the
x-api-keyheader is being sent - Ensure no extra whitespace in the key
- Verify timestamp is current (within 5 minutes)
- Check that message construction matches:
{timestamp}{body} - Ensure HMAC secret matches server configuration
- Verify signature is lowercase hex