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
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