Skip to content

fix: add X-RateLimit-Reset header to rate limit responses (#548)#1060

Open
Vishal-Prajapati17 wants to merge 1 commit into
imDarshanGK:mainfrom
Vishal-Prajapati17:fix-548-rate-limit-headers
Open

fix: add X-RateLimit-Reset header to rate limit responses (#548)#1060
Vishal-Prajapati17 wants to merge 1 commit into
imDarshanGK:mainfrom
Vishal-Prajapati17:fix-548-rate-limit-headers

Conversation

@Vishal-Prajapati17

Copy link
Copy Markdown

Fix Summary

Fixes #548

Implemented rate limit response headers to improve client visibility into API usage and prevent unexpected 429 responses.

Changes Made

Backend

  • Added X-RateLimit-Reset header to the rate limiting middleware response headers.

  • Existing headers already provided:

    • X-RateLimit-Limit
    • X-RateLimit-Remaining
  • Responses now expose:

    • Maximum request limit
    • Remaining requests in the current window
    • Time until the rate limit window resets

Tests

Updated and extended rate limit test coverage to verify:

  • Successful responses include:

    • X-RateLimit-Limit
    • X-RateLimit-Remaining
    • X-RateLimit-Reset
  • Rate-limited (429) responses include:

    • Retry-After
    • X-RateLimit-Limit
    • X-RateLimit-Remaining
    • X-RateLimit-Reset

Verification

Executed targeted rate limit tests:

pytest tests/test_endpoints.py -k rate_limit -v

Result:

2 passed

Executed full backend test suite:

pytest

Result:

428 passed

Files Modified

backend/app/main.py
backend/tests/test_endpoints.py

Outcome

Clients can now reliably determine:

  • Current rate limit quota
  • Remaining requests
  • When the quota window resets

This improves client-side retry handling and reduces surprise 429 responses while maintaining consistent rate limit metadata across successful and throttled requests.

Screenshots

Screenshot (20) Screenshot (21)

@Vishal-Prajapati17

Copy link
Copy Markdown
Author

Hi @imDarshanGK ,

Completed Issue #548.

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.

Add rate limit headers to API responses

1 participant