Manus Invitation Code Application Guide
Character.AI launches AvatarFX: AI video generation model allows static images to "open to speak"
Manychat completes US$140 million Series B financing, using AI to accelerate global social e-commerce layout
Google AI Overview Severely Impacts SEO Click-through Rate: Ahrefs Research shows traffic drop by more than 34%
To use the Gemini API, you need an API key. You can create a key in Google AI Studio in a few clicks.
Get Gemini API Key in Google AI Studio
For initial testing, you can hardcode the API key, but this should be temporary, as it is not safe to do so. The rest of this section will explain how to set the API key as an environment variable to a different operating system locally.
Bash is a common Linux and macOS terminal configuration. You can check if there is a corresponding configuration file by running the following command:
~/.bashrc
If the response is "No such file or directory" (no such file or directory), you need to run the following command to create and open this file, or use zsh :
touch ~/.bashrc open ~/.bashrc
Next, you need to add the following export command to set the API key:
export GEMINI_API_KEY=<YOUR_API_KEY_HERE>
After saving the file, apply the changes by running the following command:
source ~/.bashrc
Zsh is a common Linux and macOS terminal configuration. You can check if there is a corresponding configuration file by running the following command:
~/.zshrc
If the response is "No such file or directory" (no such file or directory), you need to run the following command to create and open this file, or use bash:
touch ~/.zshrc open ~/.zshrc
Next, you need to add the following export command to set the API key:
export GEMINI_API_KEY=<YOUR_API_KEY_HERE>
After saving the file, apply the changes by running the following command:
source ~/.zshrc
1. Search for "Environment Variables" in the system settings
2. Modify "User Variable" (applicable to the current user) or "System Variable" (applicable to all users, please use it with caution).
3. Create variables and add export GEMINI_API_KEY=your_key_here
4. Apply changes
You can verify settings using the curl command:
curl "https://generatedlanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent?key=${GEMINI_API_KEY}" -H 'Content-Type: application/json' -X POST -d '{ "contents": [{ "parts":[{"text": "Write a story about a magic backpack."}] }] }'
Be sure to make sure your Gemini API key is secure. When using Gemini API keys, please note the following:
1. Google AI Gemini API uses API keys for authorization. If others gain access to your Gemini API key, they can not only use the quota for your project, but may also cause quota churn or incur additional costs (for projects with billing enabled),
2. Adding API key restrictions helps limit the range each API key can use.
3. It is your responsibility to ensure the security of the Gemini API key.
Do not check the Gemini API key into the source control system.
Client applications (Android, Swift, Web, and Dart/Flutter) may compromise API keys. We do not recommend using the Google AI Client SDK in official applications to invoke the Google AI Gemini API directly from mobile and web applications.