Skip to content

feat: expose full rate limit headers on RateLimitError #6

@0xneobyte

Description

@0xneobyte

Problem

The backend returns the following headers on 429 responses:

  • X-RateLimit-Limit-PerMinute
  • X-RateLimit-Remaining-PerMinute
  • X-RateLimit-Limit-PerDay
  • X-RateLimit-Remaining-PerDay
  • Retry-After

The SDK currently only parses Retry-After and discards the rest. Callers have no way to know which limit was hit or what the limit value is, making it impossible to implement informed backoff or meaningful error messages.

Proposed Behaviour

Parse all rate limit response headers and expose them as fields on RateLimitError.

except RateLimitError as e:
    print(e.retry_after)       # seconds to wait
    print(e.limit_per_minute)  # per-minute cap, or None
    print(e.limit_per_day)     # per-day cap, or None

Files to Modify

File Change
src/brainus_ai/exceptions.py Add limit_per_minute, limit_per_day fields to RateLimitError
src/brainus_ai/client.py Parse additional headers in _make_request error handler

Acceptance Criteria

  • RateLimitError.retry_after behaviour is unchanged
  • RateLimitError.limit_per_minute set when header is present
  • RateLimitError.limit_per_day set when header is present
  • Fields are None when the corresponding header is absent
  • Tests cover both per-minute and per-day header scenarios

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions