140dev
#1
Version 1.1 breaks down rate limits into 15 minute “windows”. The docs don’t explain exactly how a window is determined.
Is a window based on fixed clock timing? For example, is 00:00 to 00:15 a single window?
Or is a window based on the starting time for my first request? If I make a specific API request at 00:03, does the window for that method extend to 00:18?
I’m writing an ebook on rate limiting, so getting a clear answer will let me share it with lots of people. Thanks.
episod
#2
It begins with the starting time of your “first” request.
140dev
#3
Thanks. I will describe this as “looking back over the previous 15 minutes.” So it is a rolling count.
Hi Taylor,
Could you please clarify what’s meant by “first request”? Are requests to OAuth endpoints in order to obtain access_token count as well?
I’d like to have API usage statistic per user on my side. For this I need to know when the window duration begins so that I can save timestamp just before user has issued her first request to the REST API.
Thanks in advance.
Cheers,
Kostya.
episod
#5
Request to the oauth/* methods are not, strictly speaking, API resource calls. The first request would be the initial request to an api.twitter.com/1.1/* resource method.
Thanks Taylor,
And what about the X-Rate-Limit-* HTTP headers? Could they be relied upon or it’s better to have my own fall back tracking solution? I’ve heard they not always present.
I have a question (experiencing odd behaviour) related to this.
I’m using several tokens to do calls. If all of them are ‘used up’, I wait the longest time (furthest reset time) so that I can use all the tokens again. So basically, the last token I use in the set of tokens, I use that one’s reset time and then wait until it is “clear” again to start using all of the tokens.
The problem: When waiting, the reset time is longer than 15 minutes by almost a minute. I use Python’s time.time() (which returns unix time) to compare against the timestamp in reset time. I often get it to be over 900 seconds (15minutes) for some odd reason. The 15 requests I use per 15 minute window occurs very quickly (1-2 seconds), so it doesn’t make any sense?
Why is the reset time further into the ‘future’ more than 15 minutes based from the first request?
Is this intentional? Is there some bug? Am I missing something? Made doubly sure, it isn’t due to some way Python determines time.time() or something.