Google Gemini API
    Google Gemini API
    • Get API key
    • Release notes
    • Libraries
    • Run Gemini on Google Cloud
    • Model Capabilities
      • Overview
      • Long context
      • Structured output
      • Document understanding
      • Image understanding
      • Video understanding
      • Audio understanding
      • Text generation
        • Text input
        • Image input
        • Streaming output
        • Multi-turn conversations
        • Multi-turn conversations (Streaming)
        • Configuration parameters
      • Generate images
        • Generate images using Gemini
        • Image editing with Gemini
        • Generate images using Imagen 3
      • Gemini thinking
        • Use thinking models
        • Set budget on thinking models
      • Function calling
        • Function Calling with the Gemini API
    • models
      • All Model
      • Pricing
      • Rate limits
      • Billing info
    • Safety
      • Safety settings
      • Safety guidance

    Get API key

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

    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).
    Adding API key restrictions helps limit the scope of each API key.
    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.
    For general best practices, you can also refer to this support article.
    Next
    Release notes
    Built with