> ## Documentation Index
> Fetch the complete documentation index at: https://docs.coreflux.org/llms.txt
> Use this file to discover all available pages before exploring further.

# Vertex Ai

> 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

Technical Preview

## 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).

> [!NOTE]
>
> 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](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

| Placeholder | Type | Description | Required |
| - | - | - | - |
| `RouteName` | string | Name of the Vertex Ai connector | no |
| `BaseUrl` | string | Vertex Ai base URL without trailing slash (e.g. [https://YOUR\_REGION-aiplatform.googleapis.com](https://YOUR_REGION-aiplatform.googleapis.com)) | yes |

`BASE_ADDRESS` default: `https://YOUR_REGION-aiplatform.googleapis.com`.

## Events

| Event | Method | Endpoint | Request topic | Response topic | Payload fields |
| - | - | - | - | - | - |
| `VertexGenerateContent` | POST | `/v1/projects/YOUR_PROJECT_ID/locations/YOUR_REGION/publishers/google/models/{value.json.model}:generateContent` | `ai/gemini/vertex-content/generate` | `ai/gemini/vertex-content/generate/response` | `access_token`, `body`, `model` |
| `VertexCountTokens` | POST | `/v1/projects/YOUR_PROJECT_ID/locations/YOUR_REGION/publishers/google/models/{value.json.model}:countTokens` | `ai/gemini/vertex-tokens/count` | `ai/gemini/vertex-tokens/count/response` | `access_token`, `body`, `model` |
| `VertexEmbedPredict` | POST | `/v1/projects/YOUR_PROJECT_ID/locations/YOUR_REGION/publishers/google/models/{value.json.model}:predict` | `ai/gemini/vertex-embedding/predict` | `ai/gemini/vertex-embedding/predict/response` | `access_token`, `body`, `model` |
| `VertexEndpointPredict` | POST | `/v1/projects/YOUR_PROJECT_ID/locations/YOUR_REGION/endpoints/{value.json.endpoint_id}:predict` | `ai/gemini/vertex-endpoint/predict` | `ai/gemini/vertex-endpoint/predict/response` | `access_token`, `body`, `endpoint_id` |
| `VertexListEndpoints` | GET | `/v1/projects/YOUR_PROJECT_ID/locations/YOUR_REGION/endpoints?pageSize={value.json.page_size}` | `ai/gemini/vertex-endpoint/list` | `ai/gemini/vertex-endpoint/list/response` | `access_token`, `page_size` |
| `VertexGetEndpoint` | GET | `/v1/projects/YOUR_PROJECT_ID/locations/YOUR_REGION/endpoints/{value.json.endpoint_id}` | `ai/gemini/vertex-endpoint/get` | `ai/gemini/vertex-endpoint/get/response` | `access_token`, `endpoint_id` |

## Deploy

Get the template card (JSON with `template` and `metadata`) from the broker, then deploy the connector:

```bash theme={"theme":"css-variables","languages":{"custom":["/languages/lot.json"]}}
mosquitto_pub -t '$SYS/Coreflux/Command' -m "-routeCode VERTEX_AI"
```

The deployable connector from the REST API app, with `BASE_ADDRESS` already filled in:

```lot theme={"theme":"css-variables","languages":{"custom":["/languages/lot.json"]}}
DEFINE ROUTE VertexAiRestApi WITH TYPE REST_API
    ADD REST_API_CONFIG
        WITH BASE_ADDRESS "https://YOUR_REGION-aiplatform.googleapis.com"
        WITH ENABLE_CLIENT "true"
        WITH USE_SSL "true"
        WITH REQUEST_TIMEOUT '120'
        WITH DEFAULT_CONTENT_TYPE "application/json"
    ADD EVENT VertexGenerateContent
        WITH SOURCE_TOPIC "ai/gemini/vertex-content/generate"
        WITH DESTINATION_TOPIC "ai/gemini/vertex-content/generate/response"
        WITH METHOD "POST"
        WITH ENDPOINT "/v1/projects/YOUR_PROJECT_ID/locations/YOUR_REGION/publishers/google/models/{value.json.model}:generateContent"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "Content-Type" "application/json"
            ADD "Authorization" "Bearer {value.json.access_token}"
        WITH BODY "{value.json.body}"
    ADD EVENT VertexCountTokens
        WITH SOURCE_TOPIC "ai/gemini/vertex-tokens/count"
        WITH DESTINATION_TOPIC "ai/gemini/vertex-tokens/count/response"
        WITH METHOD "POST"
        WITH ENDPOINT "/v1/projects/YOUR_PROJECT_ID/locations/YOUR_REGION/publishers/google/models/{value.json.model}:countTokens"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "Content-Type" "application/json"
            ADD "Authorization" "Bearer {value.json.access_token}"
        WITH BODY "{value.json.body}"
    ADD EVENT VertexEmbedPredict
        WITH SOURCE_TOPIC "ai/gemini/vertex-embedding/predict"
        WITH DESTINATION_TOPIC "ai/gemini/vertex-embedding/predict/response"
        WITH METHOD "POST"
        WITH ENDPOINT "/v1/projects/YOUR_PROJECT_ID/locations/YOUR_REGION/publishers/google/models/{value.json.model}:predict"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "Content-Type" "application/json"
            ADD "Authorization" "Bearer {value.json.access_token}"
        WITH BODY "{value.json.body}"
    ADD EVENT VertexEndpointPredict
        WITH SOURCE_TOPIC "ai/gemini/vertex-endpoint/predict"
        WITH DESTINATION_TOPIC "ai/gemini/vertex-endpoint/predict/response"
        WITH METHOD "POST"
        WITH ENDPOINT "/v1/projects/YOUR_PROJECT_ID/locations/YOUR_REGION/endpoints/{value.json.endpoint_id}:predict"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "Content-Type" "application/json"
            ADD "Authorization" "Bearer {value.json.access_token}"
        WITH BODY "{value.json.body}"
    ADD EVENT VertexListEndpoints
        WITH SOURCE_TOPIC "ai/gemini/vertex-endpoint/list"
        WITH DESTINATION_TOPIC "ai/gemini/vertex-endpoint/list/response"
        WITH METHOD "GET"
        WITH ENDPOINT "/v1/projects/YOUR_PROJECT_ID/locations/YOUR_REGION/endpoints?pageSize={value.json.page_size}"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "Authorization" "Bearer {value.json.access_token}"
    ADD EVENT VertexGetEndpoint
        WITH SOURCE_TOPIC "ai/gemini/vertex-endpoint/get"
        WITH DESTINATION_TOPIC "ai/gemini/vertex-endpoint/get/response"
        WITH METHOD "GET"
        WITH ENDPOINT "/v1/projects/YOUR_PROJECT_ID/locations/YOUR_REGION/endpoints/{value.json.endpoint_id}"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "Authorization" "Bearer {value.json.access_token}"
```

Deploy it with `-addRoute` (do not include `ADD METADATA`).

## Usage example

Call `VertexGenerateContent` by publishing a JSON payload to its request topic, and read the reply on the response topic:

```bash theme={"theme":"css-variables","languages":{"custom":["/languages/lot.json"]}}
mosquitto_sub -t 'ai/gemini/vertex-content/generate/response' &
mosquitto_pub -t 'ai/gemini/vertex-content/generate' -m '{"access_token": "<access_token>", "body": {}, "model": "<model>"}'
```

## Related

* [REST API Connectors](/latest/lot-language/routes/rest-api-routes)
* [REST API Apps catalog](/latest/lot-language/routes/rest-api-apps)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.