My Gemini call takes about 10 seconds to process on their server. I have the call out to their server wrapped in an asynchronous method, so I can do overlapping calls on separate threads. In my dispatcher loop I have a Thread.Sleep(1000) (You can find that at the bottom of the foreach loop) so that I am not submitting these calls at a pace which exceeds 1 per second. (Although I will have roughly 10 overlapping calls executing simultaneously each second.)
foreach (QueuedReview qr in queuedReviews)
{
swLimiter.Restart();
GetBearerToken();
m_nextQueuedReview = qr;
m_nextAssistant = GetAuthoringAssistant();
Thread t = new Thread(StartAuthoringProcess)
{
Priority = 0
};
t.Name = "AuthoringAssistant: " + qr.ReviewId;
t.Start();
swLimiter.Stop();
if (swLimiter.ElapsedMilliseconds < m_RateDelay)
{
Thread.Sleep((int)(m_RateDelay - swLimiter.ElapsedMilliseconds));
}
}
Despite this, 90% of my calls are failing with The remote server returned an error: (429) Too Many Requests. When you run the math, I’d achieve the same rate of processing with a synchronous call to Gemini every 10 seconds. (Roughly the time it takes each call to complete.) So what’s my rate limit? 1 call per second or 1 call every 10 seconds?