Skip to content

fix: read a 429's limit type from the API's detail - #13

Merged
vdavez merged 1 commit into
mainfrom
fix/rate-limit-type-from-detail
Oct 19, 2026
Merged

vdavez merged 1 commit into
mainfrom
fix/rate-limit-type-from-detail

Conversation

@makegov-mark

@makegov-mark makegov-mark Bot commented Oct 19, 2026

Copy link
Copy Markdown
Contributor

What

Error::RateLimit's limit_type now reports which limit a 429 hit, "daily" or "burst", instead of always being None.

Why

The SDK read the limit type only from an X-RateLimit-Type header, which the Tango API does not send.
The API names the tripped rate in the 429 body's detail instead: Rate limit exceeded for daily. Please try again in 16 hours, 58 minutes.
This matches tango-python 1.18.2, which reads the same field the same way.

How

  • The rate's name after exceeded for is read, never the wait text, so a daily lockout whose wait mentions minutes is not reported as burst.
  • Daily is checked first (daily, or the word day), then burst (burst or minute); anything else is None.
  • A premium endpoint's per-scope budget (premium_daily) reports as "daily".
  • A non-empty X-RateLimit-Type header still takes precedence, so a future header wins.
  • No public type changes: the field already existed on Error::RateLimit (the enum is #[non_exhaustive]; no variant or field is added). RateLimitInfo is untouched.

Testing

  • Unit tests: the daily message above, daily with a one-minute wait, burst with seconds and minute waits, a burst whose wait mentions a day, premium_daily, Too many requests., an empty detail, a non-string detail, a non-JSON body, an empty body, header precedence, and an empty header falling back to the detail.
  • Integration test through the mock server: a daily 429 without the header yields Some("daily").
  • cargo fmt --check and cargo clippy --workspace --all-features -- -D warnings on 1.80 and stable; cargo test --workspace with --all-features and --no-default-features on stable and 1.80.

🤖 Generated with Claude Code

`Error::RateLimit`'s `limit_type` was read only from an `X-RateLimit-Type` header the Tango API does not send, so it was always `None`.
It is now `"daily"` or `"burst"`, read from the rate named in the 429 body's `detail` (`Rate limit exceeded for daily. ...`), matching tango-python 1.18.2; a header still wins when present.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vdavez
vdavez marked this pull request as ready for review October 19, 2026 23:01
@vdavez
vdavez merged commit 946d176 into main Oct 19, 2026
9 checks passed
@vdavez
vdavez deleted the fix/rate-limit-type-from-detail branch October 19, 2026 23:01
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.

1 participant