Gemini API Pricing, Quotas & Rate Limits Explained
The calculator for this page is switched off while it is checked. The formula is below, and the worked example in the article shows how to use it by hand.
Gemini API pricing, quotas, and rate limits determine how much you pay per request and how many requests you can make per minute or per day. You get charged per token (input and output) for model access, and you also have free-tier quotas that reset daily, with higher limits available for paid tiers. This article breaks down the cost structure, the quota system, and the rate limits you’ll encounter, with concrete examples and practical advice.
What Is the Gemini API?
The Gemini API is Google’s interface for its Gemini family of large language models. Developers send text (or images, audio, and video, depending on the model) to the API, and the model returns a generated response. The API is used for chatbots, summarization, content generation, code assistance, and many other natural language tasks. It’s available through Google AI Studio for experimentation and through Google Cloud Vertex AI for enterprise deployments.
There are several models in the Gemini family, with different sizes and capabilities. The most commonly used are Gemini 1.5 Flash (fast and cost-effective) and Gemini 1.5 Pro (more capable, but slower and more expensive). Newer models like Gemini 2.0 Flash are also available, but pricing and quotas may differ. Always check the official documentation for the latest model list and pricing.
How Pricing Works: Tokens, Not Requests
Gemini API pricing is based on tokens, not the number of requests. A token is roughly a piece of a word; 1,000 tokens is about 750 English words. The cost is calculated separately for input tokens (the text you send to the model) and output tokens (the text the model generates). Each model has a price per million tokens for input and output.
For example, Gemini 1.5 Flash costs $0.075 per million input tokens and $0.30 per million output tokens (for prompts up to 128K tokens). Gemini 1.5 Pro costs $1.25 per million input tokens and $5.00 per million output tokens. These prices are for standard text prompts; longer context (up to 1M tokens) has a different price tier. Audio, image, and video inputs are also charged differently, usually at a higher rate per token.
There is also a free tier with limited quotas. The free tier is intended for experimentation and small projects. You get a certain number of requests per minute (RPM) and tokens per minute (TPM) for free, but the quotas are much lower than paid tiers. If you exceed the free quotas, you must upgrade to a paid plan.
Quotas: What You Can Use Per Day and Per Minute
Quotas are the limits on how much you can use the API. They are defined in terms of requests per minute (RPM), tokens per minute (TPM), and requests per day (RPD). The quotas vary by model and by whether you are on the free tier or a paid tier.
For Gemini 1.5 Flash on the free tier, typical quotas are 15 RPM, 1 million TPM, and 1,500 RPD. For Gemini 1.5 Pro on the free tier, typical quotas are 5 RPM, 100,000 TPM, and 1,000 RPD. These numbers are approximate and can change, so always check the official quota page.
On a paid tier (Pay-as-you-go), the quotas are much higher. For Gemini 1.5 Flash, you might get 2,000 RPM, 4 million TPM, and no daily request limit (or a very high one). For Gemini 1.5 Pro, you might get 1,000 RPM, 4 million TPM, and no daily limit. However, these are default quotas; you can request an increase through Google Cloud Console if you need more.
It’s important to note that quotas are per project, not per API key. If you have multiple projects, each has its own quotas. Also, the free tier quotas reset daily at midnight Pacific Time.
Rate Limits: How Fast You Can Send Requests
Rate limits are the enforcement of quotas. When you exceed a rate limit, the API returns a 429 HTTP status code (Too Many Requests). You can handle this by implementing exponential backoff (waiting longer between retries) or by using the Retry-After header that the API returns.
There are two main types of rate limits: RPM (requests per minute) and TPM (tokens per minute). RPM limits how many API calls you can make in a minute, regardless of size. TPM limits the total number of tokens (input + output) you can process in a minute. Both limits apply simultaneously; you must stay under both.
For example, if you have a TPM limit of 1 million tokens and your average request uses 5,000 tokens (input + output), you can make about 200 requests per minute before hitting the TPM limit, even if your RPM limit is 1,000. Conversely, if your RPM limit is 15, you can only make 15 requests per minute even if your TPM limit is much higher.
To avoid hitting rate limits, you can use the following strategies:
- Batch multiple requests into one call if possible (e.g., using the
contentsarray for multiple prompts). - Cache responses for repeated queries.
- Implement exponential backoff with jitter (random delay) in your retry logic.
- Monitor your usage in Google Cloud Console and set alerts for approaching limits.
Common Mistakes and Misconceptions
One common misconception is that the free tier is enough for production. It’s not; the free tier has strict quotas that are easily exceeded by real users. Another is that the price per request is fixed; it actually depends on the number of tokens, which can vary widely. For example, a short query might cost a fraction of a cent, while a long document summarization could cost several cents.
Another mistake is not accounting for the output tokens. The output tokens are often longer than you expect, especially for creative tasks. Always estimate the maximum output length and set the max_output_tokens parameter to avoid surprise costs.
Also, many developers forget that the context window (the total tokens sent to the model) includes the system instructions and any conversation history. If you have a long chat history, the input token count can be large, increasing cost. Use the countTokens method to check the token count before sending a request.
How to Choose the Right Model and Tier
Choosing the right model depends on your use case. If you need fast responses and low cost, Gemini 1.5 Flash is a good choice. If you need high-quality reasoning and are willing to pay more, Gemini 1.5 Pro is better. For very large context windows (up to 1M tokens), you may need to use a model that supports that, and the pricing is higher.
For the tier, start with the free tier to test your application. Once you need more quota, switch to pay-as-you-go. You can set a budget in Google Cloud to avoid unexpected charges. If you have predictable high usage, you might consider a committed use contract (like a flat-rate tier) for lower per-token costs.
Remember that the API also has a “context caching� feature that can reduce costs for repeated prompts. Caching stores the input tokens and charges a lower rate for cached tokens. This is useful for chatbots with long system prompts or few-shot examples.
Frequently Asked Questions
What happens if I exceed the rate limit?
You get a 429 error. The API returns a Retry-After header indicating how many seconds to wait before retrying. Your code should handle this by waiting and retrying, ideally with exponential backoff. If you consistently hit rate limits, you need to request a quota increase or optimize your usage.
How do I check my current quota usage?
In Google Cloud Console, go to the “Quotas� page for your project. You can see the current usage and the limit for each quota. You can also set up alerts to notify you when you approach a limit. The API also returns usage information in the response headers (e.g., x-ratelimit-remaining).
Is the free tier really free?
Yes, the free tier does not charge any money. However, it has limited quotas that are shared across all free users. If you exceed the quotas, you get rate-limited until the next day. The free tier is for experimentation and development, not for production.
Can I increase my quotas?
Yes, you can request a quota increase from the Google Cloud Console. You need to specify the quota you want to increase and the new value. The request is usually approved within a few days, but it may take longer for large increases. You must have a billing account attached to your project to request an increase.
Are there any costs for failed requests?
No, you are only charged for successful requests that generate tokens. If a request fails due to a rate limit or an invalid input, you are not charged. However, if the request is successful but the model returns an error, you may still be charged for the input tokens used.
How do I estimate the cost of a request?
You can use the countTokens method to get the token count of your input. Then, estimate the output tokens (you can set a max output length). Multiply the input tokens by the input price per token and the output tokens by the output price per token. Add them together. The calculator above does this for you with the default prices.
Related
Formula used
in tokens | Input tokens | tokens | 1000 | 0 in model | Model | gemini-1.5-flash=0.00001875, gemini-1.5-pro=0.00000125 out tokens | Output tokens | tokens | 500 | 0 out cost | Estimated cost | USD | (in tokens * model) + (out tokens * model * 4) | 4
Each line is one input (in, sel, list) or one result (out: label, unit, formula, decimals). How the calculators work
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.