lichess-org / lila-tablebase

Tablebase server

Home Page:https://tablebase.lichess.ovh

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

HTTP 429 when requesting /standard/mainline endpoint

pkacprzak opened this issue · comments

I just started working on adding the tablebase to u/chessvision-ai-bot/ bot on Reddit and this API looks like an awesome resource I could use. The bot tries to give the best continuation line so the GET /standard/mainline endpoint is quite useful. When I'm testing the requests to the API locally I get 429 Too Many Requests quite often. I'm sending a normal request with a unique User-Agent describing the bot. Is there any way to avoid the 429? In the production, the bot uses queuing to process Reddit submissions so that there is always at least a 30-60s interval between processing two submissions. Could this 429 be a problem?

The rate limiting on this endpoint is quite strict (currently one request per minute with bursts of 5), because computing the mainline is fairly expensive. It needs to hit the tablebase for (just about) every legal move at every step, which can mean hundreds or thousands of probes.

To clarify, do you need the entire line, or just the best move?

Thanks for the clarification.

The first couple of moves would be best, but I'm doing a workaround now:

  1. If I don't get rate limited, then I'm giving the full line
  2. If I get rate limited, I give the line as only the best move from the response from /standard endpoint

I'm planning to push the update soon so I can monitor how is it doing.

Sounds good. Another idea would be adding a new parameter like ?limit=5 for /standard/mainline (and I will, if you would use that), but the rate limiting is done outside of this server (by nginx), so it can't really take that into account.

Alternatively, how about always just doing sth like 5 /standard requests in sequence? It's a little bit of HTTP overhead, but avoids the expensive full mainline probes and works with the existing limits.

Definitely good ideas - thank you. I think I can do chained /standard requests to construct some prefix of the mainline so that no change in the API is needed. The first 3-5 moves should be enough for any reasonable use-case I think.