Skip to content

Make lab-report OCR scan rate limit configurable via env var #985

Description

@rkerian

Problem

The lab-report OCR scan endpoint (/api/labs/ocr/extract) hardcodes its rate limit at 6 scans/hour (EXTRACT_LIMIT_PER_HOUR in
src/app/api/labs/ocr/extract/route.ts, lines 67-68), with no way to raise it. For a self-hoster batch-scanning a stack of lab reports after a doctor
visit, this throttles hard and there's no config path around it — you just wait an hour, repeatedly, or manually clear the labs-ocr: row in the
rate_limits table.

Proposed solution

Make EXTRACT_LIMIT_PER_HOUR operator-tunable via an environment variable, following the exact pattern already used for the sibling document-AI bucket (DOCUMENT_AI_LIMIT_PER_HOUR in src/lib/documents/ai-route-support.ts — default 6, clamped 1-1000, falls back to the default on unset/non-numeric). Something like LABS_OCR_LIMIT_PER_HOUR with the same resolver shape would be a drop-in, low-risk change and consistent with how the rest of the AI egress surfaces are already configured.

Alternatives considered

Manually deleting the rate_limits row for labs-ocr: via psql works as a stopgap but isn't something a typical self-hoster should have to do,
and it doesn't help mid-scanning-session — you have to notice you're throttled, drop into the DB, then resume. This also isn't practical when there are multiple users running into the throttling issue.

Affected surface

Self-hosting / Docker

Additional context

No response

Pre-flight checks

  • I confirmed this is not a duplicate of an existing feature request.
  • I'm proposing a feature, not asking a usage question (those go to Discussions or the docs).

Activity

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

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions