English Version: README.en.md
默认语言:中文
本仓库现包含 2 个 Tampermonkey/Greasemonkey 用户脚本 + 3 个浏览器控制台脚本 ,帮助你批量创建 Google Cloud 项目并获取或管理 Google AI Studio(Gemini)API Key。
适用于需要大规模管理 Key 或频繁创建新项目的场景。
⚠️ 重要提示 / 免责声明
- 本项目仅供学习和参考使用,任何由此脚本引发的风险由使用者自行承担。
- 由于 Google 限制原因,每个项目的 API Key 共享同一资源,默认每个项目只创建 1 个 Key,且建议单账号不超过 5 个项目。
- 代码可直接复制粘贴执行(脚本内注释已说明可调整参数),若需修改,可根据注释进行微调。
- Google 可能随时更新界面或接口,如脚本失效,请自行调试或提交 Issue。
- 请遵守 Google Cloud 与 Google AI Studio 的服务条款,避免恶意或高频操作导致账号受限。
- 如果你觉得本项目有帮助,欢迎点个 Star ⭐️ 支持!
名称 | 文件 | 形态 | 主要功能 | 备注 |
---|---|---|---|---|
AI Studio API Key Clipboard Automator | AI_Studio_API_Key_Clipboard_Automator.user.js |
Tampermonkey | ① 批量创建项目 ② 生成 Key 并自动复制到剪贴板 ③ 提取现有 Key 并复制到剪贴板 |
推荐(手机用户) — 全流程无需打开控制台 |
Google AI Studio Gemini Automation Suite | Google_AI_Studio_Gemini_Automation_Suite.user.js |
Tampermonkey | ① 批量创建项目 ② 生成 Key 并 输出到浏览器控制台 ③ 提取现有 Key 至控制台 |
推荐(电脑用户) |
Create-Projects | CreateProjects.js |
控制台脚本 | 仅批量创建项目 | 需手动粘贴到 Cloud Console |
Fetch-Api-Keys | FetchApiKeys.js |
控制台脚本 | 为每个项目生成 Key | 需手动粘贴到 AI Studio |
Fetch-All-Existing-Keys | FetchAllExistingKeys.js |
控制台脚本 | 提取账号下全部现有 Key | 需手动粘贴到 AI Studio |
本仓库的脚本可为你提供以下便利:
-
自动化项目创建
无需手动点击多次,即可在 Google Cloud Console 中批量创建若干项目。 -
自动化 API Key 生成
在 Google AI Studio 中为每个新项目自动生成 Gemini API Key,并将结果在浏览器控制台输出,方便统一管理与复制。 -
自动提取已有 API Key
扫描当前账号下已有的 API Key 并列表输出,让你不会遗失已有的 Key。
-
Google 账号
- 需登录 Google Cloud Console 与 Google AI Studio。
- 若设置了双因素认证(2FA)或使用企业/学校账号,请先完成解锁。
-
浏览器和网络
- 建议使用最新版 Chrome、Edge 或 Firefox。
- 确保网络畅通且可访问 Google 服务,否则脚本可能报错或卡住。
-
项目配额
- 免费账号默认可创建 12 个项目。若不够,可参考下文可选操作:申请更多项目配额。
下图简要说明了从登录到创建项目、生成 Key 的完整操作顺序:
┌────────────────────────────┐
│ 1. 登录 Google Cloud │
│ (若需 2FA 先解锁) │
└──────────────┬─────────────┘
│
▼
┌────────────────────────────┐
│ 2. (可选) 申请更多配额 │
└──────────────┬─────────────┘
│
▼
┌────────────────────────────┐
│ 3. 运行创建项目脚本 │
│ (批量创建新项目) │
└──────────────┬─────────────┘
│
▼
┌────────────────────────────┐
│ 4. 登录 AI Studio │
│ 打开 /apikey 页面 │
└──────────────┬─────────────┘
│
▼
┌────────────────────────────┐
│ 5. 运行生成 Key 脚本 │
│ (批量生成 API Key) │
└──────────────┬─────────────┘
│
▼
(可选) 如果已有 Key
┌────────────────────────────┐
│ 6. 运行提取 Key 脚本 │
│ (扫描已存在的所有Key) │
└────────────────────────────┘
两份 Tampermonkey 脚本顶部均有 CONFIG
常量(或直接在代码中有同名变量)可自定义参数:
参数 | 说明 | 默认值 |
---|---|---|
TARGET / PROJECT_CREATION_COUNT |
本轮创建的项目数量 | 5 |
API_KEYS_PER_PROJECT |
每个项目要生成的 Key 数 | 1 |
BETWEEN / PROJECT_CREATION_DELAY |
连续创建项目的间隔 (ms) | 5000 |
API_KEY_CREATION_DELAY |
连续生成 Key 的间隔 (ms) | 2500 |
SELECT_CHANGE_DELAY |
选择下拉框后额外等待 (ms) | 1000 |
MAXR |
创建异常时最多自动刷新次数 | 5 |
建议先按默认配置试运行;如出现超时/配额问题,再适当调大间隔或调低数量。
脚本文件:
Google_AI_Studio_Gemini_Automation_Suite.user.js
AI_Studio_API_Key_Clipboard_Automator.user.js
此油猴脚本将项目创建、API Key 生成与 Key 提取三大功能集成在一起,并在页面中插入浮动按钮,让操作更直观。
第一个脚本将 API KEY
输出在控制台,而后者自动复制到剪贴板,电脑端用户默认前者方便,手机端用户只能用后者。
-
安装 Tampermonkey
- 在浏览器插件商店搜索并安装 “Tampermonkey”(或其他用户脚本管理器)。
- 懒得搜索,也可以点这里直达
-
导入油猴脚本
- 将本仓库中的
Google_AI_Studio_Gemini_Automation_Suite.user.js
(AI_Studio_API_Key_Clipboard_Automator.user.js
)文件保存后,添加到 Tampermonkey。 - 若需自定义项目数、等待时间等配置,可在脚本开头的
CONFIG
对象中进行修改。
- 将本仓库中的
-
操作说明
- 在 Google Cloud Console:
进入 Google Cloud Console,页面右上角出现名为 “创建项目并获取APIKEY” 的按钮:- 若当前页面不在
console.cloud.google.com
域下,脚本会自动跳转到此域。 - 点击按钮后,脚本会按照配置批量创建项目,完成后自动记录标记并跳转到 Google AI Studio /apikey 页面。
- 若当前页面不在
- 在 Google AI Studio:
进入/apikey
页面后,脚本检测到标记并开始批量创建 API Key。- 对于首次下拉框点击,脚本会派发
change
事件并等待一小段时间(默认 1000 毫秒)以确保操作生效。
- 对于首次下拉框点击,脚本会派发
- 提取已有 Key:
点击浮动按钮 “提取APIKEY” 即可扫描并输出所有已存在的 Key 到浏览器控制台。
- 在 Google Cloud Console:
如果你更喜欢在 Console(浏览器开发者工具)中手动执行脚本,或只想执行部分功能,则可使用控制台脚本。
-
项目创建:
- 登录 Google Cloud Console
- 按
F12
打开开发者工具 → Console,将CreateProjects.js
文件中全部代码复制并粘贴,按 Enter 执行。
-
API Key 自动生成:
- 登录 Google AI Studio /apikey。
- 在 Console 中复制
FetchApiKeys.js
文件的全部代码并执行。
-
提取已有 Key(可选):
- 同样在 Google AI Studio /apikey 页面,Console 中复制
FetchAllExistingKeys.js
代码并执行,脚本会扫描并输出当前账号已有的所有 Key。
- 同样在 Google AI Studio /apikey 页面,Console 中复制
google-ai-gemini-key-scripts/
├─ AI_Studio_API_Key_Clipboard_Automator.user.js # 油猴脚本**自动复制到剪贴板**版(整合全部功能)
├─ CreateProjects.js # (Step 1) 控制台脚本版:自动创建项目脚本
├─ FetchApiKeys.js # (Step 2) 控制台脚本版:自动为项目创建并获取 API Key
├─ FetchAllExistingKeys.js # (Step 3, 可选) 控制台脚本版:提取所有已有的 API Key
├─ Google_AI_Studio_Gemini_Automation_Suite.user.js # 油猴脚本**控制台输出**版(整合全部功能)
├─ README.en.md # English documentation
└── README.md # 本文档(中文版)
-
脚本无反应或报错?
- 请确认已登录到正确的页面(Google Cloud Console / AI Studio),检查控制台报错信息。
- 若出现选择器失效,可能是 Google 界面改版导致,需要更新脚本。
- 网络不稳定也会导致脚本卡住或超时。
-
Key 没有生成或只生成部分?
- 可能是配额耗尽、网络波动或等待时间不足造成。
- 尝试降低一次性创建数量或增加等待延时(如
SELECT_CHANGE_DELAY
)。
-
会不会被 Google 封号?
- 脚本涉及自动批量操作,存在一定风险。请合理使用,避免短时间内频繁创建或删除项目与 Key。
-
如何申请更多项目配额?
- 请参见下方【可选操作:申请更多项目配额】或查看 Google 官方文档。
-
生成的 Key 如何使用?
- 一般在请求头中使用
Authorization: Bearer YOUR_KEY
。 - 具体请参考 Google AI Studio 官方文档。
- 一般在请求头中使用
-
首次生成 API Key 失败怎么办?
- 脚本点击下拉框后会触发
change
事件并等待默认 1000 毫秒,如仍失败,请适度调整该值或多尝试几次。
- 脚本点击下拉框后会触发
-
油猴脚本还是控制台脚本?
- 油猴脚本 一键式全自动,适合追求省事;
- 控制台脚本 手动复制粘贴,适合部分功能或调试。
若默认的 12 个项目额度不足,你可以在创建项目之前前往 配额申请页面 申请更多项目配额。具体步骤可参考本仓库或 Google 官方文档,一般需要填写合理的申请理由并等待审核。 以下是一种参考流程与示例理由,你也可以自行调整内容:
-
打开链接
https://support.google.com/code/contact/project_quota_increase -
填写基本信息
Company name or website
:可以写自己的域名、个人网站或干脆github.com
等。- 配额
How many projects are being requested? (ex. 5, 10, 20, 50, etc.)
:例如填100
。 - What kind of services will these projects use?
- 若你是付费用户,可选择
Both free and paid services
,相对减少被封可能。
- 若你是付费用户,可选择
-
编写理由
- 你可以直接粘贴以下示例,或做适当修改:
第一种:Iata Analysis
Our ongoing scientific research project requires substantial computational resources for analyzing increasingly complex datasets. We are experiencing limitations with our current quota when running advanced statistical analyses and computational modeling tasks essential to our research goals. An increased quota is necessary to ensure timely completion of our data analysis and to maintain progress in our research.
第二种:Expanding Simulation Capabilities for Scientific Modeling
Our research relies heavily on computational simulations to model complex scientific phenomena. We are currently expanding the scope and scale of our simulations, which demands a significant increase in computational resources. The current quota restricts our ability to run larger, more detailed simulations necessary for achieving higher fidelity and more accurate research outcomes. A quota increase is crucial to enable these advanced simulations.
第三种:Growing Data Storage Needs for Research Datasets
Our scientific research is generating increasingly large datasets that require secure and accessible storage. Our current storage quota is becoming insufficient to accommodate the growing volume of research data. An increased storage quota is essential to ensure we can continue to collect, store, and manage our research data effectively and maintain the integrity of our research outputs.
第四种:Increased API Usage for Data Acquisition and Integration
Our research project relies on programmatic access to external scientific databases and APIs to acquire and integrate data from various sources. As our research expands, our usage of these APIs has increased significantly. The current API request quota is limiting our ability to collect the necessary data for our research in a timely manner. A quota increase is needed to facilitate efficient data acquisition.
第五种:Supporting Collaborative Research and Data Sharing
Our research project involves collaboration with multiple research institutions and requires secure data sharing and collaborative analysis environments. The current quota limitations are hindering our ability to effectively support collaborative access to resources and data sharing among our research partners. An increased quota is needed to facilitate seamless collaboration and data sharing, which are critical for the success of our multi-institutional research project.
- 如在使用过程中遇到问题或有改进建议,欢迎在 GitHub 提交 Issue 或 Pull Request。
- 希望本项目能帮你批量创建项目与管理 API Key,节省宝贵时间。
- 感谢你的关注,也祝开发顺利!🚀