Overview
Client-mode REST API connectors for Google Gemini: triage alarms and summarize shift logs with generateContent (structured JSON output), create embeddings, count tokens and list models with a Gemini API key, run Gemini and custom anomaly models on Vertex AI (predict on your endpoint), and get Google OAuth 2.0 access tokens. This is one of the templates in the Google Gemini API and Vertex AI REST API app (google-gemini-api-and-vertex-ai). Deploy it alongside the other connectors of that app when they depend on each other (for example a token connector plus an API connector).
Not yet verified against the live vendor API: Needs either (a) a Gemini API key: a Google account with Google AI Studio (aistudio.google.com/apikey) or a Google Cloud project with the Generative Language API enabled and an API key restricted to it (free tier is enough for the smoke, but unpaid-tier prompts may be used by Google, so a paid / billing-enabled project is preferred for plant data), and/or (b) Vertex AI access: a Google Cloud project with billing and the Vertex AI API (aiplatform.googleapis.com) enabled, a region (e.g. europe-west1; or global), and an OAuth 2.0 access token with scope cloud-platform for an identity holding roles/aiplatform.user: either a short-lived token (gcloud auth print-access-token), an OAuth client id + client secret + refresh token for the refresh_token grant, or a service account key to sign the JWT bearer assertion outside the broker; optionally a custom model (e.g. anomaly detector) deployed to a Vertex AI endpoint with its endpoint id and a sample instances JSON for VertexEndpointPredict. Hub secrets GEMINI_API_KEY / GOOGLE_OAUTH_CLIENT_ID / GOOGLE_OAUTH_CLIENT_SECRET / GOOGLE_OAUTH_REFRESH_TOKEN. Gate (Gemini API): ListModels 200 (GET) + GetModel 200 + CountTokens 200 + GenerateContent 200 with structured JSON (POST) + EmbedContent 200 + BatchEmbedContents 200 via GEMINI_API_KEY=<key> python3 smoke_gemini.py; gate (Vertex AI): [RefreshToken 200] + VertexListEndpoints 200 (GET) + VertexGenerateContent 200 (POST) + VertexCountTokens 200 + VertexEmbedPredict 200 [+ VertexGetEndpoint 200 + VertexEndpointPredict 200 with VERTEX_ENDPOINT_ID + VERTEX_INSTANCES_JSON] via VERTEX_PROJECT VERTEX_REGION (VERTEX_ACCESS_TOKEN | GOOGLE_OAUTH_CLIENT_ID GOOGLE_OAUTH_CLIENT_SECRET GOOGLE_OAUTH_REFRESH_TOKEN) python3 smoke_gemini.py; either gate clears ready for its connector, ideally plus a broker MQTT round-trip. No Gemini / Google Cloud credentials on the factory box (no GEMINI_API_KEY / GOOGLE_API_KEY / VERTEX_* env, nothing in runtime/). Spec cross-check 100/100, local contract mock 39/39 and real unauthenticated probes 21/21 (generativelanguage.googleapis.com: fake key 400 API_KEY_INVALID on all 6 Gemini events, no key 403 PERMISSION_DENIED unregistered callers; europe-west1-aiplatform.googleapis.com: fake Bearer 401 UNAUTHENTICATED on all 6 Vertex events, empty Bearer 401 CREDENTIALS_MISSING; oauth2.googleapis.com: bogus client 401 invalid_client, bogus JWT 400 invalid_scope; controls :generateContentX, :predictX, /v9 -> 404) are partial evidence only.
Auth
Gemini API: header x-goog-api-key {value.json.api_key} (Google AI Studio / Cloud API key; Hub secret GEMINI_API_KEY via GET SECRET). Vertex AI: Authorization: Bearer {value.json.access_token}, OAuth 2.0 access token with scope https://www.googleapis.com/auth/cloud-platform for an identity with roles/aiplatform.user (~1 h lifetime); GoogleOAuthToken connector gets it (refresh_token grant with client id/secret/refresh token, or service-account JWT bearer grant with a JWT signed outside the broker). Hub secrets GEMINI_API_KEY, GOOGLE_OAUTH_CLIENT_ID, GOOGLE_OAUTH_CLIENT_SECRET, GOOGLE_OAUTH_REFRESH_TOKEN. Never commit keys, tokens or service-account JSON. Auth headers used by the template:Authorization: Bearer {value.json.access_token}.
Template parameters
BASE_ADDRESS default: https://YOUR_REGION-aiplatform.googleapis.com.
Events
Deploy
Get the template card (JSON withtemplate and metadata) from the broker, then deploy the connector:
BASE_ADDRESS already filled in:
-addRoute (do not include ADD METADATA).
Usage example
CallVertexGenerateContent by publishing a JSON payload to its request topic, and read the reply on the response topic:

