Using the API - Good practices


#1

Hi there community!

I’ve created a Java application that uses the API to check a users list of online followed streamers.

It does this, by using two API calls. I am including (I hope!) my assigned application Client ID, in order to deal with rate limiting. But I am curious though - even with this included Client ID, what’s the maximum amount of requests I can send within a given time frame? Secondly, what’s good practice when it comes to using the API? Currently, my application does its two API requests every 30 seconds. Is this too much?

Thanks!


#2

Two requests every 30 seconds is barely anything, so I’d say it’s nothing you should be concerned about. If we’re talking two requests multiplied by thousands of users then that’s something else however…

As far as I know there is no limit when you provide a client id, and any app that gets unusually high will get reviewed on a case by case basis, and then contacted by the devs directly.

As with any API, if you’re serving multiple users the same data, or there’s a lot of data reuse, having some caching mechanism is good practice. This doesn’t seem to be relevant in your case though.


#3

moocat is mostly right. However, we don’t look at just the client_id, but also take into account what IP the requests are coming from. So if you have an app that has tons of users making client-side requests, you’re still good to go.


#4

Hi guys!

I’m really excited to see my app working, and it feels really good to know that I’m not in the excess of requests. When I’m debugging my application though, there might be a tad more requests than just two per 30 seconds :wink:

My application sends two requests to the Kraken API when it starts up and two requests every 30 seconds after that - is this considered a “client-side” request?

Anyway, I’ve only just now actually verified that I’m sending the correct headers *d’oh*. In either case, it’s good to hear that if I’m approaching anything close to a limit, I will be contacted - not that I think this application will ever become popular as I’m sure there’s probably already some sort of alternative to mine out there.

Also, I’ve tried looking into caching but the information I’m retrieving is real-time sensitive, unfortunately.

But, thank you - both of you! - for your replies, really great to hear that I’m not overstepping any self-imposed barrier.


#5

can you tell me how to authorize the API application please i got the option to register, i selected my website and pressed update. i went back on to the applications and it says i need to authorize them. thanks


#6

Have you read our documentation about authentication?


#7

We have the same concerns particularly regarding the polling of viewers during streams. Seems we have to do an interval call to check the status of the stream and if it’s live then follow with intervals of api calls to check the viewer count. Most examples people have been discussion are only 2 or 3 call every 30 secs but we are trying to prepare to achieve this with as much as 10,000 users. We are not there yet but we want to properly plan for this scenario.

In this scenario it would be at minimum 10k calls every 5 minutes to check stream status and then lets assume worst case scenario all are live then it would be 10k calls every minute to update the viewer status. then would we have a problem, would we then need an alternative solution?


#8

1 request per minute per client should be perfectly fine.


#9

Thanks, just to clarify, when you say client you mean per twitch user we are accessing? so even if it’s 10k at the same time from the same IP, it’s not a problem as long as each individual call is a unique twitch user?


#10

If the calls are made by your server and not the end client directly, then it is expected that you optimize your API calls since the server can know better which calls need to be made. For example, if each client only cares about the viewers for a single channel but each client cares about a different channel then it’s expected that you’d implement a naive call if done the client, https://api.twitch.tv/kraken/streams?channel=CHANNEL_CLIENT_1_CARES_ABOUT, but a smarter call if done in the server, https://api.twitch.tv/kraken/streams?channel=CHANNEL_CLIENT_1_CARES_ABOUT,CHANNEL_CLIENT_2_CARES_ABOUT,CHANNEL_CLIENT_3_CARES_ABOUT,....

Likewise, if you are doing tons of queries on a server it is expected that you properly distribute them over time. Do not make 10,000 requests simultaneously if you can avoid it.


#11

Ok cool thanks, yea I was just speaking hypothetically just to see what you thought.


#12

There is still not a clear answer on how often it is alright to make a request from the same IP.
Is it okay 1 request for a channel’s followers every 10 seconds?


#13

2y old thread so maybe a new one would be better as V5 is now recently released and a new Dev Agreement published (or a better outlined one.) Speaking of which, the Developer Agreement is a good place to start but there isn’t really a hard limit, the general guideline is 1 call/sec at most - I don’t believe it’s necessarily tracked by IP but rather Client ID (or a conjunction of the two).

Twitch monitors usage and will contact you if it is what they consider excessive.


#14