Skip to content

feat(auth): source plan limits from gateway headers#539

Merged
0237h merged 1 commit into
mainfrom
feat/plan-limits-from-headers
May 13, 2026
Merged

feat(auth): source plan limits from gateway headers#539
0237h merged 1 commit into
mainfrom
feat/plan-limits-from-headers

Conversation

@0237h
Copy link
Copy Markdown
Collaborator

@0237h 0237h commented May 13, 2026

Summary

  • Replace the static PLANS env / --plans CLI plan map with three trusted request headers set by the upstream gateway:
    • x-token-api-batch-size — max array length on any query parameter
    • x-token-api-items-returned — max limit value
    • x-token-api-lowest-time-parameter — minimum OHLCV interval granularity (e.g. 1h rejects 1m/5m/10m/30m)
  • Requests without these headers (local development, direct pod hits) bypass plan enforcement.
  • The X-Plan header is no longer read by the service.
  • Unlocks per-user custom limits for enterprise plans without redeploying the API.

Test plan

  • bun test src/ — 269 pass, 0 fail
  • bunx tsc --noEmit clean
  • Local smoke test against running server:
    • x-token-api-items-returned: 5 + limit=10403
    • x-token-api-lowest-time-parameter: 1d + interval=1h (1m) → 403
    • x-token-api-lowest-time-parameter: 1d + interval=1d200
    • x-token-api-batch-size: 2 + 3-valued address403
    • No headers → no plan-limit rejection

🤖 Generated with Claude Code

Replace the static PLANS env-driven plan map with three trusted headers
set by the upstream gateway on every authenticated request:

- x-token-api-batch-size: max array length per query parameter
- x-token-api-items-returned: max `limit` value
- x-token-api-lowest-time-parameter: minimum OHLCV interval granularity

Requests without these headers (local development, direct pod hits)
bypass plan enforcement. The X-Plan header is no longer read by the
service. Drops the PLANS env variable, --plans CLI flag, and the
in-process plans map.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@YaroShkvorets YaroShkvorets temporarily deployed to feat/plan-limits-from-headers - token-api PR #539 May 13, 2026 14:26 — with Render Destroyed
@0237h 0237h merged commit 43bde74 into main May 13, 2026
2 of 3 checks passed
@0237h 0237h deleted the feat/plan-limits-from-headers branch May 13, 2026 14:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants