Rate limit information extracted from Twitch API response headers.
Twitch includes these headers on every response:
Ratelimit-Limit— total requests allowed in the current windowRatelimit-Remaining— requests remaining in the current windowRatelimit-Reset— Unix timestamp (seconds) when the window resets
All Teac.Api.* functions return this struct as the last element of their
return tuple so callers can implement their own throttling strategy.
Non-paginated
case Teac.Api.Users.get(client, id: "123") do
{:ok, users, rl} ->
if rl.remaining < 10, do: maybe_slow_down()
users
{:error, %Teac.Error{status: 429, ratelimit: rl}} ->
wait_until(rl.reset)
endPaginated
{:ok, data, cursor, rl} = Teac.Api.Clips.get(client, broadcaster_id: "123")Fields
Fields are nil when headers are absent (e.g. in tests using Req.Test stubs).
Summary
Types
@type t() :: %Teac.RateLimit{ limit: non_neg_integer() | nil, remaining: non_neg_integer() | nil, reset: non_neg_integer() | nil }