Skip to content

Update Tool Server#37

Merged
fcogidi merged 6 commits into
mainfrom
f/tool_server_updates
Nov 5, 2025
Merged

Update Tool Server#37
fcogidi merged 6 commits into
mainfrom
f/tool_server_updates

Conversation

@fcogidi
Copy link
Copy Markdown
Collaborator

@fcogidi fcogidi commented Nov 5, 2025

PR Type

Fix, Feature

Short Description

  • Added a major new feature where API usage counters are not consumed if the call to Gemini is still within the free RPD limit.

Tests Added

...

- Updated the search function to include an authenticator dependency for managing API key usage.
- Implemented error handling to roll back usage reservations in case of request failures.
- Added a new method in APIKeyAuthenticator to decrement usage counters, ensuring accurate tracking of API key usage.
- Introduced new environment variables for API key usage retries and delays.
- Implemented a retry mechanism with exponential backoff for Firestore transactions in the API key repository.
- Added a method to decrement the usage counter, ensuring accurate tracking during request failures.
- Introduced DailyUsageRepository to manage daily usage counters.
- Added environment variables for daily usage configuration in .env.example and README.
- Updated app.py to integrate daily usage tracking with API key consumption.
- Modified Dockerfile to include daily_usage.py.
- Enhanced tests to validate usage consumption and limits.
@fcogidi fcogidi requested a review from Copilot November 5, 2025 15:51
@fcogidi fcogidi self-assigned this Nov 5, 2025
@fcogidi fcogidi added the enhancement New feature or request label Nov 5, 2025
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces a dual-tier usage tracking system for Gemini grounding requests, implementing daily free-tier allowances alongside existing API key quotas. The implementation includes rollback mechanisms for failed requests and retry logic for transactional updates.

  • Adds daily usage counters with configurable free limits per model/bucket
  • Implements usage reservation rollback for both daily and API key quotas when requests fail
  • Adds retry logic with exponential backoff for Firestore transaction conflicts

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/utils/web_search/daily_usage.py New repository implementing daily usage counters with reserve/release operations
src/utils/web_search/db.py Added decrement_usage_counter method with retry logic for API key usage rollback
src/utils/web_search/auth.py Added consume_usage and release_usage methods for deferred and rollback usage accounting
src/utils/web_search/app.py Integrated daily usage tracking into request flow with two-phase commit pattern
tests/test_web_search_auth.py Added test coverage for new release_usage and consume_usage methods
src/utils/web_search/README.md Documented new environment variables for daily usage configuration
src/utils/web_search/.env.example Added configuration examples for daily usage limits and retry tuning
src/utils/web_search/Dockerfile Updated to include daily_usage.py in container
src/utils/web_search/.dockerignore Updated to exclude daily_usage.py from ignore list

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/utils/web_search/app.py Outdated
Comment thread src/utils/web_search/app.py Outdated
Comment thread src/utils/web_search/daily_usage.py
@fcogidi fcogidi merged commit ea2ee6a into main Nov 5, 2025
4 checks passed
@fcogidi fcogidi deleted the f/tool_server_updates branch November 5, 2025 16:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants