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

tr3ntg

readback-api

API for readback.
Unlisted
Like
readback-api
Home
Code
5
backend
4
README.md
main.tsx
test-upload.html
test-url-extraction.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
/
database
/
README.md
Code
/
backend
/
database
/
README.md
Search
6/16/2025
Viewing readonly version of main branch: v76
View latest version
README.md

Database Module

This module handles usage tracking for the speech synthesis API.

Schema

customer_usage_v1 Table

ColumnTypeDescription
idINTEGER PRIMARY KEYAuto-incrementing unique identifier
customer_idTEXT NOT NULLCustomer ID from RevenueCat
character_countINTEGER NOT NULLNumber of characters in the request
request_timestampTEXT NOT NULLISO timestamp when request was made
created_atTEXT DEFAULT CURRENT_TIMESTAMPDatabase insertion timestamp

Indexes:

  • customer_id - For efficient customer lookups
  • request_timestamp - For efficient date range queries

Functions

initializeUsageTable()

Creates the usage tracking table if it doesn't exist. Called automatically when the module is imported.

recordUsage(customerId: string, characterCount: number)

Records a usage event for a customer.

getMonthlyUsage(customerId: string): Promise<number>

Returns the total character count used by a customer in the current calendar month.

getUsageHistory(customerId: string, limit?: number): Promise<UsageRecord[]>

Returns detailed usage history for a customer (useful for debugging or admin dashboards).

Usage Calculation

Monthly usage is calculated based on calendar months:

  • Start: 1st day of the month at 00:00:00
  • End: Last day of the month at 23:59:59.999

This means customers get a fresh allowance on the 1st of each month, regardless of when they subscribed.

Performance Considerations

  • Indexes on customer_id and request_timestamp ensure fast queries
  • Monthly usage queries use date range filtering for efficiency
  • Table name includes version suffix (_v1) for easy schema migrations
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.