c

c

世上本没有路
tg_channel
mastodon
pleroma

Gemini API KEY Application and Usage

Gemini

Gemini, developed by Google, is one of the competitors of ChatGPT. Gemini recently launched a free API for users to use. The application process is very simple and does not require any payment verification. Among all similar products that offer official APIs, Gemini has the lowest threshold, without a doubt.

Currently, only the free version of Gemini is available. You can make sixty requests per minute.

Register and Get API Key#

Currently, Gemini supports the following regions. Please use the network of these regions to access Google AI Studio.

(It's amazing how some friends cannot use Gemini in their location! So I have specially listed all the regions where Gemini is available on this webpage. Dear visitors, it's time to exercise your hand muscles! Scroll your mouse wheel or swipe your phone back and forth to make your fingers true athletes!)

  • Algeria
  • American Samoa
  • Angola
  • Anguilla
  • Antarctica
  • Antigua and Barbuda
  • Argentina
  • Armenia
  • Aruba
  • Australia
  • Azerbaijan
  • Bahamas
  • Bahrain
  • Bangladesh
  • Barbados
  • Belize
  • Benin
  • Bermuda
  • Bhutan
  • Bolivia
  • Botswana
  • Brazil
  • British Indian Ocean Territory
  • British Virgin Islands
  • Brunei
  • Burkina Faso
  • Burundi
  • Cape Verde
  • Cambodia
  • Cameroon
  • Caribbean Netherlands
  • Cayman Islands
  • Central African Republic
  • Chad
  • Chile
  • Christmas Island
  • Cocos (Keeling) Islands
  • Colombia
  • Comoros
  • Cook Islands
  • Côte d'Ivoire
  • Costa Rica
  • Curaçao
  • Democratic Republic of the Congo
  • Djibouti
  • Dominica
  • Dominican Republic
  • Ecuador
  • Egypt
  • El Salvador
  • Equatorial Guinea
  • Eritrea
  • Eswatini
  • Ethiopia
  • Falkland Islands (Malvinas)
  • Fiji
  • Gabon
  • Gambia
  • Georgia
  • Ghana
  • Gibraltar
  • Grenada
  • Guam
  • Guatemala
  • Guernsey
  • Guinea
  • Guinea-Bissau
  • Guyana
  • Haiti
  • Heard Island and McDonald Islands
  • Honduras
  • India
  • Indonesia
  • Iraq
  • Isle of Man
  • Israel
  • Jamaica
  • Japan
  • Jersey
  • Jordan
  • Kazakhstan
  • Kenya
  • Kiribati
  • Kyrgyzstan
  • Kuwait
  • Laos
  • Lebanon
  • Lesotho
  • Liberia
  • Libya
  • Madagascar
  • Malawi
  • Malaysia
  • Maldives
  • Mali
  • Marshall Islands
  • Mauritania
  • Mauritius
  • Mexico
  • Micronesia
  • Mongolia
  • Montserrat
  • Morocco
  • Mozambique
  • Namibia
  • Nauru
  • Nepal
  • New Caledonia
  • New Zealand
  • Nicaragua
  • Niger
  • Nigeria
  • Niue
  • Norfolk Island
  • Northern Mariana Islands
  • Oman
  • Pakistan
  • Palau
  • Palestine
  • Panama
  • Papua New Guinea
  • Paraguay
  • Peru
  • Philippines
  • Pitcairn Islands
  • Puerto Rico
  • Qatar
  • Republic of the Congo
  • Rwanda
  • Saint Barthélemy
  • Saint Kitts and Nevis
  • Saint Lucia
  • Saint Pierre and Miquelon
  • Saint Vincent and the Grenadines
  • Saint Helena, Ascension and Tristan da Cunha
  • Samoa
  • São Tomé and Príncipe
  • Saudi Arabia
  • Senegal
  • Seychelles
  • Sierra Leone
  • Singapore
  • Solomon Islands
  • Somalia
  • South Africa
  • South Georgia and the South Sandwich Islands
  • South Korea
  • South Sudan
  • Sri Lanka
  • Sudan
  • Suriname
  • Taiwan
  • Tajikistan
  • Tanzania
  • Thailand
  • Timor-Leste
  • Togo
  • Tokelau
  • Tonga
  • Trinidad and Tobago
  • Tunisia
  • Turkey
  • Turkmenistan
  • Turks and Caicos Islands
  • Tuvalu
  • Uganda
  • United Arab Emirates
  • United States
  • United States Minor Outlying Islands
  • United States Virgin Islands
  • Uruguay
  • Uzbekistan
  • Vanuatu
  • Venezuela
  • Vietnam
  • Wallis and Futuna
  • Western Sahara
  • Yemen
  • Zambia
  • Zimbabwe

After exploring the available regions for Gemini, continue to apply for the API and open the door to more surprises and creativity:

Agree to the relevant agreements. Click "get API key" in the left sidebar. Then click "Create API key in new project" on the right to obtain the API key.

Usage#

Note: You need to use the network of the aforementioned regions to use Gemini.

Open the terminal and run the following command for testing (On Windows, open the command prompt in the attachment, you can search for it). Note: Please replace <API_KEY> with your API key.

curl -sS "https://generativelanguage.googleapis.com/v1beta/models/gemini-pro:generateContent?key=<API_KEY>" -H "Content-Type: application/json" -X POST -d "{\"contents\": [{\"parts\":[{\"text\": \"你好,请问你是谁?\"}]}]}"

If the returned content is as follows, it means that your region is not supported, which means it is not in the long list of regions I just mentioned.

{
  "error": {
    "code": 400,
    "message": "User location is not supported for the API use.",
    "status": "FAILED_PRECONDITION"
  }
}

You can also use Python to test if you can use Gemini. Of course, the official provides examples of using different programming languages and libraries here.

import requests

url = 'https://generativelanguage.googleapis.com/v1beta/models/gemini-pro:generateContent?key=' + <API_KEY>
headers = {'Content-Type': 'application/json'}
data = {
    "contents": [{
        "parts": [{
            "text": "你好,请问你是谁? "
        }]
    }]
}

response = requests.post(url, headers=headers, json=data)
print(response.json())

The example uses Chinese. Currently, the official supports the following languages:

  • Arabic (ar)
  • Bengali (bn)
  • Bulgarian (bg)
  • Chinese (Simplified and Traditional) (zh)
  • Croatian (hr)
  • Czech (cs)
  • Danish (da)
  • Dutch (nl)
  • English (en)
  • Estonian (et)
  • Finnish (fi)
  • French (fr)
  • German (de)
  • Greek (el)
  • Hebrew (iw)
  • Hindi (hi)
  • Hungarian (hu)
  • Indonesian (id)
  • Italian (it)
  • Japanese (ja)
  • Korean (ko)
  • Latvian (lv)
  • Lithuanian (lt)
  • Norwegian (no)
  • Polish (pl)
  • Portuguese (pt)
  • Romanian (ro)
  • Russian (ru)
  • Serbian (sr)
  • Slovak (sk)
  • Slovenian (sl)
  • Spanish (es)
  • Swahili (sw)
  • Swedish (sv)
  • Thai (th)
  • Turkish (tr)
  • Ukrainian (uk)
  • Vietnamese (vi)

For more usage, please refer to the official documentation Gemini API Tutorials | Google AI for Developers.

Yes, this tutorial ends here. It's easier than eating potato chips with just a few clicks!

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.