
Unlisted
Like
readback-api
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.
Viewing readonly version of main branch: v19View latest version
This backend provides a speech synthesis API with usage tracking and authentication.
index.ts- Main Hono app with route definitionsmiddleware/auth.ts- Authentication middleware (RevenueCat + admin key)middleware/usage.ts- Usage tracking and rate limiting middlewaredatabase/usage.ts- Database operations for usage tracking
- Admin access via
ADMIN_ACCESS_KEYenvironment variable - Customer authentication via RevenueCat subscription verification
- Authorization header format:
Bearer {customer_id}orCustomer {customer_id}
- Monthly character limit: 4,000,000 characters per customer
- Calendar month-based tracking (resets on 1st of each month)
- Automatic usage recording for successful requests
- Usage stats endpoint for customers to check their limits
The customer_usage_v1 table stores:
id- Auto-incrementing primary keycustomer_id- Customer identifier from RevenueCatcharacter_count- Number of characters in the requestrequest_timestamp- ISO timestamp of the requestcreated_at- Database insertion timestamp
Converts text to speech using LemonFox API.
Headers:
Authorization: Bearer {customer_id}orAuthorization: Bearer {admin_key}
Body:
{
"voice": "voice_name",
"input": "text to convert"
}
Response:
{
"audio": "base64_encoded_audio",
"word_timestamps": [
{
"word": "hello",
"start": 0.0,
"end": 0.5
}
]
}
Get current month's usage statistics.
Headers:
Authorization: Bearer {customer_id}orAuthorization: Bearer {admin_key}
Query Parameters (admin only):
customer_id- Check usage for specific customer
Response:
{
"monthly_limit": 4000000,
"current_usage": 150000,
"remaining_characters": 3850000,
"usage_percentage": 4
}
Health check endpoint.
Response:
{
"status": "ok",
"timestamp": "2024-01-01T00:00:00.000Z"
}
ADMIN_ACCESS_KEY- Admin authentication keyREVENUECAT_API_KEY- RevenueCat API keyLEMONFOX_API_KEY- LemonFox API key
- 4,000,000 characters per calendar month per customer
- Admin users have unlimited usage
- Requests that would exceed the limit are rejected with HTTP 429
- Usage is tracked after successful requests only
401- Missing or invalid authorization403- No active subscription or subscription verification failed429- Monthly character limit exceeded500- Internal server error