@rawdash/connector-vertex-ai 0.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +140 -0
- package/dist/index.d.ts +479 -0
- package/dist/index.js +1080 -0
- package/dist/index.js.map +1 -0
- package/package.json +44 -0
package/README.md
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
<!-- This file is generated from connector metadata by scripts/generate-connector-docs.ts. Do not edit by hand. -->
|
|
2
|
+
|
|
3
|
+
# @rawdash/connector-vertex-ai
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@rawdash/connector-vertex-ai)
|
|
6
|
+
[](https://github.com/rawdash/rawdash/blob/main/LICENSE)
|
|
7
|
+
|
|
8
|
+
Sync daily Vertex AI model invocations, token counts, errors, and spend (Gemini and partner models) into a single dashboard view of GCP AI usage.
|
|
9
|
+
|
|
10
|
+
> **Cost & frequency.** Each BigQuery spend query is billed against the bqProject. Prefer once-a-day syncs unless you need fresher invocation counts. Recommended sync interval: **1 day**. Minimum sensible interval: **1 hour**. Each sync costs roughly: 2 Cloud Monitoring requests, plus 1 BigQuery query when bqProject/bqDataset are set.
|
|
11
|
+
|
|
12
|
+
## Install
|
|
13
|
+
|
|
14
|
+
```sh
|
|
15
|
+
npm install @rawdash/connector-vertex-ai
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Authentication
|
|
19
|
+
|
|
20
|
+
Authenticate against the Cloud Monitoring v3 API (and optionally BigQuery for spend) with a Google service account JSON key. The service account needs the Monitoring Viewer role on the project running Vertex AI. To sync spend, it additionally needs BigQuery Data Viewer on the billing dataset and BigQuery Job User on the billing project.
|
|
21
|
+
|
|
22
|
+
1. Identify the GCP project running Vertex AI (it owns the publisher/online_serving metrics).
|
|
23
|
+
2. Create a service account at Google Cloud -> IAM & Admin -> Service Accounts in that project (or grant an existing one access).
|
|
24
|
+
3. Grant the service account the Monitoring Viewer role (roles/monitoring.viewer) on the project so it can read Vertex AI metrics.
|
|
25
|
+
4. To sync spend, enable the Cloud Billing -> BigQuery export (Billing -> Billing export -> BigQuery export). Then grant the service account roles/bigquery.dataViewer on the export dataset and roles/bigquery.jobUser on the bqProject.
|
|
26
|
+
5. Generate a JSON key for the service account and store its contents as a secret (e.g. GCP_SA_JSON).
|
|
27
|
+
6. Reference the key from config as serviceAccountJson: secret("GCP_SA_JSON") and set projectId to the Vertex AI project. Set bqProject / bqDataset to enable the spend resource.
|
|
28
|
+
|
|
29
|
+
## Configuration
|
|
30
|
+
|
|
31
|
+
| Field | Type | Required | Description |
|
|
32
|
+
| -------------------- | ------ | -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
33
|
+
| `projectId` | string | Yes | Google Cloud project ID that hosts the Vertex AI workload. Cloud Monitoring metrics are read from this project. |
|
|
34
|
+
| `serviceAccountJson` | secret | Yes | Contents of the JSON key file for a Google service account with the role required by this connector. Create one at Google Cloud -> IAM & Admin -> Service Accounts and store the JSON as a secret. |
|
|
35
|
+
| `bqProject` | string | No | Project that hosts the Cloud Billing -> BigQuery export. Required to sync the spend resource; omit to disable spend syncing. |
|
|
36
|
+
| `bqDataset` | string | No | BigQuery dataset containing the Cloud Billing export tables (gcp*billing_export_v1*\*). Required to sync the spend resource. |
|
|
37
|
+
| `bqLocation` | string | No | Region or multi-region of the billing dataset (e.g. US, EU, us-central1). Defaults to US when bqDataset is set. |
|
|
38
|
+
| `spendServiceFilter` | string | No | BigQuery LIKE pattern matched against service.description to scope spend rows to Vertex AI. Defaults to "Vertex AI%" which covers both "Vertex AI" and "Vertex AI Generative AI" services. |
|
|
39
|
+
| `lookbackDays` | number | No | How many days of history to pull on a full sync. Defaults to 30. |
|
|
40
|
+
|
|
41
|
+
## Resources
|
|
42
|
+
|
|
43
|
+
- **`vertex_ai_invocations`** _(metric)_ - Daily count of successful Vertex AI model invocations (HTTP 2xx) per (date, modelId). Sourced from the Cloud Monitoring metric `aiplatform.googleapis.com/publisher/online_serving/model_invocation_count`, aggregated to one sample per day with SUM.
|
|
44
|
+
- Endpoint: `GET /v3/projects/{projectId}/timeSeries`
|
|
45
|
+
- Granularity: daily
|
|
46
|
+
- Dimensions: `modelId`, `responseCode`
|
|
47
|
+
- On every sync the trailing `lookbackDays` window is rewritten idempotently. Non-2xx response codes flow to `vertex_ai_errors` instead.
|
|
48
|
+
- **`vertex_ai_errors`** _(metric)_ - Daily count of failed Vertex AI model invocations (non-2xx) per (date, modelId, errorType). Sourced from the same Cloud Monitoring API call as `vertex_ai_invocations`; rows with response_code outside 200-299 are routed here.
|
|
49
|
+
- Endpoint: `GET /v3/projects/{projectId}/timeSeries (shared with vertex_ai_invocations)`
|
|
50
|
+
- Granularity: daily
|
|
51
|
+
- Dimensions: `modelId`, `errorType`
|
|
52
|
+
- errorType carries the upstream HTTP status (e.g. 400, 429, 500). Use it to slice quota errors (429) from request errors (4xx) and platform errors (5xx). The response schema is registered under `vertex_ai_invocations`.
|
|
53
|
+
- **`vertex_ai_tokens`** _(metric)_ - Daily Vertex AI token usage per (date, modelId, tokenType). Sourced from the Cloud Monitoring metric `aiplatform.googleapis.com/publisher/online_serving/token_count`. tokenType is either `input` (prompt) or `output` (completion).
|
|
54
|
+
- Endpoint: `GET /v3/projects/{projectId}/timeSeries`
|
|
55
|
+
- Granularity: daily
|
|
56
|
+
- Dimensions: `modelId`, `tokenType`
|
|
57
|
+
- Sum across both tokenType values to get total tokens; slice by tokenType to separate input from output cost drivers.
|
|
58
|
+
- **`vertex_ai_spend`** _(metric)_ - Daily Vertex AI spend per (date, sku) sourced from the Cloud Billing -> BigQuery export. Skipped unless bqProject and bqDataset are configured.
|
|
59
|
+
- Endpoint: `POST /bigquery/v2/projects/{bqProject}/queries`
|
|
60
|
+
- Unit: USD
|
|
61
|
+
- Granularity: daily
|
|
62
|
+
- Dimensions: `sku`, `service`, `currency`
|
|
63
|
+
- The trailing 5 days are always refetched on incremental syncs to pick up GCP back-revisions. SKU describes the specific Vertex AI model and token type (e.g. "Gemini 1.5 Pro Online Inference - Input").
|
|
64
|
+
|
|
65
|
+
## Example
|
|
66
|
+
|
|
67
|
+
```ts
|
|
68
|
+
import {
|
|
69
|
+
defineConfig,
|
|
70
|
+
defineDashboard,
|
|
71
|
+
defineMetric,
|
|
72
|
+
secret,
|
|
73
|
+
} from '@rawdash/core';
|
|
74
|
+
|
|
75
|
+
const vertexAi = {
|
|
76
|
+
name: 'vertexAi',
|
|
77
|
+
connectorId: 'vertex-ai',
|
|
78
|
+
config: {
|
|
79
|
+
projectId: 'my-project-123',
|
|
80
|
+
serviceAccountJson: secret('GCP_SA_JSON'),
|
|
81
|
+
bqProject: 'my-billing-project',
|
|
82
|
+
bqDataset: 'billing_export',
|
|
83
|
+
bqLocation: 'US',
|
|
84
|
+
lookbackDays: 30,
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
export default defineConfig({
|
|
89
|
+
connectors: [vertexAi],
|
|
90
|
+
dashboards: {
|
|
91
|
+
ai: defineDashboard({
|
|
92
|
+
widgets: {
|
|
93
|
+
invocations: {
|
|
94
|
+
kind: 'stat',
|
|
95
|
+
title: 'Invocations (24h)',
|
|
96
|
+
metric: defineMetric({
|
|
97
|
+
connector: vertexAi,
|
|
98
|
+
shape: 'metric',
|
|
99
|
+
name: 'vertex_ai_invocations',
|
|
100
|
+
fn: 'sum',
|
|
101
|
+
}),
|
|
102
|
+
},
|
|
103
|
+
spend: {
|
|
104
|
+
kind: 'timeseries',
|
|
105
|
+
title: 'Vertex AI spend',
|
|
106
|
+
window: '30d',
|
|
107
|
+
metric: defineMetric({
|
|
108
|
+
connector: vertexAi,
|
|
109
|
+
shape: 'metric',
|
|
110
|
+
name: 'vertex_ai_spend',
|
|
111
|
+
fn: 'sum',
|
|
112
|
+
}),
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
}),
|
|
116
|
+
},
|
|
117
|
+
});
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
## Rate limits
|
|
121
|
+
|
|
122
|
+
Cloud Monitoring projects.timeSeries.list and BigQuery jobs.query are rate-limited per project; 429 / RESOURCE_EXHAUSTED responses are retried with backoff. Each sync issues at most three requests (invocations metric, tokens metric, optional BigQuery query).
|
|
123
|
+
|
|
124
|
+
## Limitations
|
|
125
|
+
|
|
126
|
+
- Only the publisher (Gemini and partner online-serving) metric family is synced. Custom model deployments under aiplatform.googleapis.com/prediction/\* are out of scope; query Cloud Monitoring directly via the gcp-monitoring connector if you need them.
|
|
127
|
+
- Spend rows come from the Cloud Billing -> BigQuery export; the export must be configured manually in the GCP console and only days after the configuration date are present.
|
|
128
|
+
- BigQuery cost rows are back-revised by GCP for several days; an incremental sync refetches a short trailing window to pick up corrections.
|
|
129
|
+
- Each BigQuery query is billed against the bqProject; keep lookbackDays reasonable.
|
|
130
|
+
- Daily aggregation only - sub-day granularity is intentionally not exposed for spend or invocation rollups.
|
|
131
|
+
|
|
132
|
+
## Links
|
|
133
|
+
|
|
134
|
+
- [Rawdash docs](https://rawdash.dev/docs/connectors/)
|
|
135
|
+
- [Google Cloud API docs](https://cloud.google.com/vertex-ai/docs/general/monitoring)
|
|
136
|
+
- [GitHub](https://github.com/rawdash/rawdash)
|
|
137
|
+
|
|
138
|
+
## License
|
|
139
|
+
|
|
140
|
+
Apache-2.0
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,479 @@
|
|
|
1
|
+
import { BqQueryResponse } from '@rawdash/connector-gcp-shared';
|
|
2
|
+
import { BaseConnector, ConnectorCost, ConnectorContext, SyncOptions, StorageHandle, SyncResult, ChunkedSyncCursor, MetricSample, ConnectorDoc, JSONValue } from '@rawdash/core';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
|
|
5
|
+
declare const configFields: z.ZodObject<{
|
|
6
|
+
bqProject: z.ZodOptional<z.ZodString>;
|
|
7
|
+
bqDataset: z.ZodOptional<z.ZodString>;
|
|
8
|
+
bqLocation: z.ZodOptional<z.ZodString>;
|
|
9
|
+
spendServiceFilter: z.ZodOptional<z.ZodString>;
|
|
10
|
+
lookbackDays: z.ZodOptional<z.ZodNumber>;
|
|
11
|
+
serviceAccountJson: z.ZodObject<{
|
|
12
|
+
$secret: z.ZodString;
|
|
13
|
+
}, z.core.$strip>;
|
|
14
|
+
projectId: z.ZodString;
|
|
15
|
+
}, z.core.$strip>;
|
|
16
|
+
declare const doc: ConnectorDoc;
|
|
17
|
+
interface VertexAiSettings {
|
|
18
|
+
projectId: string;
|
|
19
|
+
bqProject?: string;
|
|
20
|
+
bqDataset?: string;
|
|
21
|
+
bqLocation?: string;
|
|
22
|
+
spendServiceFilter?: string;
|
|
23
|
+
lookbackDays?: number;
|
|
24
|
+
}
|
|
25
|
+
declare const vertexAiCredentials: {
|
|
26
|
+
serviceAccountJson: {
|
|
27
|
+
description: string;
|
|
28
|
+
auth: "required";
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
type VertexAiCredentials = typeof vertexAiCredentials;
|
|
32
|
+
declare const pointSchema: z.ZodObject<{
|
|
33
|
+
interval: z.ZodObject<{
|
|
34
|
+
startTime: z.ZodOptional<z.ZodISODateTime>;
|
|
35
|
+
endTime: z.ZodISODateTime;
|
|
36
|
+
}, z.core.$strip>;
|
|
37
|
+
value: z.ZodObject<{
|
|
38
|
+
doubleValue: z.ZodOptional<z.ZodNumber>;
|
|
39
|
+
int64Value: z.ZodOptional<z.ZodString>;
|
|
40
|
+
boolValue: z.ZodOptional<z.ZodBoolean>;
|
|
41
|
+
stringValue: z.ZodOptional<z.ZodString>;
|
|
42
|
+
distributionValue: z.ZodOptional<z.ZodUnknown>;
|
|
43
|
+
}, z.core.$strip>;
|
|
44
|
+
}, z.core.$strip>;
|
|
45
|
+
declare const INVOCATIONS_METRIC_NAME = "vertex_ai_invocations";
|
|
46
|
+
declare const ERRORS_METRIC_NAME = "vertex_ai_errors";
|
|
47
|
+
declare const TOKENS_METRIC_NAME = "vertex_ai_tokens";
|
|
48
|
+
declare const SPEND_METRIC_NAME = "vertex_ai_spend";
|
|
49
|
+
declare const vertexAiResources: {
|
|
50
|
+
readonly vertex_ai_invocations: {
|
|
51
|
+
readonly shape: "metric";
|
|
52
|
+
readonly description: "Daily count of successful Vertex AI model invocations (HTTP 2xx) per (date, modelId). Sourced from the Cloud Monitoring metric `aiplatform.googleapis.com/publisher/online_serving/model_invocation_count`, aggregated to one sample per day with SUM.";
|
|
53
|
+
readonly endpoint: "GET /v3/projects/{projectId}/timeSeries";
|
|
54
|
+
readonly granularity: "daily";
|
|
55
|
+
readonly notes: "On every sync the trailing `lookbackDays` window is rewritten idempotently. Non-2xx response codes flow to `vertex_ai_errors` instead.";
|
|
56
|
+
readonly dimensions: [{
|
|
57
|
+
readonly name: "modelId";
|
|
58
|
+
readonly description: "Vertex AI publisher model identifier, e.g. gemini-1.5-pro or text-bison.";
|
|
59
|
+
}, {
|
|
60
|
+
readonly name: "responseCode";
|
|
61
|
+
readonly description: "Upstream HTTP response code reported by Vertex AI (always 2xx in this resource).";
|
|
62
|
+
}];
|
|
63
|
+
readonly responses: {
|
|
64
|
+
readonly oauth_token: z.ZodObject<{
|
|
65
|
+
access_token: z.ZodString;
|
|
66
|
+
expires_in: z.ZodOptional<z.ZodNumber>;
|
|
67
|
+
}, z.core.$strip>;
|
|
68
|
+
readonly invocations: z.ZodObject<{
|
|
69
|
+
timeSeries: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
70
|
+
metric: z.ZodObject<{
|
|
71
|
+
type: z.ZodString;
|
|
72
|
+
labels: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
73
|
+
}, z.core.$strip>;
|
|
74
|
+
resource: z.ZodOptional<z.ZodObject<{
|
|
75
|
+
type: z.ZodOptional<z.ZodString>;
|
|
76
|
+
labels: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
77
|
+
}, z.core.$strip>>;
|
|
78
|
+
valueType: z.ZodOptional<z.ZodString>;
|
|
79
|
+
metricKind: z.ZodOptional<z.ZodString>;
|
|
80
|
+
points: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
81
|
+
interval: z.ZodObject<{
|
|
82
|
+
startTime: z.ZodOptional<z.ZodISODateTime>;
|
|
83
|
+
endTime: z.ZodISODateTime;
|
|
84
|
+
}, z.core.$strip>;
|
|
85
|
+
value: z.ZodObject<{
|
|
86
|
+
doubleValue: z.ZodOptional<z.ZodNumber>;
|
|
87
|
+
int64Value: z.ZodOptional<z.ZodString>;
|
|
88
|
+
boolValue: z.ZodOptional<z.ZodBoolean>;
|
|
89
|
+
stringValue: z.ZodOptional<z.ZodString>;
|
|
90
|
+
distributionValue: z.ZodOptional<z.ZodUnknown>;
|
|
91
|
+
}, z.core.$strip>;
|
|
92
|
+
}, z.core.$strip>>>;
|
|
93
|
+
}, z.core.$strip>>>;
|
|
94
|
+
nextPageToken: z.ZodOptional<z.ZodString>;
|
|
95
|
+
}, z.core.$strip>;
|
|
96
|
+
};
|
|
97
|
+
};
|
|
98
|
+
readonly vertex_ai_errors: {
|
|
99
|
+
readonly shape: "metric";
|
|
100
|
+
readonly description: "Daily count of failed Vertex AI model invocations (non-2xx) per (date, modelId, errorType). Sourced from the same Cloud Monitoring API call as `vertex_ai_invocations`; rows with response_code outside 200-299 are routed here.";
|
|
101
|
+
readonly endpoint: "GET /v3/projects/{projectId}/timeSeries (shared with vertex_ai_invocations)";
|
|
102
|
+
readonly granularity: "daily";
|
|
103
|
+
readonly notes: "errorType carries the upstream HTTP status (e.g. 400, 429, 500). Use it to slice quota errors (429) from request errors (4xx) and platform errors (5xx). The response schema is registered under `vertex_ai_invocations`.";
|
|
104
|
+
readonly dimensions: [{
|
|
105
|
+
readonly name: "modelId";
|
|
106
|
+
readonly description: "Vertex AI publisher model identifier.";
|
|
107
|
+
}, {
|
|
108
|
+
readonly name: "errorType";
|
|
109
|
+
readonly description: "HTTP status code returned by Vertex AI (400, 401, 403, 429, 5xx, ...).";
|
|
110
|
+
}];
|
|
111
|
+
};
|
|
112
|
+
readonly vertex_ai_tokens: {
|
|
113
|
+
readonly shape: "metric";
|
|
114
|
+
readonly description: "Daily Vertex AI token usage per (date, modelId, tokenType). Sourced from the Cloud Monitoring metric `aiplatform.googleapis.com/publisher/online_serving/token_count`. tokenType is either `input` (prompt) or `output` (completion).";
|
|
115
|
+
readonly endpoint: "GET /v3/projects/{projectId}/timeSeries";
|
|
116
|
+
readonly granularity: "daily";
|
|
117
|
+
readonly notes: "Sum across both tokenType values to get total tokens; slice by tokenType to separate input from output cost drivers.";
|
|
118
|
+
readonly dimensions: [{
|
|
119
|
+
readonly name: "modelId";
|
|
120
|
+
readonly description: "Vertex AI publisher model identifier.";
|
|
121
|
+
}, {
|
|
122
|
+
readonly name: "tokenType";
|
|
123
|
+
readonly description: "Either `input` (prompt tokens) or `output` (response tokens).";
|
|
124
|
+
}];
|
|
125
|
+
readonly responses: {
|
|
126
|
+
readonly tokens: z.ZodObject<{
|
|
127
|
+
timeSeries: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
128
|
+
metric: z.ZodObject<{
|
|
129
|
+
type: z.ZodString;
|
|
130
|
+
labels: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
131
|
+
}, z.core.$strip>;
|
|
132
|
+
resource: z.ZodOptional<z.ZodObject<{
|
|
133
|
+
type: z.ZodOptional<z.ZodString>;
|
|
134
|
+
labels: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
135
|
+
}, z.core.$strip>>;
|
|
136
|
+
valueType: z.ZodOptional<z.ZodString>;
|
|
137
|
+
metricKind: z.ZodOptional<z.ZodString>;
|
|
138
|
+
points: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
139
|
+
interval: z.ZodObject<{
|
|
140
|
+
startTime: z.ZodOptional<z.ZodISODateTime>;
|
|
141
|
+
endTime: z.ZodISODateTime;
|
|
142
|
+
}, z.core.$strip>;
|
|
143
|
+
value: z.ZodObject<{
|
|
144
|
+
doubleValue: z.ZodOptional<z.ZodNumber>;
|
|
145
|
+
int64Value: z.ZodOptional<z.ZodString>;
|
|
146
|
+
boolValue: z.ZodOptional<z.ZodBoolean>;
|
|
147
|
+
stringValue: z.ZodOptional<z.ZodString>;
|
|
148
|
+
distributionValue: z.ZodOptional<z.ZodUnknown>;
|
|
149
|
+
}, z.core.$strip>;
|
|
150
|
+
}, z.core.$strip>>>;
|
|
151
|
+
}, z.core.$strip>>>;
|
|
152
|
+
nextPageToken: z.ZodOptional<z.ZodString>;
|
|
153
|
+
}, z.core.$strip>;
|
|
154
|
+
};
|
|
155
|
+
};
|
|
156
|
+
readonly vertex_ai_spend: {
|
|
157
|
+
readonly shape: "metric";
|
|
158
|
+
readonly description: "Daily Vertex AI spend per (date, sku) sourced from the Cloud Billing -> BigQuery export. Skipped unless bqProject and bqDataset are configured.";
|
|
159
|
+
readonly endpoint: "POST /bigquery/v2/projects/{bqProject}/queries";
|
|
160
|
+
readonly unit: "USD";
|
|
161
|
+
readonly granularity: "daily";
|
|
162
|
+
readonly notes: "The trailing 5 days are always refetched on incremental syncs to pick up GCP back-revisions. SKU describes the specific Vertex AI model and token type (e.g. \"Gemini 1.5 Pro Online Inference - Input\").";
|
|
163
|
+
readonly dimensions: [{
|
|
164
|
+
readonly name: "sku";
|
|
165
|
+
readonly description: "GCP SKU description, e.g. \"Gemini 1.5 Pro Online Inference - Input Tokens\".";
|
|
166
|
+
}, {
|
|
167
|
+
readonly name: "service";
|
|
168
|
+
readonly description: "GCP service description, typically \"Vertex AI\" or \"Vertex AI Generative AI\".";
|
|
169
|
+
}, {
|
|
170
|
+
readonly name: "currency";
|
|
171
|
+
readonly description: "Billing currency reported by GCP.";
|
|
172
|
+
}];
|
|
173
|
+
readonly responses: {
|
|
174
|
+
readonly spend: z.ZodObject<{
|
|
175
|
+
jobComplete: z.ZodOptional<z.ZodBoolean>;
|
|
176
|
+
schema: z.ZodOptional<z.ZodObject<{
|
|
177
|
+
fields: z.ZodArray<z.ZodObject<{
|
|
178
|
+
name: z.ZodString;
|
|
179
|
+
type: z.ZodString;
|
|
180
|
+
}, z.core.$strip>>;
|
|
181
|
+
}, z.core.$strip>>;
|
|
182
|
+
rows: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
183
|
+
f: z.ZodArray<z.ZodObject<{
|
|
184
|
+
v: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
185
|
+
}, z.core.$strip>>;
|
|
186
|
+
}, z.core.$strip>>>;
|
|
187
|
+
pageToken: z.ZodOptional<z.ZodString>;
|
|
188
|
+
jobReference: z.ZodOptional<z.ZodObject<{
|
|
189
|
+
projectId: z.ZodString;
|
|
190
|
+
jobId: z.ZodString;
|
|
191
|
+
location: z.ZodOptional<z.ZodString>;
|
|
192
|
+
}, z.core.$strip>>;
|
|
193
|
+
}, z.core.$strip>;
|
|
194
|
+
};
|
|
195
|
+
};
|
|
196
|
+
};
|
|
197
|
+
declare const PHASE_ORDER: readonly ["invocations", "tokens", "spend"];
|
|
198
|
+
type VertexAiPhase = (typeof PHASE_ORDER)[number];
|
|
199
|
+
type VertexAiCursor = ChunkedSyncCursor<VertexAiPhase, string>;
|
|
200
|
+
declare const id = "vertex-ai";
|
|
201
|
+
declare const cost: ConnectorCost;
|
|
202
|
+
declare class VertexAiConnector extends BaseConnector<VertexAiSettings, VertexAiCredentials> {
|
|
203
|
+
static readonly id = "vertex-ai";
|
|
204
|
+
static readonly resources: {
|
|
205
|
+
readonly vertex_ai_invocations: {
|
|
206
|
+
readonly shape: "metric";
|
|
207
|
+
readonly description: "Daily count of successful Vertex AI model invocations (HTTP 2xx) per (date, modelId). Sourced from the Cloud Monitoring metric `aiplatform.googleapis.com/publisher/online_serving/model_invocation_count`, aggregated to one sample per day with SUM.";
|
|
208
|
+
readonly endpoint: "GET /v3/projects/{projectId}/timeSeries";
|
|
209
|
+
readonly granularity: "daily";
|
|
210
|
+
readonly notes: "On every sync the trailing `lookbackDays` window is rewritten idempotently. Non-2xx response codes flow to `vertex_ai_errors` instead.";
|
|
211
|
+
readonly dimensions: [{
|
|
212
|
+
readonly name: "modelId";
|
|
213
|
+
readonly description: "Vertex AI publisher model identifier, e.g. gemini-1.5-pro or text-bison.";
|
|
214
|
+
}, {
|
|
215
|
+
readonly name: "responseCode";
|
|
216
|
+
readonly description: "Upstream HTTP response code reported by Vertex AI (always 2xx in this resource).";
|
|
217
|
+
}];
|
|
218
|
+
readonly responses: {
|
|
219
|
+
readonly oauth_token: z.ZodObject<{
|
|
220
|
+
access_token: z.ZodString;
|
|
221
|
+
expires_in: z.ZodOptional<z.ZodNumber>;
|
|
222
|
+
}, z.core.$strip>;
|
|
223
|
+
readonly invocations: z.ZodObject<{
|
|
224
|
+
timeSeries: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
225
|
+
metric: z.ZodObject<{
|
|
226
|
+
type: z.ZodString;
|
|
227
|
+
labels: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
228
|
+
}, z.core.$strip>;
|
|
229
|
+
resource: z.ZodOptional<z.ZodObject<{
|
|
230
|
+
type: z.ZodOptional<z.ZodString>;
|
|
231
|
+
labels: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
232
|
+
}, z.core.$strip>>;
|
|
233
|
+
valueType: z.ZodOptional<z.ZodString>;
|
|
234
|
+
metricKind: z.ZodOptional<z.ZodString>;
|
|
235
|
+
points: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
236
|
+
interval: z.ZodObject<{
|
|
237
|
+
startTime: z.ZodOptional<z.ZodISODateTime>;
|
|
238
|
+
endTime: z.ZodISODateTime;
|
|
239
|
+
}, z.core.$strip>;
|
|
240
|
+
value: z.ZodObject<{
|
|
241
|
+
doubleValue: z.ZodOptional<z.ZodNumber>;
|
|
242
|
+
int64Value: z.ZodOptional<z.ZodString>;
|
|
243
|
+
boolValue: z.ZodOptional<z.ZodBoolean>;
|
|
244
|
+
stringValue: z.ZodOptional<z.ZodString>;
|
|
245
|
+
distributionValue: z.ZodOptional<z.ZodUnknown>;
|
|
246
|
+
}, z.core.$strip>;
|
|
247
|
+
}, z.core.$strip>>>;
|
|
248
|
+
}, z.core.$strip>>>;
|
|
249
|
+
nextPageToken: z.ZodOptional<z.ZodString>;
|
|
250
|
+
}, z.core.$strip>;
|
|
251
|
+
};
|
|
252
|
+
};
|
|
253
|
+
readonly vertex_ai_errors: {
|
|
254
|
+
readonly shape: "metric";
|
|
255
|
+
readonly description: "Daily count of failed Vertex AI model invocations (non-2xx) per (date, modelId, errorType). Sourced from the same Cloud Monitoring API call as `vertex_ai_invocations`; rows with response_code outside 200-299 are routed here.";
|
|
256
|
+
readonly endpoint: "GET /v3/projects/{projectId}/timeSeries (shared with vertex_ai_invocations)";
|
|
257
|
+
readonly granularity: "daily";
|
|
258
|
+
readonly notes: "errorType carries the upstream HTTP status (e.g. 400, 429, 500). Use it to slice quota errors (429) from request errors (4xx) and platform errors (5xx). The response schema is registered under `vertex_ai_invocations`.";
|
|
259
|
+
readonly dimensions: [{
|
|
260
|
+
readonly name: "modelId";
|
|
261
|
+
readonly description: "Vertex AI publisher model identifier.";
|
|
262
|
+
}, {
|
|
263
|
+
readonly name: "errorType";
|
|
264
|
+
readonly description: "HTTP status code returned by Vertex AI (400, 401, 403, 429, 5xx, ...).";
|
|
265
|
+
}];
|
|
266
|
+
};
|
|
267
|
+
readonly vertex_ai_tokens: {
|
|
268
|
+
readonly shape: "metric";
|
|
269
|
+
readonly description: "Daily Vertex AI token usage per (date, modelId, tokenType). Sourced from the Cloud Monitoring metric `aiplatform.googleapis.com/publisher/online_serving/token_count`. tokenType is either `input` (prompt) or `output` (completion).";
|
|
270
|
+
readonly endpoint: "GET /v3/projects/{projectId}/timeSeries";
|
|
271
|
+
readonly granularity: "daily";
|
|
272
|
+
readonly notes: "Sum across both tokenType values to get total tokens; slice by tokenType to separate input from output cost drivers.";
|
|
273
|
+
readonly dimensions: [{
|
|
274
|
+
readonly name: "modelId";
|
|
275
|
+
readonly description: "Vertex AI publisher model identifier.";
|
|
276
|
+
}, {
|
|
277
|
+
readonly name: "tokenType";
|
|
278
|
+
readonly description: "Either `input` (prompt tokens) or `output` (response tokens).";
|
|
279
|
+
}];
|
|
280
|
+
readonly responses: {
|
|
281
|
+
readonly tokens: z.ZodObject<{
|
|
282
|
+
timeSeries: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
283
|
+
metric: z.ZodObject<{
|
|
284
|
+
type: z.ZodString;
|
|
285
|
+
labels: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
286
|
+
}, z.core.$strip>;
|
|
287
|
+
resource: z.ZodOptional<z.ZodObject<{
|
|
288
|
+
type: z.ZodOptional<z.ZodString>;
|
|
289
|
+
labels: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
290
|
+
}, z.core.$strip>>;
|
|
291
|
+
valueType: z.ZodOptional<z.ZodString>;
|
|
292
|
+
metricKind: z.ZodOptional<z.ZodString>;
|
|
293
|
+
points: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
294
|
+
interval: z.ZodObject<{
|
|
295
|
+
startTime: z.ZodOptional<z.ZodISODateTime>;
|
|
296
|
+
endTime: z.ZodISODateTime;
|
|
297
|
+
}, z.core.$strip>;
|
|
298
|
+
value: z.ZodObject<{
|
|
299
|
+
doubleValue: z.ZodOptional<z.ZodNumber>;
|
|
300
|
+
int64Value: z.ZodOptional<z.ZodString>;
|
|
301
|
+
boolValue: z.ZodOptional<z.ZodBoolean>;
|
|
302
|
+
stringValue: z.ZodOptional<z.ZodString>;
|
|
303
|
+
distributionValue: z.ZodOptional<z.ZodUnknown>;
|
|
304
|
+
}, z.core.$strip>;
|
|
305
|
+
}, z.core.$strip>>>;
|
|
306
|
+
}, z.core.$strip>>>;
|
|
307
|
+
nextPageToken: z.ZodOptional<z.ZodString>;
|
|
308
|
+
}, z.core.$strip>;
|
|
309
|
+
};
|
|
310
|
+
};
|
|
311
|
+
readonly vertex_ai_spend: {
|
|
312
|
+
readonly shape: "metric";
|
|
313
|
+
readonly description: "Daily Vertex AI spend per (date, sku) sourced from the Cloud Billing -> BigQuery export. Skipped unless bqProject and bqDataset are configured.";
|
|
314
|
+
readonly endpoint: "POST /bigquery/v2/projects/{bqProject}/queries";
|
|
315
|
+
readonly unit: "USD";
|
|
316
|
+
readonly granularity: "daily";
|
|
317
|
+
readonly notes: "The trailing 5 days are always refetched on incremental syncs to pick up GCP back-revisions. SKU describes the specific Vertex AI model and token type (e.g. \"Gemini 1.5 Pro Online Inference - Input\").";
|
|
318
|
+
readonly dimensions: [{
|
|
319
|
+
readonly name: "sku";
|
|
320
|
+
readonly description: "GCP SKU description, e.g. \"Gemini 1.5 Pro Online Inference - Input Tokens\".";
|
|
321
|
+
}, {
|
|
322
|
+
readonly name: "service";
|
|
323
|
+
readonly description: "GCP service description, typically \"Vertex AI\" or \"Vertex AI Generative AI\".";
|
|
324
|
+
}, {
|
|
325
|
+
readonly name: "currency";
|
|
326
|
+
readonly description: "Billing currency reported by GCP.";
|
|
327
|
+
}];
|
|
328
|
+
readonly responses: {
|
|
329
|
+
readonly spend: z.ZodObject<{
|
|
330
|
+
jobComplete: z.ZodOptional<z.ZodBoolean>;
|
|
331
|
+
schema: z.ZodOptional<z.ZodObject<{
|
|
332
|
+
fields: z.ZodArray<z.ZodObject<{
|
|
333
|
+
name: z.ZodString;
|
|
334
|
+
type: z.ZodString;
|
|
335
|
+
}, z.core.$strip>>;
|
|
336
|
+
}, z.core.$strip>>;
|
|
337
|
+
rows: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
338
|
+
f: z.ZodArray<z.ZodObject<{
|
|
339
|
+
v: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
340
|
+
}, z.core.$strip>>;
|
|
341
|
+
}, z.core.$strip>>>;
|
|
342
|
+
pageToken: z.ZodOptional<z.ZodString>;
|
|
343
|
+
jobReference: z.ZodOptional<z.ZodObject<{
|
|
344
|
+
projectId: z.ZodString;
|
|
345
|
+
jobId: z.ZodString;
|
|
346
|
+
location: z.ZodOptional<z.ZodString>;
|
|
347
|
+
}, z.core.$strip>>;
|
|
348
|
+
}, z.core.$strip>;
|
|
349
|
+
};
|
|
350
|
+
};
|
|
351
|
+
};
|
|
352
|
+
static readonly schemas: object & {
|
|
353
|
+
readonly oauth_token: z.ZodObject<{
|
|
354
|
+
access_token: z.ZodString;
|
|
355
|
+
expires_in: z.ZodOptional<z.ZodNumber>;
|
|
356
|
+
}, z.core.$strip>;
|
|
357
|
+
readonly invocations: z.ZodObject<{
|
|
358
|
+
timeSeries: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
359
|
+
metric: z.ZodObject<{
|
|
360
|
+
type: z.ZodString;
|
|
361
|
+
labels: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
362
|
+
}, z.core.$strip>;
|
|
363
|
+
resource: z.ZodOptional<z.ZodObject<{
|
|
364
|
+
type: z.ZodOptional<z.ZodString>;
|
|
365
|
+
labels: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
366
|
+
}, z.core.$strip>>;
|
|
367
|
+
valueType: z.ZodOptional<z.ZodString>;
|
|
368
|
+
metricKind: z.ZodOptional<z.ZodString>;
|
|
369
|
+
points: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
370
|
+
interval: z.ZodObject<{
|
|
371
|
+
startTime: z.ZodOptional<z.ZodISODateTime>;
|
|
372
|
+
endTime: z.ZodISODateTime;
|
|
373
|
+
}, z.core.$strip>;
|
|
374
|
+
value: z.ZodObject<{
|
|
375
|
+
doubleValue: z.ZodOptional<z.ZodNumber>;
|
|
376
|
+
int64Value: z.ZodOptional<z.ZodString>;
|
|
377
|
+
boolValue: z.ZodOptional<z.ZodBoolean>;
|
|
378
|
+
stringValue: z.ZodOptional<z.ZodString>;
|
|
379
|
+
distributionValue: z.ZodOptional<z.ZodUnknown>;
|
|
380
|
+
}, z.core.$strip>;
|
|
381
|
+
}, z.core.$strip>>>;
|
|
382
|
+
}, z.core.$strip>>>;
|
|
383
|
+
nextPageToken: z.ZodOptional<z.ZodString>;
|
|
384
|
+
}, z.core.$strip>;
|
|
385
|
+
} & {
|
|
386
|
+
readonly tokens: z.ZodObject<{
|
|
387
|
+
timeSeries: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
388
|
+
metric: z.ZodObject<{
|
|
389
|
+
type: z.ZodString;
|
|
390
|
+
labels: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
391
|
+
}, z.core.$strip>;
|
|
392
|
+
resource: z.ZodOptional<z.ZodObject<{
|
|
393
|
+
type: z.ZodOptional<z.ZodString>;
|
|
394
|
+
labels: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
395
|
+
}, z.core.$strip>>;
|
|
396
|
+
valueType: z.ZodOptional<z.ZodString>;
|
|
397
|
+
metricKind: z.ZodOptional<z.ZodString>;
|
|
398
|
+
points: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
399
|
+
interval: z.ZodObject<{
|
|
400
|
+
startTime: z.ZodOptional<z.ZodISODateTime>;
|
|
401
|
+
endTime: z.ZodISODateTime;
|
|
402
|
+
}, z.core.$strip>;
|
|
403
|
+
value: z.ZodObject<{
|
|
404
|
+
doubleValue: z.ZodOptional<z.ZodNumber>;
|
|
405
|
+
int64Value: z.ZodOptional<z.ZodString>;
|
|
406
|
+
boolValue: z.ZodOptional<z.ZodBoolean>;
|
|
407
|
+
stringValue: z.ZodOptional<z.ZodString>;
|
|
408
|
+
distributionValue: z.ZodOptional<z.ZodUnknown>;
|
|
409
|
+
}, z.core.$strip>;
|
|
410
|
+
}, z.core.$strip>>>;
|
|
411
|
+
}, z.core.$strip>>>;
|
|
412
|
+
nextPageToken: z.ZodOptional<z.ZodString>;
|
|
413
|
+
}, z.core.$strip>;
|
|
414
|
+
} & {
|
|
415
|
+
readonly spend: z.ZodObject<{
|
|
416
|
+
jobComplete: z.ZodOptional<z.ZodBoolean>;
|
|
417
|
+
schema: z.ZodOptional<z.ZodObject<{
|
|
418
|
+
fields: z.ZodArray<z.ZodObject<{
|
|
419
|
+
name: z.ZodString;
|
|
420
|
+
type: z.ZodString;
|
|
421
|
+
}, z.core.$strip>>;
|
|
422
|
+
}, z.core.$strip>>;
|
|
423
|
+
rows: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
424
|
+
f: z.ZodArray<z.ZodObject<{
|
|
425
|
+
v: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
426
|
+
}, z.core.$strip>>;
|
|
427
|
+
}, z.core.$strip>>>;
|
|
428
|
+
pageToken: z.ZodOptional<z.ZodString>;
|
|
429
|
+
jobReference: z.ZodOptional<z.ZodObject<{
|
|
430
|
+
projectId: z.ZodString;
|
|
431
|
+
jobId: z.ZodString;
|
|
432
|
+
location: z.ZodOptional<z.ZodString>;
|
|
433
|
+
}, z.core.$strip>>;
|
|
434
|
+
}, z.core.$strip>;
|
|
435
|
+
} & Readonly<Record<string, z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>>;
|
|
436
|
+
static readonly cost: ConnectorCost;
|
|
437
|
+
static create(input: unknown, ctx?: ConnectorContext): VertexAiConnector;
|
|
438
|
+
readonly id = "vertex-ai";
|
|
439
|
+
readonly credentials: {
|
|
440
|
+
serviceAccountJson: {
|
|
441
|
+
description: string;
|
|
442
|
+
auth: "required";
|
|
443
|
+
};
|
|
444
|
+
};
|
|
445
|
+
private monitoringTokenProvider?;
|
|
446
|
+
private bigQueryTokenProvider?;
|
|
447
|
+
private getMonitoringToken;
|
|
448
|
+
private getBigQueryToken;
|
|
449
|
+
private listTimeSeries;
|
|
450
|
+
private fetchBigQueryPage;
|
|
451
|
+
private syncInvocations;
|
|
452
|
+
private syncTokens;
|
|
453
|
+
private syncSpend;
|
|
454
|
+
sync(options: SyncOptions, storage: StorageHandle, signal?: AbortSignal): Promise<SyncResult>;
|
|
455
|
+
}
|
|
456
|
+
declare function pointToCountSample(modelId: string | null, responseCode: string, point: z.infer<typeof pointSchema>): {
|
|
457
|
+
ts: number;
|
|
458
|
+
value: number;
|
|
459
|
+
attributes: Record<string, JSONValue>;
|
|
460
|
+
} | null;
|
|
461
|
+
declare function pointToTokenSample(modelId: string | null, tokenType: string, point: z.infer<typeof pointSchema>): MetricSample | null;
|
|
462
|
+
declare function getMonitoringWindow(options: SyncOptions, lookbackDays: number, now?: number): {
|
|
463
|
+
startMs: number;
|
|
464
|
+
endMs: number;
|
|
465
|
+
};
|
|
466
|
+
declare function getSpendWindow(options: SyncOptions, lookbackDays: number, now?: number): {
|
|
467
|
+
startDate: string;
|
|
468
|
+
endDate: string;
|
|
469
|
+
};
|
|
470
|
+
declare function buildVertexSpendSql(args: {
|
|
471
|
+
bqProject: string;
|
|
472
|
+
bqDataset: string;
|
|
473
|
+
startDate: string;
|
|
474
|
+
endDate: string;
|
|
475
|
+
serviceFilter: string;
|
|
476
|
+
}): string;
|
|
477
|
+
declare function buildSpendSamplesFromBqResponse(response: BqQueryResponse): MetricSample[];
|
|
478
|
+
|
|
479
|
+
export { ERRORS_METRIC_NAME, INVOCATIONS_METRIC_NAME, SPEND_METRIC_NAME, TOKENS_METRIC_NAME, VertexAiConnector, type VertexAiCursor, type VertexAiPhase, type VertexAiSettings, buildSpendSamplesFromBqResponse, buildVertexSpendSql, configFields, cost, VertexAiConnector as default, doc, getMonitoringWindow, getSpendWindow, id, pointToCountSample, pointToTokenSample, vertexAiResources as resources };
|