How to manage one gemini API key per client in a saas app?

Hi,
I am building a SaaS app with some AI agents. For the LLMs, the clients will not provide any API key; we will use our own Gemini API keys.

In this setting, we need to solve two challenges:

  • We need to track the API usage and costs for each client
  • We need to be sure that we don’t hit the Gemini API rate limits

What is the best practice to manage this?

For instance, one possible method is to create a separate API key for each client. But in the Gemini API, rate limits are applied per project, not per API key. Thus, you need to create a different project per client, which is not easy to manage.

What are your suggestions about this?

Hey @ay2025 — great question, and you’re absolutely right to think ahead about usage tracking and rate limit management in a multi-client SaaS setup.

You’re correct that Gemini API rate limits are enforced per project, not per API key, which makes per-client isolation tricky. Here are a few best practices and ideas to consider:

:white_check_mark: Centralized Billing + Internal Metering
Use a single Gemini project and API key, but implement internal usage tracking per client. You can log each request with metadata (client ID, timestamp, token count, etc.) and use that to calculate usage and costs. This keeps things simple while giving you full visibility.

:white_check_mark: Rate Limit Buffering
To avoid hitting rate limits, implement a rate limiter in your backend that tracks usage per client and throttles requests if needed. You can also stagger requests or queue them during peak times.

:white_check_mark: Multiple Projects (Advanced)
If you truly need hard isolation, creating separate GCP projects per client is the only way to get separate rate limits — but as you said, this is hard to scale and manage. You’d need automation (e.g., Terraform or scripts) to provision and monitor these projects.

:white_check_mark: Quota Increase Request
If your SaaS is growing, consider requesting a quota increase from Google. They may offer higher limits for enterprise use cases, especially if you explain your architecture.

:white_check_mark: Billing Attribution
Use your internal logs to generate monthly usage reports per client. You can then bill them accordingly, even if all usage goes through a single API key.

Hope this helps! Let me know if you want help designing a usage tracking system or setting up rate limit controls.

Thanks for reaching us!