gemini-api-rate-limiting
Best practices for handling Gemini API rate limits, implementing sequential queues, and preventing 429 RESOURCE_EXHAUSTED errors in WescoBar
Security Assessment
About gemini-api-rate-limiting
The 'gemini-api-rate-limiting' skill provides a set of best practices for managing and optimizing API calls to the Google Gemini API in the WescoBar Universe Storyteller application. The primary challenge it addresses is the occurrence of '429 RESOURCE_EXHAUSTED' errors, which are triggered when too many simultaneous API requests are made. This skill offers strategies for preventing these errors by implementing a sequential queue system, reducing simultaneous requests, and incorporating API rate limits into workflows. By following these practices, developers can ensure smoother operation, better user experiences, and more efficient API usage.
FAQ
How do I prevent 429 RESOURCE_EXHAUSTED errors?
To prevent these errors, use a sequential queue with delays between API calls. The skill suggests using a `for...of` loop for sequential processing and adding a delay, such as a 2-second pause, between requests.
What is the best way to handle API timeouts?
API timeouts can be managed by using `Promise.race()` to race the API call against a timeout. This ensures that long-running requests are terminated if they exceed a specified time limit.
Can I optimize API usage to avoid unnecessary calls?
Yes, by implementing caching strategies, such as using entity-stable cache keys and cache versioning, you can reduce the number of calls made to the API. Cache busting is also possible when explicit regeneration is needed.
How can I track the progress of queued requests?
To keep users informed, you can add queue status indicators in the UI. This involves updating the generation queue's status with details about the current character being processed and the progress of the overall queue.
Install gemini-api-rate-limiting
Quick Setup:
- Copy the skill folder to
.claude/skills/ - Claude will automatically detect and use the skill
Repository
BerryKuipers/claude-code-toolkit