Skip to main content

Google Gemini

Google Gemini integration allows your product to connect with Google's multimodal AI models (Gemini 1.5 Pro, 1.5 Flash, and future versions) via the Google AI API (formerly PaLM / Bard API). This integration enables your product to perform text generation, summarization, code reasoning, image and file analysis, embeddings, and chat-based applications using Google's state-of-the-art Gemini models.

Credentials Needed

To integrate with the Google Gemini API, you need an API Key from Google AI Studio or a Service Account if you are integrating via Google Cloud.

Option 1 — API Key (Simpler Method):

  • Google AI API Key

Option 2 — Service Account (Enterprise Integration):

  • Service Account JSON Key File containing:
    • project_id
    • client_email
    • private_key

Use the API Key method for lightweight integrations, and Service Account method for secured, multi-user, or enterprise scenarios.

Permissions Needed / API Scopes

Gemini APIs use Google Cloud IAM and OAuth scopes for access control.

FunctionalityScope / PermissionDescription
Generate text / chathttps://www.googleapis.com/auth/generative-languageAllows text and chat generation
Generate multimodal content (text + image)Same as aboveUsed for Gemini 1.5 Pro and multimodal input
Embeddingshttps://www.googleapis.com/auth/generative-language.retrievalAllows embedding and retrieval APIs
API Key (no OAuth)Direct API key authSimplified key-based authentication for most use cases

For most integrations, you only need API Key access — OAuth scopes apply mainly for user-based or enterprise flows.

Creating Users / Access Tokens

Step 1: Generate an API Key (Recommended for Most Use Cases)

  1. Visit Google AI Studio: https://aistudio.google.com/
  2. Sign in with your Google account.
  3. Go to Get API key under the left panel or visit: https://aistudio.google.com/app/apikey
  4. Click Create API key.
  5. Copy the generated API key — it will start with AIza....

Step 2 (Alternative): Create a Service Account (Enterprise)

  1. Go to Google Cloud Console → IAM & Admin → Service Accounts.
  2. Click Create Service Account.
  3. Provide a name (e.g., GeminiIntegrationSA).
  4. Assign the following role:
    • Vertex AI User (roles/aiplatform.user)
  5. Click Continue → Done.
  6. Open the created service account → Keys → Add Key → Create New Key → JSON.
  7. Download the key file securely (e.g., gemini-service-key.json).

Test Connectivity

You can test Gemini using curl, the Google Generative AI SDK, or directly through the REST API:

Example: Using curl

curl \
-H "Content-Type: application/json" \
-H "x-goog-api-key: <GEMINI_API_KEY>" \
https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent \
-d '{
"contents": [{
"role": "user",
"parts": [{"text": "Hello Gemini! Can you confirm connectivity?"}]
}]
}'

If successful, you'll receive a JSON response with model output.

Example: Using Python SDK

from google import genai

client = genai.Client(api_key="<GEMINI_API_KEY>")
response = client.models.generate_content(
model="gemini-1.5-flash",
contents="Hello Gemini, this is a test!"
)
print(response.text)

Save the Results in the Platform and Create Connection

In your platform's integration module, securely store:

  • GEMINI_API_KEY (for API key auth)
  • or SERVICE_ACCOUNT_JSON (for enterprise auth)

Label the connection as Google Gemini Integration.

Test the connection by generating sample text or running a small chat completion request.

Best Practices

  • Use API keys for single-tenant or developer integrations; use Service Accounts for multi-tenant or enterprise setups.
  • Store credentials in a secret vault or Google Secret Manager, never in plain text.
  • Rotate API keys periodically.
  • Choose the right model:
    • Gemini 1.5 Flash — fast and cost-effective for chat, summarization, or light reasoning.
    • Gemini 1.5 Pro — for deeper reasoning, multimodal (text, image, code) tasks.
  • Handle rate limits gracefully — check error codes 429 (Too Many Requests).
  • Log token usage and monitor billing in the Google Cloud Console → Billing → Reports.
  • For multimodal input (image, text, file), ensure proper encoding (Base64 for images).
  • Follow Google AI safety and usage policies.