API Authentication
How TG Filter authenticates bots, API consumers and dashboard visitors.
API Keys
API requests authenticate with a key sent in an Authorization: Bearer <key> header, or equivalently an X-Api-Key header. This applies to the decision log on the app host and to the filter's /moderate endpoints alike. A key is shown once at creation; only its hash is stored. Each key carries capability scopes: read is implied, and write must be requested explicitly, which covers overrides and key management. Rotating a key preserves its scopes and leaves the old key valid for 24 hours so you can swap without downtime.
Two scopes
Read for the decision log. Write for overrides and key management, granted only if asked for.
Graceful rotation
A rolled key keeps working for 24 hours, then expires on its own.
Telegram Webhook
setWebhook registers a secret token. Telegram echoes it in the X-Telegram-Bot-Api-Secret-Token header on every request, and the server compares it in constant time, rejecting any mismatch with 401. A key that is revoked, expired or whose owner has left Pro returns 401 INVALID_KEY rather than silently falling back to a free view.
curl "https://api.telegram.org/bot<token>/setWebhook\
?url=https://tgfilter.co/api/webhooks/telegram\
&secret_token=<secret>"Constant time
The secret comparison does not leak length or prefix information.
Fails closed
No configured secret means every request is rejected, not accepted.
Dashboard Authentication
Dashboard sessions are server-side records with an expiry, issued only after password verification, with optional TOTP as a second factor. Roles (admin, user, partner, developer) decide which sections load; the API documentation is readable by any signed-in user. A downgrade to Free takes effect on the next request, not at the end of the session.
Server-side sessions
The cookie carries no role or plan; both are looked up on the server.
Two factors
TOTP is available for any account that wants it.
Error Handling
Errors are JSON with a short machine-readable code and a human sentence, never a stack trace. Missing key gives 401 MISSING_KEY, an unusable key gives 401 INVALID_KEY, a key without the needed scope gives 403 SCOPE_REQUIRED, too many calls gives 429 RATE_LIMITED with a retry hint, oversized bodies give 413, and unknown routes give 404.
Machine-readable
Every error carries a stable code you can branch on.
Rate limited per key
60 requests per minute by default, with the remaining count returned on each response.