Gemini Developer API 免费版 运行 gemini-2.5-flash、gemini-3-flash
Google Gemini API提供免费额度,适用于轻量版模型如gemini-2.5-flash和gemini-3-flash-preview。用户可通过官方文档获取API密钥,并安装google-genai库进行调用。示例代码展示了如何使用Python调用API获取AI解释或未来事件预测。虽然高级模型无免费额度,但基础版本已能满足简单需求,实测响应效果良好。
·
总目录 大模型相关研究:https://blog.csdn.net/WhiffeYF/article/details/142132328
今天偶然发现Gemini的API有免费额度(2025-12-24)
https://ai.google.dev/gemini-api/docs/pricing?hl=zh-cn
b站视频:https://www.bilibili.com/video/BV1NQBLB7EDU
免费API一览
最好的模型没有免费额度,但是轻量版/过去的模型就有免费额度。








调用API
API位置:
https://aistudio.google.com/api-keys
入门教程:
https://ai.google.dev/gemini-api/docs/quickstart?hl=zh-cn

pip install -q -U google-genai
导入你的API
export GEMINI_API_KEY=<YOUR_API_KEY_HERE>
from google import genai
# The client gets the API key from the environment variable `GEMINI_API_KEY`.
client = genai.Client()
response = client.models.generate_content(
model="gemini-2.5-flash", contents="Explain how AI works in a few words"
)
print(response.text)
运行结果如下:

感动,竟然真的免费。
调用gemini-3-flash-preview
from google import genai
# The client gets the API key from the environment variable `GEMINI_API_KEY`.
client = genai.Client()
response = client.models.generate_content(
# model="gemini-2.5-flash", contents="2025年中国发生了哪些重要事情"
model="gemini-3-flash-preview", contents="2025年中国发生了哪些重要事情"
)
print(response.text)

限制
可惜了,我跑了20次就限制了
Gemini API调用出错: 429 RESOURCE_EXHAUSTED. {'error': {'code': 429, 'message': 'You exceeded your current quota, please check your plan and billing details. For more information on this error, head to: https://ai.google.dev/gemini-api/docs/rate-limits. To monitor your current usage, head to: https://ai.dev/usage?tab=rate-limit. \n* Quota exceeded for metric: generativelanguage.googleapis.com/generate_content_free_tier_requests, limit: 20, model: gemini-2.5-flash\nPlease retry in 54.442074981s.', 'status': 'RESOURCE_EXHAUSTED', 'details': [{'@type': 'type.googleapis.com/google.rpc.Help', 'links': [{'description': 'Learn more about Gemini API quotas', 'url': 'https://ai.google.dev/gemini-api/docs/rate-limits'}]}, {'@type': 'type.googleapis.com/google.rpc.QuotaFailure', 'violations': [{'quotaMetric': 'generativelanguage.googleapis.com/generate_content_free_tier_requests', 'quotaId': 'GenerateRequestsPerDayPerProjectPerModel-FreeTier', 'quotaDimensions': {'location': 'global', 'model': 'gemini-2.5-flash'}, 'quotaValue': '20'}]}, {'@type': 'type.googleapis.com/google.rpc.RetryInfo', 'retryDelay': '54s'}]}}
解析:
⏺ 这是 Google Gemini API 的配额超限错误。让我解释一下:
错误含义:
429 RESOURCE_EXHAUSTED = 资源耗尽,超出配额
关键信息:
- 您使用的是免费层级(free tier)
- gemini-2.5-flash 模型每天限制 20 次请求
- 您今天已经用完了 20 次配额
- 建议 54 秒后重试(但免费层配额是按天重置的)
解决方案:
1. 等待配额重置(推荐,如果不急)
- 免费层配额会在每天午夜(UTC时间)重置
- 明天就可以再用 20 次
2. 升级到付费计划(推荐,如果需要大量调用)
- 访问:https://ai.google.dev/pricing
- 付费后配额会大幅提升(每分钟 1000+ 请求)
3. 添加自动重试机制
我可以帮您修改代码,添加速率限制处理和自动重试功能,避免超出配额。需要我修改吗?
4. 查看当前用量
访问:https://ai.dev
⎿ API Error: Claude Code is unable to respond to this request, which appears to violate our Usage Policy
(https://www.anthropic.com/legal/aup). Please double press esc to edit your last message or start a new
session for Claude Code to assist with a different task. If you are seeing this refusal repeatedly, try
running /model claude-sonnet-4-20250514 to switch models.
也就是说【模型每天限制 20 次请求】
更多推荐



所有评论(0)