To use this API, you need an API key. You can create one with a single click in Google AI Studio.Verify your API key using the curl command#
You can use the curl
command to verify your setup. You can pass the API key through either of the following URLs:API_KEY="YOUR_API_KEY"
curl -H 'Content-Type: application/json' \
-d '{"contents":[
{"role": "user",
"parts":[{"text": "Give me five subcategories of jazz?"}]}]}' \
"https://generativelanguage.googleapis.com/v1/models/gemini-pro:generateContent?key=${API_KEY}"
Or in the x-goog-api-key
header:API_KEY="YOUR_API_KEY"
curl -H 'Content-Type: application/json' \
-H "x-goog-api-key: ${API_KEY}" \
-d '{"contents":[
{"role": "user",
"parts":[{"text": "Give me five subcategories of jazz?"}]}]}' \
"https://generativelanguage.googleapis.com/v1/models/gemini-pro:generateContent"
Secure your API key#
It's crucial to keep your Gemini API key secure. Please note the following when using a Gemini API key:The Google AI Gemini API uses API keys for authorization. If someone gains access to your Gemini API key, they can use your project's quota for calls, potentially leading to quota depletion or additional charges (for projects with billing enabled).
You are responsible for ensuring the security of your Gemini API keys.Do not check Gemini API keys into source code control systems.
Client applications (Android, Swift, Web, and Dart/Flutter) may expose API keys. We do not recommend using the Google AI client SDK to call the Google AI Gemini API directly from mobile and web applications in production applications.
Modified at 2025-04-24 09:09:33