Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gemini error 429 Too Many Requests. Resource has been exhausted #25

Open
Stijnp opened this issue Feb 6, 2025 · 2 comments
Open

Gemini error 429 Too Many Requests. Resource has been exhausted #25

Stijnp opened this issue Feb 6, 2025 · 2 comments

Comments

@Stijnp
Copy link

Stijnp commented Feb 6, 2025

I'm getting a Gemini error 429 on the free plan.

Seems like the request limit per model per minute for a project in the free tier is 15.

Currently it seems like there is no way to cap this in the script. Any suggestions on how to get around this?

Error in deduplication analysis: GoogleGenerativeAIFetchError: [GoogleGenerativeAI Error]: Error fetching from https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent: [429 Too Many Requests] Resource has been exhausted (e.g. check quota).
    at handleResponseNotOk (~/dev/node-DeepResearch/node_modules/@google/generative-ai/dist/index.js:414:11)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async makeRequest (~/dev/node-DeepResearch/node_modules/@google/generative-ai/dist/index.js:387:9)
    at async generateContent (~/dev/node-DeepResearch/node_modules/@google/generative-ai/dist/index.js:832:22)
    at async dedupQueries (~/dev/node-DeepResearch/src/tools/dedup.ts:91:20)
    at async getResponse (~/dev/node-DeepResearch/src/agent.ts:505:26)
    at async main (~/dev/node-DeepResearch/src/agent.ts:744:7) {
  status: 429,
  statusText: 'Too Many Requests',
  errorDetails: undefined
}
GoogleGenerativeAIFetchError: [GoogleGenerativeAI Error]: Error fetching from https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent: [429 Too Many Requests] Resource has been exhausted (e.g. check quota).
    at handleResponseNotOk (~/dev/node-DeepResearch/node_modules/@google/generative-ai/dist/index.js:414:11)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async makeRequest (~/dev/node-DeepResearch/node_modules/@google/generative-ai/dist/index.js:387:9)
    at async generateContent (~/dev/node-DeepResearch/node_modules/@google/generative-ai/dist/index.js:832:22)
    at async dedupQueries (~/dev/node-DeepResearch/src/tools/dedup.ts:91:20)
    at async getResponse (~/dev/node-DeepResearch/src/agent.ts:505:26)
    at async main (~/dev/node-DeepResearch/src/agent.ts:744:7) {
  status: 429,
  statusText: 'Too Many Requests',
  errorDetails: undefined
}
@PureRocketsDev
Copy link

Yes I'm getting the same error too. I just did a "git pull" just a few minutes ago so I have the latest. I would doubt there is really a good way around it. Han could put in an artificial limit perhaps, but that would likely just truncate an answer, not ideal. I doubt he could check for a free Gemini account due to Google security, which means using an environment flag that the user could set. I'm loving this tool, personally I'm probably going to opt for a paid Gemini account to get around it.

@apix7
Copy link

apix7 commented Feb 7, 2025

add something like this to error-analyzer.ts


/* rateLimitExample.ts */

let apiCallTimestamps: number[] = [];

// A helper function to create a delay for a given number of milliseconds
function delay(ms: number): Promise<void> {
  return new Promise(resolve => setTimeout(resolve, ms));
}

// This function enforces a rate limit allowing at most 10 API calls per minute (60000 ms)
// It does so by maintaining an array of timestamps of recent calls, and waiting if needed
async function enforceRateLimit(): Promise<void> {
  const windowMs = 60000; // 1 minute
  const rateLimit = 10;   // maximum allowed calls per minute
  const now = Date.now();

  // Remove timestamps that are older than the current window
  apiCallTimestamps = apiCallTimestamps.filter(timestamp => now - timestamp < windowMs);

  if (apiCallTimestamps.length >= rateLimit) {
    // Calculate the time to wait until the earliest call drops out of the window
    const waitTime = windowMs - (now - apiCallTimestamps[0]);
    console.warn(`Rate limit reached. Waiting for ${waitTime}ms before proceeding.`);
    await delay(waitTime);
    // Recursively enforce the rate limit after waiting
    return enforceRateLimit();
  }
  
  // Record the current call
  apiCallTimestamps.push(now);
}

// Example function: simulate making an API call by enforcing rate limit before proceeding
async function makeAPICall() {
  await enforceRateLimit();
  console.log(`API call made at ${new Date().toISOString()}`);
}

// Test the rate limiting by attempting to make 12 API calls
async function testRateLimit() {
  for (let i = 0; i < 12; i++) {
    await makeAPICall();
  }
}

// Run the test
testRateLimit();


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants