@ai-sdk/google-vertex 5.0.0-beta.4 → 5.0.0-beta.41
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/CHANGELOG.md +324 -8
- package/README.md +65 -1
- package/dist/anthropic/edge/index.d.mts +60 -15
- package/dist/anthropic/edge/index.d.ts +60 -15
- package/dist/anthropic/edge/index.js +29 -7
- package/dist/anthropic/edge/index.js.map +1 -1
- package/dist/anthropic/edge/index.mjs +26 -4
- package/dist/anthropic/edge/index.mjs.map +1 -1
- package/dist/anthropic/index.d.mts +60 -15
- package/dist/anthropic/index.d.ts +60 -15
- package/dist/anthropic/index.js +28 -6
- package/dist/anthropic/index.js.map +1 -1
- package/dist/anthropic/index.mjs +25 -3
- package/dist/anthropic/index.mjs.map +1 -1
- package/dist/edge/index.d.mts +19 -19
- package/dist/edge/index.d.ts +19 -19
- package/dist/edge/index.js +8 -8
- package/dist/edge/index.js.map +1 -1
- package/dist/edge/index.mjs +5 -5
- package/dist/edge/index.mjs.map +1 -1
- package/dist/index.d.mts +19 -19
- package/dist/index.d.ts +19 -19
- package/dist/index.js +8 -8
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +5 -5
- package/dist/index.mjs.map +1 -1
- package/dist/maas/edge/index.d.mts +76 -0
- package/dist/maas/edge/index.d.ts +76 -0
- package/dist/maas/edge/index.js +215 -0
- package/dist/maas/edge/index.js.map +1 -0
- package/dist/maas/edge/index.mjs +196 -0
- package/dist/maas/edge/index.mjs.map +1 -0
- package/dist/maas/index.d.mts +60 -0
- package/dist/maas/index.d.ts +60 -0
- package/dist/maas/index.js +125 -0
- package/dist/maas/index.js.map +1 -0
- package/dist/maas/index.mjs +101 -0
- package/dist/maas/index.mjs.map +1 -0
- package/docs/16-google-vertex.mdx +227 -6
- package/maas/edge.d.ts +1 -0
- package/maas/index.d.ts +1 -0
- package/package.json +19 -8
- package/src/anthropic/edge/google-vertex-anthropic-provider-edge.ts +1 -2
- package/src/anthropic/google-vertex-anthropic-provider-node.ts +1 -2
- package/src/anthropic/google-vertex-anthropic-provider.ts +32 -7
- package/src/edge/google-vertex-provider-edge.ts +1 -2
- package/src/google-vertex-embedding-model.ts +5 -5
- package/src/google-vertex-embedding-options.ts +2 -0
- package/src/google-vertex-image-model.ts +17 -17
- package/src/google-vertex-provider-node.ts +1 -2
- package/src/google-vertex-provider.ts +12 -12
- package/src/google-vertex-video-model.ts +7 -7
- package/src/maas/edge/google-vertex-maas-provider-edge.ts +65 -0
- package/src/maas/edge/index.ts +9 -0
- package/src/maas/google-vertex-maas-options.ts +15 -0
- package/src/maas/google-vertex-maas-provider-node.ts +64 -0
- package/src/maas/google-vertex-maas-provider.ts +111 -0
- package/src/maas/index.ts +9 -0
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/maas/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
createVertexMaas: () => createVertexMaas2,
|
|
24
|
+
vertexMaas: () => vertexMaas
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(index_exports);
|
|
27
|
+
|
|
28
|
+
// src/maas/google-vertex-maas-provider-node.ts
|
|
29
|
+
var import_provider_utils2 = require("@ai-sdk/provider-utils");
|
|
30
|
+
|
|
31
|
+
// src/google-vertex-auth-google-auth-library.ts
|
|
32
|
+
var import_google_auth_library = require("google-auth-library");
|
|
33
|
+
var authInstance = null;
|
|
34
|
+
var authOptions = null;
|
|
35
|
+
function getAuth(options) {
|
|
36
|
+
if (!authInstance || options !== authOptions) {
|
|
37
|
+
authInstance = new import_google_auth_library.GoogleAuth({
|
|
38
|
+
scopes: ["https://www.googleapis.com/auth/cloud-platform"],
|
|
39
|
+
...options
|
|
40
|
+
});
|
|
41
|
+
authOptions = options;
|
|
42
|
+
}
|
|
43
|
+
return authInstance;
|
|
44
|
+
}
|
|
45
|
+
async function generateAuthToken(options) {
|
|
46
|
+
const auth = getAuth(options || {});
|
|
47
|
+
const client = await auth.getClient();
|
|
48
|
+
const token = await client.getAccessToken();
|
|
49
|
+
return (token == null ? void 0 : token.token) || null;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// src/maas/google-vertex-maas-provider.ts
|
|
53
|
+
var import_openai_compatible = require("@ai-sdk/openai-compatible");
|
|
54
|
+
var import_provider_utils = require("@ai-sdk/provider-utils");
|
|
55
|
+
function createVertexMaas(options = {}) {
|
|
56
|
+
const loadLocation = () => (0, import_provider_utils.loadOptionalSetting)({
|
|
57
|
+
settingValue: options.location,
|
|
58
|
+
environmentVariableName: "GOOGLE_VERTEX_LOCATION"
|
|
59
|
+
});
|
|
60
|
+
const loadProject = () => (0, import_provider_utils.loadSetting)({
|
|
61
|
+
settingValue: options.project,
|
|
62
|
+
settingName: "project",
|
|
63
|
+
environmentVariableName: "GOOGLE_VERTEX_PROJECT",
|
|
64
|
+
description: "Google Vertex project"
|
|
65
|
+
});
|
|
66
|
+
const constructBaseURL = () => {
|
|
67
|
+
var _a;
|
|
68
|
+
const projectId = loadProject();
|
|
69
|
+
const location = (_a = loadLocation()) != null ? _a : "global";
|
|
70
|
+
return `https://aiplatform.googleapis.com/v1/projects/${projectId}/locations/${location}/endpoints/openapi`;
|
|
71
|
+
};
|
|
72
|
+
const loadBaseURL = () => {
|
|
73
|
+
var _a;
|
|
74
|
+
return (0, import_provider_utils.withoutTrailingSlash)((_a = options.baseURL) != null ? _a : "") || constructBaseURL();
|
|
75
|
+
};
|
|
76
|
+
let cachedProvider;
|
|
77
|
+
const getProvider = () => cachedProvider != null ? cachedProvider : cachedProvider = (0, import_openai_compatible.createOpenAICompatible)({
|
|
78
|
+
name: "vertex.maas",
|
|
79
|
+
baseURL: loadBaseURL(),
|
|
80
|
+
fetch: options.fetch
|
|
81
|
+
});
|
|
82
|
+
const provider = (modelId) => getProvider()(modelId);
|
|
83
|
+
provider.specificationVersion = "v4";
|
|
84
|
+
provider.languageModel = (modelId) => getProvider().languageModel(modelId);
|
|
85
|
+
provider.chatModel = (modelId) => getProvider().chatModel(modelId);
|
|
86
|
+
provider.completionModel = (modelId) => getProvider().completionModel(modelId);
|
|
87
|
+
provider.embeddingModel = (modelId) => getProvider().embeddingModel(modelId);
|
|
88
|
+
provider.textEmbeddingModel = (modelId) => getProvider().textEmbeddingModel(modelId);
|
|
89
|
+
provider.imageModel = (modelId) => getProvider().imageModel(modelId);
|
|
90
|
+
return provider;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// src/maas/google-vertex-maas-provider-node.ts
|
|
94
|
+
function createVertexMaas2(options = {}) {
|
|
95
|
+
const customFetch = async (url, init) => {
|
|
96
|
+
var _a;
|
|
97
|
+
const token = await generateAuthToken(options.googleAuthOptions);
|
|
98
|
+
const resolvedHeaders = await (0, import_provider_utils2.resolve)(options.headers);
|
|
99
|
+
const authHeaders = {
|
|
100
|
+
...resolvedHeaders,
|
|
101
|
+
Authorization: `Bearer ${token}`
|
|
102
|
+
};
|
|
103
|
+
const fetchInit = {
|
|
104
|
+
...init,
|
|
105
|
+
headers: {
|
|
106
|
+
...init == null ? void 0 : init.headers,
|
|
107
|
+
...authHeaders
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
return ((_a = options.fetch) != null ? _a : fetch)(url, fetchInit);
|
|
111
|
+
};
|
|
112
|
+
return createVertexMaas({
|
|
113
|
+
...options,
|
|
114
|
+
fetch: customFetch,
|
|
115
|
+
headers: void 0
|
|
116
|
+
// Don't pass headers, we handle them in fetch
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
var vertexMaas = createVertexMaas2();
|
|
120
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
121
|
+
0 && (module.exports = {
|
|
122
|
+
createVertexMaas,
|
|
123
|
+
vertexMaas
|
|
124
|
+
});
|
|
125
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/maas/index.ts","../../src/maas/google-vertex-maas-provider-node.ts","../../src/google-vertex-auth-google-auth-library.ts","../../src/maas/google-vertex-maas-provider.ts"],"sourcesContent":["export {\n createVertexMaas,\n vertexMaas,\n} from './google-vertex-maas-provider-node';\nexport type {\n GoogleVertexMaasProvider,\n GoogleVertexMaasProviderSettings,\n} from './google-vertex-maas-provider-node';\nexport type { GoogleVertexMaasModelId } from './google-vertex-maas-options';\n","import { FetchFunction, resolve } from '@ai-sdk/provider-utils';\nimport { GoogleAuthOptions } from 'google-auth-library';\nimport { generateAuthToken } from '../google-vertex-auth-google-auth-library';\nimport {\n createVertexMaas as createVertexMaasOriginal,\n GoogleVertexMaasProvider,\n GoogleVertexMaasProviderSettings as GoogleVertexMaasProviderSettingsOriginal,\n} from './google-vertex-maas-provider';\n\nexport type { GoogleVertexMaasProvider };\n\nexport interface GoogleVertexMaasProviderSettings extends GoogleVertexMaasProviderSettingsOriginal {\n /**\n * Optional. The Authentication options provided by google-auth-library.\n * Complete list of authentication options is documented in the\n * GoogleAuthOptions interface:\n * https://github.com/googleapis/google-auth-library-nodejs/blob/main/src/auth/googleauth.ts.\n */\n googleAuthOptions?: GoogleAuthOptions;\n}\n\n/**\n * Create a Google Vertex AI MaaS (Model as a Service) provider instance for Node.js.\n * Uses the OpenAI-compatible Chat Completions API for partner and open models.\n * Automatically handles Google Cloud authentication.\n *\n * @see https://cloud.google.com/vertex-ai/generative-ai/docs/maas/use-open-models\n */\nexport function createVertexMaas(\n options: GoogleVertexMaasProviderSettings = {},\n): GoogleVertexMaasProvider {\n // Create a custom fetch wrapper that adds auth headers\n const customFetch: FetchFunction = async (url, init) => {\n const token = await generateAuthToken(options.googleAuthOptions);\n const resolvedHeaders = await resolve(options.headers);\n const authHeaders = {\n ...resolvedHeaders,\n Authorization: `Bearer ${token}`,\n };\n\n // Merge auth headers with existing headers from init\n const fetchInit = {\n ...init,\n headers: {\n ...init?.headers,\n ...authHeaders,\n },\n };\n\n // Call the original fetch or user's custom fetch\n return (options.fetch ?? fetch)(url, fetchInit);\n };\n\n return createVertexMaasOriginal({\n ...options,\n fetch: customFetch,\n headers: undefined, // Don't pass headers, we handle them in fetch\n });\n}\n\n/**\n * Default Google Vertex AI MaaS provider instance for Node.js.\n */\nexport const vertexMaas = createVertexMaas();\n","import { GoogleAuth, GoogleAuthOptions } from 'google-auth-library';\n\nlet authInstance: GoogleAuth | null = null;\nlet authOptions: GoogleAuthOptions | null = null;\n\nfunction getAuth(options: GoogleAuthOptions) {\n if (!authInstance || options !== authOptions) {\n authInstance = new GoogleAuth({\n scopes: ['https://www.googleapis.com/auth/cloud-platform'],\n ...options,\n });\n authOptions = options;\n }\n return authInstance;\n}\n\nexport async function generateAuthToken(options?: GoogleAuthOptions) {\n const auth = getAuth(options || {});\n const client = await auth.getClient();\n const token = await client.getAccessToken();\n return token?.token || null;\n}\n\n// For testing purposes only\nexport function _resetAuthInstance() {\n authInstance = null;\n}\n","import { createOpenAICompatible } from '@ai-sdk/openai-compatible';\nimport type { OpenAICompatibleProvider } from '@ai-sdk/openai-compatible';\nimport {\n FetchFunction,\n loadOptionalSetting,\n loadSetting,\n Resolvable,\n withoutTrailingSlash,\n} from '@ai-sdk/provider-utils';\nimport type { GoogleVertexMaasModelId } from './google-vertex-maas-options';\n\nexport interface GoogleVertexMaasProvider extends OpenAICompatibleProvider<\n GoogleVertexMaasModelId,\n string,\n string,\n string\n> {}\n\nexport interface GoogleVertexMaasProviderSettings {\n /**\n * Google Cloud project ID. Defaults to the value of the `GOOGLE_VERTEX_PROJECT` environment variable.\n */\n project?: string;\n\n /**\n * Google Cloud location/region. Defaults to the value of the `GOOGLE_VERTEX_LOCATION` environment variable.\n * Use 'global' for the global endpoint.\n */\n location?: string;\n\n /**\n * Base URL for the API calls. If not provided, will be constructed from project and location.\n */\n baseURL?: string;\n\n /**\n * Headers to use for requests. Can be:\n * - A headers object\n * - A Promise that resolves to a headers object\n * - A function that returns a headers object\n * - A function that returns a Promise of a headers object\n */\n headers?: Resolvable<Record<string, string | undefined>>;\n\n /**\n * Custom fetch implementation. You can use it as a middleware to intercept requests,\n * or to provide a custom fetch implementation for e.g. testing.\n */\n fetch?: FetchFunction;\n}\n\n/**\n * Create a Google Vertex AI MaaS (Model as a Service) provider instance.\n * Uses the OpenAI-compatible Chat Completions API for partner and open models.\n *\n * @see https://cloud.google.com/vertex-ai/generative-ai/docs/maas/use-open-models\n */\nexport function createVertexMaas(\n options: GoogleVertexMaasProviderSettings = {},\n): GoogleVertexMaasProvider {\n // Lazy-load settings to support loading from environment variables at runtime\n const loadLocation = () =>\n loadOptionalSetting({\n settingValue: options.location,\n environmentVariableName: 'GOOGLE_VERTEX_LOCATION',\n });\n\n const loadProject = () =>\n loadSetting({\n settingValue: options.project,\n settingName: 'project',\n environmentVariableName: 'GOOGLE_VERTEX_PROJECT',\n description: 'Google Vertex project',\n });\n\n // Construct base URL: https://aiplatform.googleapis.com/v1/projects/{project}/locations/{location}/endpoints/openapi\n const constructBaseURL = () => {\n const projectId = loadProject();\n const location = loadLocation() ?? 'global';\n\n return `https://aiplatform.googleapis.com/v1/projects/${projectId}/locations/${location}/endpoints/openapi`;\n };\n\n const loadBaseURL = () =>\n withoutTrailingSlash(options.baseURL ?? '') || constructBaseURL();\n\n let cachedProvider: GoogleVertexMaasProvider | undefined;\n const getProvider = () =>\n (cachedProvider ??= createOpenAICompatible({\n name: 'vertex.maas',\n baseURL: loadBaseURL(),\n fetch: options.fetch,\n }));\n\n const provider = (modelId: GoogleVertexMaasModelId) => getProvider()(modelId);\n\n provider.specificationVersion = 'v4' as const;\n provider.languageModel = (modelId: GoogleVertexMaasModelId) =>\n getProvider().languageModel(modelId);\n provider.chatModel = (modelId: GoogleVertexMaasModelId) =>\n getProvider().chatModel(modelId);\n provider.completionModel = (modelId: string) =>\n getProvider().completionModel(modelId);\n provider.embeddingModel = (modelId: string) =>\n getProvider().embeddingModel(modelId);\n provider.textEmbeddingModel = (modelId: string) =>\n getProvider().textEmbeddingModel(modelId);\n provider.imageModel = (modelId: string) => getProvider().imageModel(modelId);\n\n return provider as GoogleVertexMaasProvider;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA,0BAAAA;AAAA,EAAA;AAAA;AAAA;;;ACAA,IAAAC,yBAAuC;;;ACAvC,iCAA8C;AAE9C,IAAI,eAAkC;AACtC,IAAI,cAAwC;AAE5C,SAAS,QAAQ,SAA4B;AAC3C,MAAI,CAAC,gBAAgB,YAAY,aAAa;AAC5C,mBAAe,IAAI,sCAAW;AAAA,MAC5B,QAAQ,CAAC,gDAAgD;AAAA,MACzD,GAAG;AAAA,IACL,CAAC;AACD,kBAAc;AAAA,EAChB;AACA,SAAO;AACT;AAEA,eAAsB,kBAAkB,SAA6B;AACnE,QAAM,OAAO,QAAQ,WAAW,CAAC,CAAC;AAClC,QAAM,SAAS,MAAM,KAAK,UAAU;AACpC,QAAM,QAAQ,MAAM,OAAO,eAAe;AAC1C,UAAO,+BAAO,UAAS;AACzB;;;ACrBA,+BAAuC;AAEvC,4BAMO;AAiDA,SAAS,iBACd,UAA4C,CAAC,GACnB;AAE1B,QAAM,eAAe,UACnB,2CAAoB;AAAA,IAClB,cAAc,QAAQ;AAAA,IACtB,yBAAyB;AAAA,EAC3B,CAAC;AAEH,QAAM,cAAc,UAClB,mCAAY;AAAA,IACV,cAAc,QAAQ;AAAA,IACtB,aAAa;AAAA,IACb,yBAAyB;AAAA,IACzB,aAAa;AAAA,EACf,CAAC;AAGH,QAAM,mBAAmB,MAAM;AA5EjC;AA6EI,UAAM,YAAY,YAAY;AAC9B,UAAM,YAAW,kBAAa,MAAb,YAAkB;AAEnC,WAAO,iDAAiD,SAAS,cAAc,QAAQ;AAAA,EACzF;AAEA,QAAM,cAAc,MAAG;AAnFzB;AAoFI,4DAAqB,aAAQ,YAAR,YAAmB,EAAE,KAAK,iBAAiB;AAAA;AAElE,MAAI;AACJ,QAAM,cAAc,MACjB,+DAAmB,iDAAuB;AAAA,IACzC,MAAM;AAAA,IACN,SAAS,YAAY;AAAA,IACrB,OAAO,QAAQ;AAAA,EACjB,CAAC;AAEH,QAAM,WAAW,CAAC,YAAqC,YAAY,EAAE,OAAO;AAE5E,WAAS,uBAAuB;AAChC,WAAS,gBAAgB,CAAC,YACxB,YAAY,EAAE,cAAc,OAAO;AACrC,WAAS,YAAY,CAAC,YACpB,YAAY,EAAE,UAAU,OAAO;AACjC,WAAS,kBAAkB,CAAC,YAC1B,YAAY,EAAE,gBAAgB,OAAO;AACvC,WAAS,iBAAiB,CAAC,YACzB,YAAY,EAAE,eAAe,OAAO;AACtC,WAAS,qBAAqB,CAAC,YAC7B,YAAY,EAAE,mBAAmB,OAAO;AAC1C,WAAS,aAAa,CAAC,YAAoB,YAAY,EAAE,WAAW,OAAO;AAE3E,SAAO;AACT;;;AFlFO,SAASC,kBACd,UAA4C,CAAC,GACnB;AAE1B,QAAM,cAA6B,OAAO,KAAK,SAAS;AAhC1D;AAiCI,UAAM,QAAQ,MAAM,kBAAkB,QAAQ,iBAAiB;AAC/D,UAAM,kBAAkB,UAAM,gCAAQ,QAAQ,OAAO;AACrD,UAAM,cAAc;AAAA,MAClB,GAAG;AAAA,MACH,eAAe,UAAU,KAAK;AAAA,IAChC;AAGA,UAAM,YAAY;AAAA,MAChB,GAAG;AAAA,MACH,SAAS;AAAA,QACP,GAAG,6BAAM;AAAA,QACT,GAAG;AAAA,MACL;AAAA,IACF;AAGA,aAAQ,aAAQ,UAAR,YAAiB,OAAO,KAAK,SAAS;AAAA,EAChD;AAEA,SAAO,iBAAyB;AAAA,IAC9B,GAAG;AAAA,IACH,OAAO;AAAA,IACP,SAAS;AAAA;AAAA,EACX,CAAC;AACH;AAKO,IAAM,aAAaA,kBAAiB;","names":["createVertexMaas","import_provider_utils","createVertexMaas"]}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
// src/maas/google-vertex-maas-provider-node.ts
|
|
2
|
+
import { resolve } from "@ai-sdk/provider-utils";
|
|
3
|
+
|
|
4
|
+
// src/google-vertex-auth-google-auth-library.ts
|
|
5
|
+
import { GoogleAuth } from "google-auth-library";
|
|
6
|
+
var authInstance = null;
|
|
7
|
+
var authOptions = null;
|
|
8
|
+
function getAuth(options) {
|
|
9
|
+
if (!authInstance || options !== authOptions) {
|
|
10
|
+
authInstance = new GoogleAuth({
|
|
11
|
+
scopes: ["https://www.googleapis.com/auth/cloud-platform"],
|
|
12
|
+
...options
|
|
13
|
+
});
|
|
14
|
+
authOptions = options;
|
|
15
|
+
}
|
|
16
|
+
return authInstance;
|
|
17
|
+
}
|
|
18
|
+
async function generateAuthToken(options) {
|
|
19
|
+
const auth = getAuth(options || {});
|
|
20
|
+
const client = await auth.getClient();
|
|
21
|
+
const token = await client.getAccessToken();
|
|
22
|
+
return (token == null ? void 0 : token.token) || null;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// src/maas/google-vertex-maas-provider.ts
|
|
26
|
+
import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
|
|
27
|
+
import {
|
|
28
|
+
loadOptionalSetting,
|
|
29
|
+
loadSetting,
|
|
30
|
+
withoutTrailingSlash
|
|
31
|
+
} from "@ai-sdk/provider-utils";
|
|
32
|
+
function createVertexMaas(options = {}) {
|
|
33
|
+
const loadLocation = () => loadOptionalSetting({
|
|
34
|
+
settingValue: options.location,
|
|
35
|
+
environmentVariableName: "GOOGLE_VERTEX_LOCATION"
|
|
36
|
+
});
|
|
37
|
+
const loadProject = () => loadSetting({
|
|
38
|
+
settingValue: options.project,
|
|
39
|
+
settingName: "project",
|
|
40
|
+
environmentVariableName: "GOOGLE_VERTEX_PROJECT",
|
|
41
|
+
description: "Google Vertex project"
|
|
42
|
+
});
|
|
43
|
+
const constructBaseURL = () => {
|
|
44
|
+
var _a;
|
|
45
|
+
const projectId = loadProject();
|
|
46
|
+
const location = (_a = loadLocation()) != null ? _a : "global";
|
|
47
|
+
return `https://aiplatform.googleapis.com/v1/projects/${projectId}/locations/${location}/endpoints/openapi`;
|
|
48
|
+
};
|
|
49
|
+
const loadBaseURL = () => {
|
|
50
|
+
var _a;
|
|
51
|
+
return withoutTrailingSlash((_a = options.baseURL) != null ? _a : "") || constructBaseURL();
|
|
52
|
+
};
|
|
53
|
+
let cachedProvider;
|
|
54
|
+
const getProvider = () => cachedProvider != null ? cachedProvider : cachedProvider = createOpenAICompatible({
|
|
55
|
+
name: "vertex.maas",
|
|
56
|
+
baseURL: loadBaseURL(),
|
|
57
|
+
fetch: options.fetch
|
|
58
|
+
});
|
|
59
|
+
const provider = (modelId) => getProvider()(modelId);
|
|
60
|
+
provider.specificationVersion = "v4";
|
|
61
|
+
provider.languageModel = (modelId) => getProvider().languageModel(modelId);
|
|
62
|
+
provider.chatModel = (modelId) => getProvider().chatModel(modelId);
|
|
63
|
+
provider.completionModel = (modelId) => getProvider().completionModel(modelId);
|
|
64
|
+
provider.embeddingModel = (modelId) => getProvider().embeddingModel(modelId);
|
|
65
|
+
provider.textEmbeddingModel = (modelId) => getProvider().textEmbeddingModel(modelId);
|
|
66
|
+
provider.imageModel = (modelId) => getProvider().imageModel(modelId);
|
|
67
|
+
return provider;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// src/maas/google-vertex-maas-provider-node.ts
|
|
71
|
+
function createVertexMaas2(options = {}) {
|
|
72
|
+
const customFetch = async (url, init) => {
|
|
73
|
+
var _a;
|
|
74
|
+
const token = await generateAuthToken(options.googleAuthOptions);
|
|
75
|
+
const resolvedHeaders = await resolve(options.headers);
|
|
76
|
+
const authHeaders = {
|
|
77
|
+
...resolvedHeaders,
|
|
78
|
+
Authorization: `Bearer ${token}`
|
|
79
|
+
};
|
|
80
|
+
const fetchInit = {
|
|
81
|
+
...init,
|
|
82
|
+
headers: {
|
|
83
|
+
...init == null ? void 0 : init.headers,
|
|
84
|
+
...authHeaders
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
return ((_a = options.fetch) != null ? _a : fetch)(url, fetchInit);
|
|
88
|
+
};
|
|
89
|
+
return createVertexMaas({
|
|
90
|
+
...options,
|
|
91
|
+
fetch: customFetch,
|
|
92
|
+
headers: void 0
|
|
93
|
+
// Don't pass headers, we handle them in fetch
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
var vertexMaas = createVertexMaas2();
|
|
97
|
+
export {
|
|
98
|
+
createVertexMaas2 as createVertexMaas,
|
|
99
|
+
vertexMaas
|
|
100
|
+
};
|
|
101
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/maas/google-vertex-maas-provider-node.ts","../../src/google-vertex-auth-google-auth-library.ts","../../src/maas/google-vertex-maas-provider.ts"],"sourcesContent":["import { FetchFunction, resolve } from '@ai-sdk/provider-utils';\nimport { GoogleAuthOptions } from 'google-auth-library';\nimport { generateAuthToken } from '../google-vertex-auth-google-auth-library';\nimport {\n createVertexMaas as createVertexMaasOriginal,\n GoogleVertexMaasProvider,\n GoogleVertexMaasProviderSettings as GoogleVertexMaasProviderSettingsOriginal,\n} from './google-vertex-maas-provider';\n\nexport type { GoogleVertexMaasProvider };\n\nexport interface GoogleVertexMaasProviderSettings extends GoogleVertexMaasProviderSettingsOriginal {\n /**\n * Optional. The Authentication options provided by google-auth-library.\n * Complete list of authentication options is documented in the\n * GoogleAuthOptions interface:\n * https://github.com/googleapis/google-auth-library-nodejs/blob/main/src/auth/googleauth.ts.\n */\n googleAuthOptions?: GoogleAuthOptions;\n}\n\n/**\n * Create a Google Vertex AI MaaS (Model as a Service) provider instance for Node.js.\n * Uses the OpenAI-compatible Chat Completions API for partner and open models.\n * Automatically handles Google Cloud authentication.\n *\n * @see https://cloud.google.com/vertex-ai/generative-ai/docs/maas/use-open-models\n */\nexport function createVertexMaas(\n options: GoogleVertexMaasProviderSettings = {},\n): GoogleVertexMaasProvider {\n // Create a custom fetch wrapper that adds auth headers\n const customFetch: FetchFunction = async (url, init) => {\n const token = await generateAuthToken(options.googleAuthOptions);\n const resolvedHeaders = await resolve(options.headers);\n const authHeaders = {\n ...resolvedHeaders,\n Authorization: `Bearer ${token}`,\n };\n\n // Merge auth headers with existing headers from init\n const fetchInit = {\n ...init,\n headers: {\n ...init?.headers,\n ...authHeaders,\n },\n };\n\n // Call the original fetch or user's custom fetch\n return (options.fetch ?? fetch)(url, fetchInit);\n };\n\n return createVertexMaasOriginal({\n ...options,\n fetch: customFetch,\n headers: undefined, // Don't pass headers, we handle them in fetch\n });\n}\n\n/**\n * Default Google Vertex AI MaaS provider instance for Node.js.\n */\nexport const vertexMaas = createVertexMaas();\n","import { GoogleAuth, GoogleAuthOptions } from 'google-auth-library';\n\nlet authInstance: GoogleAuth | null = null;\nlet authOptions: GoogleAuthOptions | null = null;\n\nfunction getAuth(options: GoogleAuthOptions) {\n if (!authInstance || options !== authOptions) {\n authInstance = new GoogleAuth({\n scopes: ['https://www.googleapis.com/auth/cloud-platform'],\n ...options,\n });\n authOptions = options;\n }\n return authInstance;\n}\n\nexport async function generateAuthToken(options?: GoogleAuthOptions) {\n const auth = getAuth(options || {});\n const client = await auth.getClient();\n const token = await client.getAccessToken();\n return token?.token || null;\n}\n\n// For testing purposes only\nexport function _resetAuthInstance() {\n authInstance = null;\n}\n","import { createOpenAICompatible } from '@ai-sdk/openai-compatible';\nimport type { OpenAICompatibleProvider } from '@ai-sdk/openai-compatible';\nimport {\n FetchFunction,\n loadOptionalSetting,\n loadSetting,\n Resolvable,\n withoutTrailingSlash,\n} from '@ai-sdk/provider-utils';\nimport type { GoogleVertexMaasModelId } from './google-vertex-maas-options';\n\nexport interface GoogleVertexMaasProvider extends OpenAICompatibleProvider<\n GoogleVertexMaasModelId,\n string,\n string,\n string\n> {}\n\nexport interface GoogleVertexMaasProviderSettings {\n /**\n * Google Cloud project ID. Defaults to the value of the `GOOGLE_VERTEX_PROJECT` environment variable.\n */\n project?: string;\n\n /**\n * Google Cloud location/region. Defaults to the value of the `GOOGLE_VERTEX_LOCATION` environment variable.\n * Use 'global' for the global endpoint.\n */\n location?: string;\n\n /**\n * Base URL for the API calls. If not provided, will be constructed from project and location.\n */\n baseURL?: string;\n\n /**\n * Headers to use for requests. Can be:\n * - A headers object\n * - A Promise that resolves to a headers object\n * - A function that returns a headers object\n * - A function that returns a Promise of a headers object\n */\n headers?: Resolvable<Record<string, string | undefined>>;\n\n /**\n * Custom fetch implementation. You can use it as a middleware to intercept requests,\n * or to provide a custom fetch implementation for e.g. testing.\n */\n fetch?: FetchFunction;\n}\n\n/**\n * Create a Google Vertex AI MaaS (Model as a Service) provider instance.\n * Uses the OpenAI-compatible Chat Completions API for partner and open models.\n *\n * @see https://cloud.google.com/vertex-ai/generative-ai/docs/maas/use-open-models\n */\nexport function createVertexMaas(\n options: GoogleVertexMaasProviderSettings = {},\n): GoogleVertexMaasProvider {\n // Lazy-load settings to support loading from environment variables at runtime\n const loadLocation = () =>\n loadOptionalSetting({\n settingValue: options.location,\n environmentVariableName: 'GOOGLE_VERTEX_LOCATION',\n });\n\n const loadProject = () =>\n loadSetting({\n settingValue: options.project,\n settingName: 'project',\n environmentVariableName: 'GOOGLE_VERTEX_PROJECT',\n description: 'Google Vertex project',\n });\n\n // Construct base URL: https://aiplatform.googleapis.com/v1/projects/{project}/locations/{location}/endpoints/openapi\n const constructBaseURL = () => {\n const projectId = loadProject();\n const location = loadLocation() ?? 'global';\n\n return `https://aiplatform.googleapis.com/v1/projects/${projectId}/locations/${location}/endpoints/openapi`;\n };\n\n const loadBaseURL = () =>\n withoutTrailingSlash(options.baseURL ?? '') || constructBaseURL();\n\n let cachedProvider: GoogleVertexMaasProvider | undefined;\n const getProvider = () =>\n (cachedProvider ??= createOpenAICompatible({\n name: 'vertex.maas',\n baseURL: loadBaseURL(),\n fetch: options.fetch,\n }));\n\n const provider = (modelId: GoogleVertexMaasModelId) => getProvider()(modelId);\n\n provider.specificationVersion = 'v4' as const;\n provider.languageModel = (modelId: GoogleVertexMaasModelId) =>\n getProvider().languageModel(modelId);\n provider.chatModel = (modelId: GoogleVertexMaasModelId) =>\n getProvider().chatModel(modelId);\n provider.completionModel = (modelId: string) =>\n getProvider().completionModel(modelId);\n provider.embeddingModel = (modelId: string) =>\n getProvider().embeddingModel(modelId);\n provider.textEmbeddingModel = (modelId: string) =>\n getProvider().textEmbeddingModel(modelId);\n provider.imageModel = (modelId: string) => getProvider().imageModel(modelId);\n\n return provider as GoogleVertexMaasProvider;\n}\n"],"mappings":";AAAA,SAAwB,eAAe;;;ACAvC,SAAS,kBAAqC;AAE9C,IAAI,eAAkC;AACtC,IAAI,cAAwC;AAE5C,SAAS,QAAQ,SAA4B;AAC3C,MAAI,CAAC,gBAAgB,YAAY,aAAa;AAC5C,mBAAe,IAAI,WAAW;AAAA,MAC5B,QAAQ,CAAC,gDAAgD;AAAA,MACzD,GAAG;AAAA,IACL,CAAC;AACD,kBAAc;AAAA,EAChB;AACA,SAAO;AACT;AAEA,eAAsB,kBAAkB,SAA6B;AACnE,QAAM,OAAO,QAAQ,WAAW,CAAC,CAAC;AAClC,QAAM,SAAS,MAAM,KAAK,UAAU;AACpC,QAAM,QAAQ,MAAM,OAAO,eAAe;AAC1C,UAAO,+BAAO,UAAS;AACzB;;;ACrBA,SAAS,8BAA8B;AAEvC;AAAA,EAEE;AAAA,EACA;AAAA,EAEA;AAAA,OACK;AAiDA,SAAS,iBACd,UAA4C,CAAC,GACnB;AAE1B,QAAM,eAAe,MACnB,oBAAoB;AAAA,IAClB,cAAc,QAAQ;AAAA,IACtB,yBAAyB;AAAA,EAC3B,CAAC;AAEH,QAAM,cAAc,MAClB,YAAY;AAAA,IACV,cAAc,QAAQ;AAAA,IACtB,aAAa;AAAA,IACb,yBAAyB;AAAA,IACzB,aAAa;AAAA,EACf,CAAC;AAGH,QAAM,mBAAmB,MAAM;AA5EjC;AA6EI,UAAM,YAAY,YAAY;AAC9B,UAAM,YAAW,kBAAa,MAAb,YAAkB;AAEnC,WAAO,iDAAiD,SAAS,cAAc,QAAQ;AAAA,EACzF;AAEA,QAAM,cAAc,MAAG;AAnFzB;AAoFI,iCAAqB,aAAQ,YAAR,YAAmB,EAAE,KAAK,iBAAiB;AAAA;AAElE,MAAI;AACJ,QAAM,cAAc,MACjB,2DAAmB,uBAAuB;AAAA,IACzC,MAAM;AAAA,IACN,SAAS,YAAY;AAAA,IACrB,OAAO,QAAQ;AAAA,EACjB,CAAC;AAEH,QAAM,WAAW,CAAC,YAAqC,YAAY,EAAE,OAAO;AAE5E,WAAS,uBAAuB;AAChC,WAAS,gBAAgB,CAAC,YACxB,YAAY,EAAE,cAAc,OAAO;AACrC,WAAS,YAAY,CAAC,YACpB,YAAY,EAAE,UAAU,OAAO;AACjC,WAAS,kBAAkB,CAAC,YAC1B,YAAY,EAAE,gBAAgB,OAAO;AACvC,WAAS,iBAAiB,CAAC,YACzB,YAAY,EAAE,eAAe,OAAO;AACtC,WAAS,qBAAqB,CAAC,YAC7B,YAAY,EAAE,mBAAmB,OAAO;AAC1C,WAAS,aAAa,CAAC,YAAoB,YAAY,EAAE,WAAW,OAAO;AAE3E,SAAO;AACT;;;AFlFO,SAASA,kBACd,UAA4C,CAAC,GACnB;AAE1B,QAAM,cAA6B,OAAO,KAAK,SAAS;AAhC1D;AAiCI,UAAM,QAAQ,MAAM,kBAAkB,QAAQ,iBAAiB;AAC/D,UAAM,kBAAkB,MAAM,QAAQ,QAAQ,OAAO;AACrD,UAAM,cAAc;AAAA,MAClB,GAAG;AAAA,MACH,eAAe,UAAU,KAAK;AAAA,IAChC;AAGA,UAAM,YAAY;AAAA,MAChB,GAAG;AAAA,MACH,SAAS;AAAA,QACP,GAAG,6BAAM;AAAA,QACT,GAAG;AAAA,MACL;AAAA,IACF;AAGA,aAAQ,aAAQ,UAAR,YAAiB,OAAO,KAAK,SAAS;AAAA,EAChD;AAEA,SAAO,iBAAyB;AAAA,IAC9B,GAAG;AAAA,IACH,OAAO;AAAA,IACP,SAAS;AAAA;AAAA,EACX,CAAC;AACH;AAKO,IAAM,aAAaA,kBAAiB;","names":["createVertexMaas"]}
|
|
@@ -5,14 +5,15 @@ description: Learn how to use the Google Vertex AI provider.
|
|
|
5
5
|
|
|
6
6
|
# Google Vertex Provider
|
|
7
7
|
|
|
8
|
-
The Google Vertex provider for the [AI SDK](/docs) contains language model support for the [Google Vertex AI](https://cloud.google.com/vertex-ai) APIs. This includes support for [Google's Gemini models](https://cloud.google.com/vertex-ai/generative-ai/docs/learn/models)
|
|
8
|
+
The Google Vertex provider for the [AI SDK](/docs) contains language model support for the [Google Vertex AI](https://cloud.google.com/vertex-ai) APIs. This includes support for [Google's Gemini models](https://cloud.google.com/vertex-ai/generative-ai/docs/learn/models), [Anthropic's Claude partner models](https://cloud.google.com/vertex-ai/generative-ai/docs/partner-models/use-claude), and [MaaS (Model as a Service) open models](https://cloud.google.com/vertex-ai/generative-ai/docs/maas/use-open-models).
|
|
9
9
|
|
|
10
10
|
<Note>
|
|
11
11
|
The Google Vertex provider is compatible with both Node.js and Edge runtimes.
|
|
12
12
|
The Edge runtime is supported through the `@ai-sdk/google-vertex/edge`
|
|
13
13
|
sub-module. More details can be found in the [Google Vertex Edge
|
|
14
|
-
Runtime](#google-vertex-edge-runtime)
|
|
15
|
-
Runtime](#google-vertex-anthropic-edge-runtime)
|
|
14
|
+
Runtime](#google-vertex-edge-runtime), [Google Vertex Anthropic Edge
|
|
15
|
+
Runtime](#google-vertex-anthropic-edge-runtime), and [Google Vertex MaaS Edge
|
|
16
|
+
Runtime](#google-vertex-maas-edge-runtime) sections below.
|
|
16
17
|
</Note>
|
|
17
18
|
|
|
18
19
|
## Setup
|
|
@@ -344,6 +345,15 @@ The following optional provider options are available for Google Vertex models:
|
|
|
344
345
|
|
|
345
346
|
Consult [Google's Documentation](https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/add-labels-to-api-calls) for usage details.
|
|
346
347
|
|
|
348
|
+
- **streamFunctionCallArguments** _boolean_
|
|
349
|
+
|
|
350
|
+
Optional. When set to true, function call arguments will be streamed
|
|
351
|
+
incrementally in streaming responses. This enables `tool-input-delta` events
|
|
352
|
+
to arrive as the model generates function call arguments, reducing perceived
|
|
353
|
+
latency for tool calls. Defaults to `true` for Vertex AI providers. Only supported on the Vertex AI API (not the Gemini API).
|
|
354
|
+
|
|
355
|
+
Consult [Google's Documentation](https://docs.cloud.google.com/vertex-ai/generative-ai/docs/multimodal/function-calling#streaming-fc) for details.
|
|
356
|
+
|
|
347
357
|
You can use Google Vertex language models to generate text with the `generateText` function:
|
|
348
358
|
|
|
349
359
|
```ts highlight="1,4"
|
|
@@ -453,6 +463,60 @@ const result = await generateText({
|
|
|
453
463
|
|
|
454
464
|
The optional `retrievalConfig.latLng` provider option provides location context for queries about nearby places. This configuration applies to any grounding tools that support location context.
|
|
455
465
|
|
|
466
|
+
#### Streaming Function Call Arguments
|
|
467
|
+
|
|
468
|
+
For Gemini 3 Pro and later models on Vertex AI, you can stream function call
|
|
469
|
+
arguments as they are generated by setting `streamFunctionCallArguments` to
|
|
470
|
+
`true`. This reduces perceived latency when functions need to be called, as
|
|
471
|
+
`tool-input-delta` events arrive incrementally instead of waiting for the
|
|
472
|
+
complete arguments. This option is `true` by default and you can opt out by
|
|
473
|
+
setting it to false.
|
|
474
|
+
|
|
475
|
+
```ts
|
|
476
|
+
import { vertex } from '@ai-sdk/google-vertex';
|
|
477
|
+
import { type GoogleLanguageModelOptions } from '@ai-sdk/google';
|
|
478
|
+
import { streamText } from 'ai';
|
|
479
|
+
import { z } from 'zod';
|
|
480
|
+
|
|
481
|
+
const result = streamText({
|
|
482
|
+
model: vertex('gemini-3.1-pro-preview'),
|
|
483
|
+
prompt: 'What is the weather in Boston and San Francisco?',
|
|
484
|
+
tools: {
|
|
485
|
+
getWeather: {
|
|
486
|
+
description: 'Get the current weather in a given location',
|
|
487
|
+
inputSchema: z.object({
|
|
488
|
+
location: z.string().describe('City name'),
|
|
489
|
+
}),
|
|
490
|
+
},
|
|
491
|
+
},
|
|
492
|
+
providerOptions: {
|
|
493
|
+
vertex: {
|
|
494
|
+
streamFunctionCallArguments: false,
|
|
495
|
+
} satisfies GoogleLanguageModelOptions,
|
|
496
|
+
},
|
|
497
|
+
});
|
|
498
|
+
|
|
499
|
+
for await (const part of result.fullStream) {
|
|
500
|
+
switch (part.type) {
|
|
501
|
+
case 'tool-input-start':
|
|
502
|
+
console.log(`Tool call started: ${part.toolName}`);
|
|
503
|
+
break;
|
|
504
|
+
case 'tool-input-delta':
|
|
505
|
+
process.stdout.write(part.delta);
|
|
506
|
+
break;
|
|
507
|
+
case 'tool-call':
|
|
508
|
+
console.log(`Tool call complete: ${part.toolName}`, part.input);
|
|
509
|
+
break;
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
```
|
|
513
|
+
|
|
514
|
+
<Note>
|
|
515
|
+
This feature is only available on the Vertex AI API. It is not supported on
|
|
516
|
+
the Gemini API. When used with the Google Generative AI provider, a warning
|
|
517
|
+
will be emitted and the option will be ignored.
|
|
518
|
+
</Note>
|
|
519
|
+
|
|
456
520
|
#### Reasoning (Thinking Tokens)
|
|
457
521
|
|
|
458
522
|
Google Vertex AI, through its support for Gemini models, can also emit "thinking" tokens, representing the model's reasoning process. The AI SDK exposes these as reasoning information.
|
|
@@ -829,9 +893,10 @@ The following optional provider options are available for Google Vertex AI embed
|
|
|
829
893
|
|
|
830
894
|
#### Model Capabilities
|
|
831
895
|
|
|
832
|
-
| Model
|
|
833
|
-
|
|
|
834
|
-
| `text-embedding-005`
|
|
896
|
+
| Model | Max Values Per Call | Parallel Calls | Multimodal |
|
|
897
|
+
| ---------------------------- | ------------------- | ------------------- | ------------------- |
|
|
898
|
+
| `text-embedding-005` | 2048 | <Check size={18} /> | <Cross size={18} /> |
|
|
899
|
+
| `gemini-embedding-2-preview` | 2048 | <Check size={18} /> | <Check size={18} /> |
|
|
835
900
|
|
|
836
901
|
<Note>
|
|
837
902
|
The table above lists popular models. You can also pass any available provider
|
|
@@ -1428,6 +1493,12 @@ The following optional provider options are available for Anthropic models:
|
|
|
1428
1493
|
|
|
1429
1494
|
Optional. See [Reasoning section](#reasoning) for more details.
|
|
1430
1495
|
|
|
1496
|
+
- `metadata` _object_
|
|
1497
|
+
|
|
1498
|
+
Optional. Metadata to include with the request. See the [Anthropic API documentation](https://platform.claude.com/docs/en/api/messages/create) for details.
|
|
1499
|
+
|
|
1500
|
+
- `userId` _string_ - An external identifier for the end-user.
|
|
1501
|
+
|
|
1431
1502
|
### Reasoning
|
|
1432
1503
|
|
|
1433
1504
|
Anthropic has reasoning support for the `claude-3-7-sonnet@20250219` model.
|
|
@@ -1547,6 +1618,12 @@ Google Vertex Anthropic supports a subset of Anthropic's built-in tools. The fol
|
|
|
1547
1618
|
`@ai-sdk/anthropic` provider if you need access to all Anthropic tools.
|
|
1548
1619
|
</Note>
|
|
1549
1620
|
|
|
1621
|
+
<Note>
|
|
1622
|
+
Google Vertex Anthropic does not support strict mode on tool definitions.
|
|
1623
|
+
Setting `strict: true` on a tool will be ignored and a warning will be
|
|
1624
|
+
emitted.
|
|
1625
|
+
</Note>
|
|
1626
|
+
|
|
1550
1627
|
For more background on Anthropic tools, see [Anthropic's documentation](https://platform.claude.com/docs/en/agents-and-tools/tool-use/overview).
|
|
1551
1628
|
|
|
1552
1629
|
#### Bash Tool
|
|
@@ -1703,3 +1780,147 @@ See also [Anthropic Model Comparison](https://docs.anthropic.com/en/docs/about-c
|
|
|
1703
1780
|
The table above lists popular models. You can also pass any available provider
|
|
1704
1781
|
model ID as a string if needed.
|
|
1705
1782
|
</Note>
|
|
1783
|
+
|
|
1784
|
+
## Google Vertex MaaS Provider Usage
|
|
1785
|
+
|
|
1786
|
+
The Google Vertex MaaS (Model as a Service) provider offers access to partner and open models hosted on Vertex AI through an OpenAI-compatible Chat Completions API. This includes models from DeepSeek, Qwen, Meta, MiniMax, Moonshot, and OpenAI.
|
|
1787
|
+
|
|
1788
|
+
For more information, see the [Vertex AI MaaS documentation](https://cloud.google.com/vertex-ai/generative-ai/docs/maas/use-open-models).
|
|
1789
|
+
|
|
1790
|
+
### Provider Instance
|
|
1791
|
+
|
|
1792
|
+
You can import the default provider instance `vertexMaas` from `@ai-sdk/google-vertex/maas`:
|
|
1793
|
+
|
|
1794
|
+
```typescript
|
|
1795
|
+
import { vertexMaas } from '@ai-sdk/google-vertex/maas';
|
|
1796
|
+
```
|
|
1797
|
+
|
|
1798
|
+
If you need a customized setup, you can import `createVertexMaas` from `@ai-sdk/google-vertex/maas` and create a provider instance with your settings:
|
|
1799
|
+
|
|
1800
|
+
```typescript
|
|
1801
|
+
import { createVertexMaas } from '@ai-sdk/google-vertex/maas';
|
|
1802
|
+
|
|
1803
|
+
const vertexMaas = createVertexMaas({
|
|
1804
|
+
project: 'my-project', // optional
|
|
1805
|
+
location: 'us-east5', // optional, defaults to 'global'
|
|
1806
|
+
});
|
|
1807
|
+
```
|
|
1808
|
+
|
|
1809
|
+
#### Node.js Runtime
|
|
1810
|
+
|
|
1811
|
+
For Node.js environments, the Google Vertex MaaS provider supports all standard Google Cloud authentication options through the `google-auth-library`:
|
|
1812
|
+
|
|
1813
|
+
```typescript
|
|
1814
|
+
import { createVertexMaas } from '@ai-sdk/google-vertex/maas';
|
|
1815
|
+
|
|
1816
|
+
const vertexMaas = createVertexMaas({
|
|
1817
|
+
googleAuthOptions: {
|
|
1818
|
+
credentials: {
|
|
1819
|
+
client_email: 'my-email',
|
|
1820
|
+
private_key: 'my-private-key',
|
|
1821
|
+
},
|
|
1822
|
+
},
|
|
1823
|
+
});
|
|
1824
|
+
```
|
|
1825
|
+
|
|
1826
|
+
##### Optional Provider Settings
|
|
1827
|
+
|
|
1828
|
+
- **project** _string_
|
|
1829
|
+
|
|
1830
|
+
The Google Cloud project ID. Defaults to the `GOOGLE_VERTEX_PROJECT` environment variable.
|
|
1831
|
+
|
|
1832
|
+
- **location** _string_
|
|
1833
|
+
|
|
1834
|
+
The Google Cloud location, e.g. `us-east5` or `global`. Defaults to the `GOOGLE_VERTEX_LOCATION` environment variable. If not set, defaults to `global`.
|
|
1835
|
+
|
|
1836
|
+
- **googleAuthOptions** _object_
|
|
1837
|
+
|
|
1838
|
+
Optional. The Authentication options used by the [Google Auth Library](https://github.com/googleapis/google-auth-library-nodejs/).
|
|
1839
|
+
|
|
1840
|
+
- **headers** _Resolvable<Record<string, string | undefined>>_
|
|
1841
|
+
|
|
1842
|
+
Headers to include in requests.
|
|
1843
|
+
|
|
1844
|
+
- **fetch** _(input: RequestInfo, init?: RequestInit) => Promise<Response>_
|
|
1845
|
+
|
|
1846
|
+
Custom [fetch](https://developer.mozilla.org/en-US/docs/Web/API/fetch) implementation.
|
|
1847
|
+
|
|
1848
|
+
<a id="google-vertex-maas-edge-runtime"></a>
|
|
1849
|
+
|
|
1850
|
+
#### Edge Runtime
|
|
1851
|
+
|
|
1852
|
+
For Edge runtimes, import from `@ai-sdk/google-vertex/maas/edge`:
|
|
1853
|
+
|
|
1854
|
+
```typescript
|
|
1855
|
+
import { vertexMaas } from '@ai-sdk/google-vertex/maas/edge';
|
|
1856
|
+
```
|
|
1857
|
+
|
|
1858
|
+
```typescript
|
|
1859
|
+
import { createVertexMaas } from '@ai-sdk/google-vertex/maas/edge';
|
|
1860
|
+
|
|
1861
|
+
const vertexMaas = createVertexMaas({
|
|
1862
|
+
project: 'my-project',
|
|
1863
|
+
location: 'us-east5',
|
|
1864
|
+
});
|
|
1865
|
+
```
|
|
1866
|
+
|
|
1867
|
+
For Edge runtime authentication, set these environment variables:
|
|
1868
|
+
|
|
1869
|
+
- `GOOGLE_CLIENT_EMAIL`
|
|
1870
|
+
- `GOOGLE_PRIVATE_KEY`
|
|
1871
|
+
- `GOOGLE_PRIVATE_KEY_ID` (optional)
|
|
1872
|
+
|
|
1873
|
+
### Language Models
|
|
1874
|
+
|
|
1875
|
+
You can create models using the provider instance. The first argument is the model ID:
|
|
1876
|
+
|
|
1877
|
+
```ts
|
|
1878
|
+
import { vertexMaas } from '@ai-sdk/google-vertex/maas';
|
|
1879
|
+
import { generateText } from 'ai';
|
|
1880
|
+
|
|
1881
|
+
const { text } = await generateText({
|
|
1882
|
+
model: vertexMaas('deepseek-ai/deepseek-v3.2-maas'),
|
|
1883
|
+
prompt: 'Invent a new holiday and describe its traditions.',
|
|
1884
|
+
});
|
|
1885
|
+
```
|
|
1886
|
+
|
|
1887
|
+
Streaming is also supported:
|
|
1888
|
+
|
|
1889
|
+
```ts
|
|
1890
|
+
import { vertexMaas } from '@ai-sdk/google-vertex/maas';
|
|
1891
|
+
import { streamText } from 'ai';
|
|
1892
|
+
|
|
1893
|
+
const result = streamText({
|
|
1894
|
+
model: vertexMaas('deepseek-ai/deepseek-v3.2-maas'),
|
|
1895
|
+
prompt: 'Invent a new holiday and describe its traditions.',
|
|
1896
|
+
});
|
|
1897
|
+
|
|
1898
|
+
for await (const textPart of result.textStream) {
|
|
1899
|
+
process.stdout.write(textPart);
|
|
1900
|
+
}
|
|
1901
|
+
```
|
|
1902
|
+
|
|
1903
|
+
### Available Models
|
|
1904
|
+
|
|
1905
|
+
The following models are available through the MaaS provider. You can also pass any valid model ID as a string.
|
|
1906
|
+
|
|
1907
|
+
| Model ID | Provider |
|
|
1908
|
+
| ---------------------------------------------- | -------- |
|
|
1909
|
+
| `deepseek-ai/deepseek-r1-0528-maas` | DeepSeek |
|
|
1910
|
+
| `deepseek-ai/deepseek-v3.1-maas` | DeepSeek |
|
|
1911
|
+
| `deepseek-ai/deepseek-v3.2-maas` | DeepSeek |
|
|
1912
|
+
| `openai/gpt-oss-120b-maas` | OpenAI |
|
|
1913
|
+
| `openai/gpt-oss-20b-maas` | OpenAI |
|
|
1914
|
+
| `meta/llama-4-maverick-17b-128e-instruct-maas` | Meta |
|
|
1915
|
+
| `meta/llama-4-scout-17b-16e-instruct-maas` | Meta |
|
|
1916
|
+
| `minimax/minimax-m2-maas` | MiniMax |
|
|
1917
|
+
| `qwen/qwen3-coder-480b-a35b-instruct-maas` | Qwen |
|
|
1918
|
+
| `qwen/qwen3-next-80b-a3b-instruct-maas` | Qwen |
|
|
1919
|
+
| `qwen/qwen3-next-80b-a3b-thinking-maas` | Qwen |
|
|
1920
|
+
| `moonshotai/kimi-k2-thinking-maas` | Moonshot |
|
|
1921
|
+
|
|
1922
|
+
<Note>
|
|
1923
|
+
Model availability depends on your Google Cloud project and region. Check the
|
|
1924
|
+
[Vertex AI Model Garden](https://console.cloud.google.com/vertex-ai/model-garden)
|
|
1925
|
+
for the latest available models.
|
|
1926
|
+
</Note>
|
package/maas/edge.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../dist/maas/edge/index';
|
package/maas/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../dist/maas/index';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/google-vertex",
|
|
3
|
-
"version": "5.0.0-beta.
|
|
3
|
+
"version": "5.0.0-beta.41",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -18,7 +18,9 @@
|
|
|
18
18
|
"README.md",
|
|
19
19
|
"edge.d.ts",
|
|
20
20
|
"anthropic/edge.d.ts",
|
|
21
|
-
"anthropic/index.d.ts"
|
|
21
|
+
"anthropic/index.d.ts",
|
|
22
|
+
"maas/edge.d.ts",
|
|
23
|
+
"maas/index.d.ts"
|
|
22
24
|
],
|
|
23
25
|
"directories": {
|
|
24
26
|
"doc": "./docs"
|
|
@@ -44,14 +46,25 @@
|
|
|
44
46
|
"types": "./dist/anthropic/edge/index.d.ts",
|
|
45
47
|
"import": "./dist/anthropic/edge/index.mjs",
|
|
46
48
|
"require": "./dist/anthropic/edge/index.js"
|
|
49
|
+
},
|
|
50
|
+
"./maas": {
|
|
51
|
+
"types": "./dist/maas/index.d.ts",
|
|
52
|
+
"import": "./dist/maas/index.mjs",
|
|
53
|
+
"require": "./dist/maas/index.js"
|
|
54
|
+
},
|
|
55
|
+
"./maas/edge": {
|
|
56
|
+
"types": "./dist/maas/edge/index.d.ts",
|
|
57
|
+
"import": "./dist/maas/edge/index.mjs",
|
|
58
|
+
"require": "./dist/maas/edge/index.js"
|
|
47
59
|
}
|
|
48
60
|
},
|
|
49
61
|
"dependencies": {
|
|
50
62
|
"google-auth-library": "^10.5.0",
|
|
51
|
-
"@ai-sdk/anthropic": "4.0.0-beta.
|
|
52
|
-
"@ai-sdk/google": "4.0.0-beta.
|
|
53
|
-
"@ai-sdk/
|
|
54
|
-
"@ai-sdk/provider
|
|
63
|
+
"@ai-sdk/anthropic": "4.0.0-beta.23",
|
|
64
|
+
"@ai-sdk/google": "4.0.0-beta.32",
|
|
65
|
+
"@ai-sdk/openai-compatible": "3.0.0-beta.21",
|
|
66
|
+
"@ai-sdk/provider": "4.0.0-beta.10",
|
|
67
|
+
"@ai-sdk/provider-utils": "5.0.0-beta.16"
|
|
55
68
|
},
|
|
56
69
|
"devDependencies": {
|
|
57
70
|
"@types/node": "20.17.24",
|
|
@@ -85,9 +98,7 @@
|
|
|
85
98
|
"build": "pnpm clean && tsup --tsconfig tsconfig.build.json",
|
|
86
99
|
"build:watch": "pnpm clean && tsup --watch",
|
|
87
100
|
"clean": "del-cli dist docs *.tsbuildinfo",
|
|
88
|
-
"lint": "eslint \"./**/*.ts*\"",
|
|
89
101
|
"type-check": "tsc --build",
|
|
90
|
-
"prettier-check": "prettier --check \"./**/*.ts*\"",
|
|
91
102
|
"test": "pnpm test:node && pnpm test:edge",
|
|
92
103
|
"test:update": "pnpm test:node -u",
|
|
93
104
|
"test:watch": "vitest --config vitest.node.config.js",
|
|
@@ -11,8 +11,7 @@ import {
|
|
|
11
11
|
|
|
12
12
|
export type { GoogleVertexAnthropicProvider };
|
|
13
13
|
|
|
14
|
-
export interface GoogleVertexAnthropicProviderSettings
|
|
15
|
-
extends GoogleVertexAnthropicProviderSettingsOriginal {
|
|
14
|
+
export interface GoogleVertexAnthropicProviderSettings extends GoogleVertexAnthropicProviderSettingsOriginal {
|
|
16
15
|
/**
|
|
17
16
|
* Optional. The Google credentials for the Google Cloud service account. If
|
|
18
17
|
* not provided, the Google Vertex provider will use environment variables to
|
|
@@ -9,8 +9,7 @@ import {
|
|
|
9
9
|
|
|
10
10
|
export type { GoogleVertexAnthropicProvider };
|
|
11
11
|
|
|
12
|
-
export interface GoogleVertexAnthropicProviderSettings
|
|
13
|
-
extends GoogleVertexAnthropicProviderSettingsOriginal {
|
|
12
|
+
export interface GoogleVertexAnthropicProviderSettings extends GoogleVertexAnthropicProviderSettingsOriginal {
|
|
14
13
|
/**
|
|
15
14
|
* Optional. The Authentication options provided by google-auth-library.
|
|
16
15
|
* Complete list of authentication options is documented in the
|