一键重装系统工具 | U盘启动盘制作工具 | 误删文件恢复软件 | 硬盘数据抢救专家 | 电脑蓝屏修复助手 | C盘空间清理神器 | 电脑驱动离线安装工具 | 微信聊天记录恢复工具 | 照片误格式化恢复 | 电脑密码破解清除工具 | 系统崩溃紧急救援盘 | 电脑加速优化大师 | 电脑开不了机怎么重装系统 | 回收站清空了怎么恢复 | 硬盘分区丢失数据恢复 | 电脑卡顿重装系统有用吗 | U盘插入提示格式化数据恢复 | 电脑中毒文件被隐藏恢复 | 忘记电脑开机密码怎么办 | 新硬盘分区对齐工具 | 旧电脑装Win10流畅工具 | SD卡照片删除恢复免费版 | 移动硬盘打不开提示损坏修复 | 电脑无故重启系统修复工具 | 电脑小白一键重装神器 | 程序员电脑环境配置助手 | 设计师电脑字体/素材恢复工具 | 网吧网管系统维护工具箱 | 财务人员电脑发票备份恢复 | 学生党免费电脑系统安装包 | 电脑维修师傅必备工具盘 | 游戏玩家电脑性能优化助手 | 办公白领误删文档恢复软件 | 自媒体视频素材恢复工具 | 网课录制视频损坏修复工具 | 最好的U盘PE系统排名 | 数据恢复软件哪个最强 | 免费电脑助手与收费版区别 | 国产装机工具哪款无广告 | 离线版驱动助手推荐 | 轻量级电脑优化工具对比 | 支持NVMe驱动的PE工具 | 带网络功能的应急启动盘 | 2026最新版万能装机工具 | 支持Win11 24H2的PE工具 | 最新免激活系统重装工具 | 2026数据恢复软件破解版合集 | 纯净无捆绑装机助手V3.0 | 支持苹果M芯片的电脑助手 | 秋季更新版系统维护工具箱 | 电脑系统崩了怎么用U盘把重要资料拷贝出来 | 重装系统前哪些文件夹必须备份 | 固态硬盘误格式化还能恢复数据吗 | 如何制作一个既带PE又能存数据的双分区U盘 | 电脑总是弹窗广告用什么助手彻底拦截 后台管理
📢 欢迎访问系统之家!所有资源均经过安全检测。

Using Gemini API keys

发布时间:2026-09-11 | 浏览:2
📥 下载地址(文章开头)
软件神器安装一切软件。
Español – América Latina Português – Brasil To use the Gemini API, you must authenticate your requests. You can authenticate using a standard or authorization API key. Create or view a Gemini API Key API key types: standard versus authorization API keys provide access to the Gemini API, but their security characteristics differ. The Gemini API is transitioning from standard API keys to authorization keys to improve security: Standard API keys : Associate requests with a Google Cloud project for billing and quota purposes. Standard keys don't identify a caller, which limits the granularity of permissions and access control they can support. Authorization (auth) keys : Bound directly to a Google Cloud service account. When you use an authorization key, your requests are processed under the identity of that bound service account, enabling granular access control. Authorization keys are restricted to the Generative Language API (Gemini API) by default and provide fast-acting leaked key enforcement that quickly stops the usage of leaked keys detected by our systems. To ensure secure usage, Gemini API will move from Standard keys to Auth keys: Auth keys default : All new API keys created in Google AI Studio are automatically created as auth keys. Unrestricted keys rejected : The Gemini API rejects requests from unrestricted standard keys . Standard API keys that have explicit restrictions applied continue to work. This restriction prevents the unauthorized use of keys that might be shared publicly or linked to other services. On September 2026 : the Gemini API will reject requests from Standard keys . You must migrate to auth keys before this date to avoid service interruption. Make sure to migrate to auth keys before September 2026. Managing API keys in Google AI Studio You can manage your projects and keys directly in Google AI Studio . Google Cloud projects Every Gemini API key is associated with a Google Cloud project . Google Cloud projects manage billing, collaborators, and permissions. Google AI Studio provides a lightweight interface to access these projects. Default project : If you are a new user, Google AI Studio automatically creates a default Google Cloud project and API key after you accept the Terms of Service. You can rename this project by navigating to the Projects view in your dashboard. Existing projects : If you already have a Google Cloud account, AI Studio does not create a default project. Instead, you must import your existing projects. Importing projects By default, Google AI Studio does not display all of your Google Cloud projects. You must import the projects you want to use: Go to Google AI Studio . Open the Dashboard from the left panel and select Projects . Click the Import projects button. Search for and select the Google Cloud project you want to import, then click Import . Once imported, navigate to the API Keys page in the dashboard to create a key in that project. Troubleshooting key creation permissions If the Create API key button is unavailable and displays the message: "You do not have permission to create a key in this project" , you lack the required IAM permissions. Ask your Google Cloud project or organization administrator to grant you a role containing the following permissions (such as Project Editor): resourcemanager.projects.get : Allows AI Studio to verify the project. apikeys.keys.create : Allows key generation. serviceusage.services.enable : Ensures the Generative Language API is enabled. iam.serviceAccounts.create : Required to create the linked service account. iam.serviceAccountApiKeyBindings.create : Binds the service account to the API key. If you cannot get administrative access, you can create a new Google Cloud project that is not associated with an organization to generate your keys. Setting up your environment Once you have a key, configure your environment to use it securely in your applications. Option 1: Use environment variables (recommended) Set the environment variable GEMINI_API_KEY or GOOGLE_API_KEY . The Gemini API client libraries automatically detect and use these variables. If both are set, GOOGLE_API_KEY takes precedence. Select your operating system to set the variable: Linux/macOS - Bash Verify if you have a bash configuration file: If not, create one and open it: Add the export command at the end of the file: Save the file, then apply the changes: Verify if you have a zsh configuration file: If not, create one and open it: Add the export command: Save the file, then apply the changes: Search for "Environment Variables" in the Windows search bar. Click Environment Variables in the System Properties dialog. Under User variables or System variables , click New... . Set the variable name to GEMINI_API_KEY and the value to your API key. Click OK to save. Open a new terminal session to load the variable. Option 2: Provide the API key explicitly in code You can pass the API key explicitly when initializing the client. Only do this if you cannot use environment variables.
📥 下载地址(文章中间)
软件神器安装一切软件。
Security and secret management Treat your Gemini API key like a password. If compromised, others can consume your project's quota, incur unexpected billing charges, and access private resources. Critical security rules Keep keys confidential : Never check API keys into source control systems like Git. Never expose keys client-side in production : Do not hardcode API keys directly in web or mobile apps. Keys compiled in client-side code can be extracted by users. To secure client-side apps, run a backend proxy server to make the actual API calls. Secret management best practices Environment variables : Read keys from environment variables rather than configuration files. Secret Manager : For production, store your keys in a secure secret store such as Google Cloud Secret Manager . Billing alerts : Set up billing alerts in the Google Cloud Console to notify you if usage or costs spike. Leak response checklist If you suspect your API key has been leaked: Generate a new key : Create a replacement key in Google AI Studio or the Cloud Console. Update your application : Deploy your code using the new key. Disable or delete the compromised key : Disable the leaked key in the Cloud Console once the new key is verified. Do not delete the old key until the new key is fully active to avoid application downtime. Audit usage : Check billing logs and API usage in the Google Cloud Console to identify unauthorized activity. Restricting and securing your keys Adding restrictions to your API keys minimizes the potential damage if a key is compromised. Apply request origin restrictions Origin restrictions limit which IP addresses, websites, or applications can use your key. Go to the Google Cloud Console Credentials page . Select your project, and click the name of the API key you want to restrict. Under Application restrictions , select IP addresses (or the appropriate restriction type for your environment). Specify the allowed IP addresses or ranges, then click Save . Securing unrestricted standard API keys To continue using the Gemini API, you must secure any unrestricted keys. Method A: Restrict the key to the Gemini API only (AI Studio) If you only use the key for the Gemini API, secure it directly in AI Studio: On the API Keys page in Google AI Studio , locate keys marked with the Unrestricted label. Hover over the label and click Add restrictions in the dialog. Select Restrict to Gemini API only . Click Restrict key to confirm. Method B: Restrict the key for other services (Google Cloud Console) If the key is shared with other Google APIs (not recommended), restrict it in the Cloud Console. Note: Gemini API requests using this key will fail after these restrictions are applied. Visit the Google Cloud Console Credentials page . Select the project and the API key. Under API restrictions , use the Select API restrictions drop-down to select the APIs you want this key to access. Do not select the Generative Language API . Click Save . Create a separate, restricted key in AI Studio to continue using the Gemini API. Blocked dormant keys Starting May 7, 2026, the Gemini API blocks unrestricted API keys that have been dormant for an extended period. These keys show a Blocked tag in AI Studio. You must generate a new key or use an existing restricted key to continue. Migrate to an auth key Follow these steps to create a new auth API key and update your applications: Go to the AI Studio API Keys page . Check the Key Type column to identify any keys listed as Standard . Click Create API key to generate a new key. All new keys created in AI Studio are automatically created as auth keys. Copy the new auth API key. Update your application code, environment variables, and any deployment configurations to use the new auth API key. Test your application to confirm it works correctly with the new key. Once verified, delete or revoke your old traffic key to prevent misuse. Google AI Studio imposes the following project and key management limitations: You can create a maximum of 10 projects at a time from the Google AI Studio Projects page. The API keys and Projects pages display a maximum of 100 keys and 50 projects. Only API keys that are unrestricted or restricted specifically to the Generative Language API (Gemini API) are displayed. For advanced project management or to modify keys with other restrictions, use the Google Cloud Console credentials page . Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License , and code samples are licensed under the Apache 2.0 License . For details, see the Google Developers Site Policies . Java is a registered trademark of Oracle and/or its affiliates. Last updated 2026-09-02 UTC.
📥 下载地址(文章结尾)
软件神器安装一切软件。