• Blog
  • Docs
  • Pricing
  • We’re hiring!
Log inSign up
tr3ntg

tr3ntg

readback-api

API for readback.
Unlisted
Like
readback-api
Home
Code
4
backend
4
README.md
main.tsx
test-upload.html
Branches
2
Pull requests
Remixes
History
Environment variables
7
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.
Sign up now
Code
/
backend
/
README.md
Code
/
backend
/
README.md
Search
6/16/2025
Viewing readonly version of main branch: v55
View latest version
README.md

Backend API

This backend provides a speech synthesis API with usage tracking and authentication.

Structure

  • index.ts - Main Hono app with route definitions
  • middleware/auth.ts - Authentication middleware (RevenueCat + admin key)
  • middleware/usage.ts - Usage tracking and rate limiting middleware
  • database/usage.ts - Database operations for usage tracking

Features

Authentication

  • Admin access via ADMIN_ACCESS_KEY environment variable
  • Customer authentication via RevenueCat subscription verification
  • Authorization header format: Bearer {customer_id} or Customer {customer_id}

Usage Tracking

  • 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

Database Schema

The customer_usage_v1 table stores:

  • id - Auto-incrementing primary key
  • customer_id - Customer identifier from RevenueCat
  • character_count - Number of characters in the request
  • request_timestamp - ISO timestamp of the request
  • created_at - Database insertion timestamp

API Endpoints

POST /api/speech

Converts text to speech using LemonFox API.

Headers:

  • Authorization: Bearer {customer_id} or Authorization: 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 /api/usage

Get current month's usage statistics.

Headers:

  • Authorization: Bearer {customer_id} or Authorization: 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 }

GET /health

Health check endpoint.

Response:

{ "status": "ok", "timestamp": "2024-01-01T00:00:00.000Z" }

Environment Variables

  • ADMIN_ACCESS_KEY - Admin authentication key
  • REVENUECAT_API_KEY - RevenueCat API key
  • LEMONFOX_API_KEY - LemonFox API key

Rate Limiting

  • 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

Error Responses

  • 401 - Missing or invalid authorization
  • 403 - No active subscription or subscription verification failed
  • 429 - Monthly character limit exceeded
  • 500 - Internal server error
FeaturesVersion controlCode intelligenceCLIMCP
Use cases
TeamsAI agentsSlackGTM
DocsShowcaseTemplatesNewestTrendingAPI examplesNPM packages
PricingNewsletterBlogAboutCareers
We’re hiring!
Brandhi@val.townStatus
X (Twitter)
Discord community
GitHub discussions
YouTube channel
Bluesky
Open Source Pledge
Terms of usePrivacy policyAbuse contact
© 2025 Val Town, Inc.