feat: expose rate limit headers via onRateLimitInfo callback#86
Merged
mikeh-lago merged 2 commits intomainfrom May 5, 2026
Merged
feat: expose rate limit headers via onRateLimitInfo callback#86mikeh-lago merged 2 commits intomainfrom
mikeh-lago merged 2 commits intomainfrom
Conversation
Surface x-ratelimit-* headers from successful responses so callers can build observability around the rate limit (warn at thresholds, emit metrics) without inspecting internals. - Add RateLimitInfo type with parseRateLimitInfo + rateLimitUsagePct helpers - Add onRateLimitInfo option on RateLimitFetchConfig - Parse and emit headers on every non-429 response in createRateLimitFetch - Ship loggingRateLimitObserver as a zero-config observer (defaults: 80/90/95%) - Callback errors are caught and logged so they cannot break requests - Backward-compatible: callback is optional, default behavior unchanged
vincent-pochet
approved these changes
May 5, 2026
Address review feedback from @vincent-pochet on PR #86: - Honor Request.method when input is a Request and init.method is undefined (a valid fetch signature). Previously this fell through to 'GET' regardless of the actual method on the Request. - Only emit on_rate_limit_info on 2xx responses. Non-429 errors no longer trigger the callback. This matches the comment on the call site, the docstring on the option, and the behavior of the Python, Go, Ruby, and Rust SDKs. - Add tests for the Request input case and for the 5xx no-emit case.
vincent-pochet
approved these changes
May 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds an optional
onRateLimitInfocallback onRateLimitFetchConfigso callers can readx-ratelimit-*headers from successful responses. Today the SDK drops them on 2xx, which makes 80/90/95% threshold observability impossible without inspecting internals. The 429 path (viaLagoRateLimitError) is unchanged. Mirrors PRs getlago/lago-python-client#393, getlago/lago-go-client#336, and getlago/lago-ruby-client#347.Notes for review
console.warnso a buggy observer can't break a request.Tests
12 new tests in
tests/rate_limit.test.ts.deno task testpasses (98 tests).deno task buildproduces a clean npm package.