Skip to content

Sync API: add subscription gate and fair-use tracking to prevent free-rider abuse #5854

Closed

Description

@beastoin

The sync endpoint (POST /v1/sync-local-files) has zero subscription checks, zero rate limiting, and zero fair-use tracking. Non-subscribers are uploading bulk audio and triggering the full LLM processing pipeline at our cost.

Current Behavior

  • Any authenticated user can call /v1/sync-local-files unlimited times with no subscription check.
  • Each upload triggers 8-9 LLM calls per audio segment via process_conversation(): structured extraction (gpt-5.1), action items (gpt-5.1), memories, trends, goals, folder assignment, app suggestion + execution, embeddings.
  • The same LLM pipeline runs for sync as for real-time recording, but sync has none of the gates that real-time has.

Expected Behavior

Sync should enforce the same plan limits and fair-use rules as real-time recording, with logging to distinguish the source.

Solution: Treat Sync the Same as Real-Time

Principle: sync audio costs the same to process as real-time audio — same plan limits, same fair-use pool, just log the source.

Phase 1 — Pre-check gate (top of endpoint, before any processing):

  • has_transcription_credits(uid) → 402 if monthly limit reached
  • is_hard_restricted(uid) → 429 if fair-use restricted
  • rate_limit_dependency(endpoint="sync_local_files", requests_per_window=20, window_seconds=3600)
  • Cost: one Firestore read + one Redis read. Blocks over-limit users with zero wasted compute.

Phase 2 — Fair-use recording (after VAD, before Deepgram):

  • Calculate total speech duration from VAD segments
  • Call record_speech_ms(uid, total_speech_ms, source='sync') — same Redis buckets as real-time, same rolling windows (daily 2h, 3-day 8h, weekly 10h)
  • Check check_soft_caps(uid) and trigger classifier if needed
  • Source='sync' is logged for traceability but does NOT create separate enforcement

Phase 3 — Usage recording (after processing completes):

  • Call record_usage(uid, transcription_seconds, speech_seconds) — same subscription budget as real-time

Why shared pool is correct:

  • Cost to Omi is identical regardless of ingestion path
  • Separate pools would let abusers double their effective free tier by splitting load
  • The LLM classifier already detects bulk non-personal patterns (audiobook chapters, podcast episodes) from conversation metadata — works for sync-created conversations identically since they go through the same process_conversation()

Affected Areas

File Line Change
backend/routers/sync.py 706 Add has_transcription_credits + is_hard_restricted pre-check
backend/routers/sync.py ~747 After VAD segments, record speech_ms with source='sync' + check soft caps
backend/routers/sync.py after processing Call record_usage for subscription tracking
backend/utils/fair_use.py record_speech_ms Add source: str = 'realtime' param, add log line for traceability

No changes needed to: subscription.py, fair_use_classifier.py, Redis schema, Firestore schema.


by AI for @beastoin

Activity

  1. added
    p1
    on Mar 20, 2026
  2. beastoin commented on Mar 20, 2026

    @beastoin
    CollaboratorAuthor

    Update from @anthropic-yuki (fair-use system author):

    The fair-use system is designed around continuous speech-hour tracking with rolling windows and LLM classification — it does NOT cover sync API and shouldn't be extended to cover it. Sync uploads are a different pattern (file-based, bursty, storage+LLM cost driven vs transcription cost driven).

    Revised recommendation: separate Redis-based daily limiter for sync, reusing the daily budget pattern from record_dg_usage_ms() / is_dg_budget_exhausted() in fair_use.py — same INCRBY + midnight TTL pattern, tracking bytes or minutes instead of ms.

    Updated proposal:

    • Free users: daily sync budget (e.g. 30 min audio or ~200 MB), hard reject at threshold with 429 + upgrade prompt
    • Unlimited subscribers: higher daily budget (e.g. 4h audio), hard reject at threshold
    • All users: per-UID rate limit (20 req/hr) to prevent rapid-fire
    • Implementation: Redis key sync_budget:{uid}:{YYYYMMDD}, INCRBY audio duration after VAD, TTL to midnight UTC

    This is simpler than integrating with fair-use and more appropriate for the bursty file-upload pattern.


    by AI for @beastoin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    p1

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions