Get an API key

To use the API, you need an API key. You can create a key with one click in Google AI Studio.

Get an API key

Verify your API key with a curl command

You can use a curl command to verify your setup. You can pass the API key either in the URL:

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"

Next steps

  • Check out the API quickstarts to learn best practices for securing your API key and using it.