@ai-sdk/google-vertex 5.0.126 → 5.0.128

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.
@@ -2,7 +2,7 @@ import { getRuntimeEnvironmentUserAgent, loadOptionalSetting, loadSetting, resol
2
2
  import { NoSuchModelError } from "@ai-sdk/provider";
3
3
  import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
4
4
  //#region src/version.ts
5
- const VERSION = "5.0.126";
5
+ const VERSION = "5.0.128";
6
6
  //#endregion
7
7
  //#region src/edge/google-vertex-auth-edge.ts
8
8
  const loadCredentials = async () => {
@@ -292,7 +292,12 @@ const googleVertex = createGoogleVertex({
292
292
 
293
293
  ##### Optional Provider Settings
294
294
 
295
- - **apiKey** _string_
295
+ - **apiKey** _string | PromiseLike<string> | (() => string | PromiseLike<string>)_
296
+
297
+ Pass a callback to resolve the API key before each request. The callback can
298
+ return a string or a promise; token caching and renewal are handled by the caller.
299
+ A callback or promise selects API key authentication and must resolve to a
300
+ non-empty string; lookup failures do not switch authentication methods.
296
301
 
297
302
  The API key for Google Vertex AI. When provided, the provider uses express mode with API key authentication instead of OAuth.
298
303
  It uses the `GOOGLE_VERTEX_API_KEY` environment variable by default.
@@ -764,6 +769,33 @@ const { text } = await generateText({
764
769
  files to that location.
765
770
  </Note>
766
771
 
772
+ For video file parts, pass `videoMetadata` through `providerOptions.googleVertex`
773
+ to control clipping and frame rate. It works with Cloud Storage URLs and inline
774
+ video data:
775
+
776
+ ```ts
777
+ import type { FilePart } from 'ai';
778
+
779
+ const videoPart = {
780
+ type: 'file',
781
+ data: new URL('gs://my-bucket/video.mp4'),
782
+ mediaType: 'video/mp4',
783
+ providerOptions: {
784
+ googleVertex: {
785
+ videoMetadata: {
786
+ startOffset: '60s',
787
+ endOffset: '120s',
788
+ fps: 1,
789
+ },
790
+ },
791
+ },
792
+ } satisfies FilePart;
793
+ ```
794
+
795
+ All three fields are optional. `startOffset` and `endOffset` are durations in
796
+ seconds, such as `'60s'` or `'3.5s'`. `fps` must be in the range `(0, 24]` and
797
+ defaults to `1`.
798
+
767
799
  See [File Parts](/docs/foundations/prompts#file-parts) for details on how to use files in prompts.
768
800
 
769
801
  ### Long decode
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-sdk/google-vertex",
3
- "version": "5.0.126",
3
+ "version": "5.0.128",
4
4
  "type": "module",
5
5
  "license": "Apache-2.0",
6
6
  "sideEffects": false,
@@ -71,11 +71,11 @@
71
71
  }
72
72
  },
73
73
  "dependencies": {
74
- "@ai-sdk/anthropic": "4.0.91",
75
- "@ai-sdk/google": "4.0.107",
76
- "@ai-sdk/openai-compatible": "3.0.80",
77
- "@ai-sdk/provider": "4.0.34",
78
- "@ai-sdk/provider-utils": "5.0.70",
74
+ "@ai-sdk/anthropic": "4.0.93",
75
+ "@ai-sdk/google": "4.0.109",
76
+ "@ai-sdk/openai-compatible": "3.0.82",
77
+ "@ai-sdk/provider": "4.0.35",
78
+ "@ai-sdk/provider-utils": "5.0.72",
79
79
  "google-auth-library": "^11.3.1"
80
80
  },
81
81
  "devDependencies": {
@@ -22,10 +22,13 @@ export interface GoogleVertexProviderSettings extends GoogleVertexProviderSettin
22
22
  export function createGoogleVertex(
23
23
  options: GoogleVertexProviderSettings = {},
24
24
  ): GoogleVertexProvider {
25
- const apiKey = loadOptionalSetting({
26
- settingValue: options.apiKey,
27
- environmentVariableName: 'GOOGLE_VERTEX_API_KEY',
28
- });
25
+ const apiKey =
26
+ typeof options.apiKey === 'string' || options.apiKey == null
27
+ ? loadOptionalSetting({
28
+ settingValue: options.apiKey,
29
+ environmentVariableName: 'GOOGLE_VERTEX_API_KEY',
30
+ })
31
+ : options.apiKey;
29
32
 
30
33
  if (apiKey) {
31
34
  return createGoogleVertexOriginal(options);
@@ -8,6 +8,7 @@ import {
8
8
  } from '@ai-sdk/google/internal';
9
9
  import {
10
10
  InvalidArgumentError,
11
+ LoadAPIKeyError,
11
12
  type Experimental_VideoModelV4,
12
13
  type ImageModelV4,
13
14
  type LanguageModelV4,
@@ -58,15 +59,25 @@ function isEndpointModelId(modelId: string): boolean {
58
59
 
59
60
  // set `x-goog-api-key` header to API key for express mode
60
61
  function createExpressModeFetch(
61
- apiKey: string,
62
+ apiKey: Resolvable<string>,
62
63
  customFetch?: FetchFunction,
63
64
  ): FetchFunction {
64
65
  return async (url, init) => {
66
+ const resolvedApiKey = await resolve(apiKey);
67
+ if (
68
+ typeof apiKey !== 'string' &&
69
+ (typeof resolvedApiKey !== 'string' || !resolvedApiKey.trim())
70
+ ) {
71
+ throw new LoadAPIKeyError({
72
+ message: 'Google Vertex API key must be a non-empty string.',
73
+ });
74
+ }
75
+
65
76
  const modifiedInit: RequestInit = {
66
77
  ...init,
67
78
  headers: {
68
79
  ...(init?.headers ? normalizeHeaders(init.headers) : {}),
69
- 'x-goog-api-key': apiKey,
80
+ 'x-goog-api-key': resolvedApiKey,
70
81
  },
71
82
  };
72
83
  return (customFetch ?? fetch)(url.toString(), modifiedInit);
@@ -153,8 +164,9 @@ export interface GoogleVertexProviderSettings {
153
164
  * Optional. The API key for the Google Cloud project. If provided, the
154
165
  * provider will use express mode with API key authentication. Defaults to
155
166
  * the value of the `GOOGLE_VERTEX_API_KEY` environment variable.
167
+ * A callback is resolved before each request and must return a non-empty key.
156
168
  */
157
- apiKey?: string;
169
+ apiKey?: Resolvable<string>;
158
170
 
159
171
  /**
160
172
  * Your Google Vertex location. Defaults to the environment variable `GOOGLE_VERTEX_LOCATION`.
@@ -214,10 +226,13 @@ export interface GoogleVertexProviderSettings {
214
226
  export function createGoogleVertex(
215
227
  options: GoogleVertexProviderSettings = {},
216
228
  ): GoogleVertexProvider {
217
- const apiKey = loadOptionalSetting({
218
- settingValue: options.apiKey,
219
- environmentVariableName: 'GOOGLE_VERTEX_API_KEY',
220
- });
229
+ const apiKey =
230
+ typeof options.apiKey === 'string' || options.apiKey == null
231
+ ? loadOptionalSetting({
232
+ settingValue: options.apiKey,
233
+ environmentVariableName: 'GOOGLE_VERTEX_API_KEY',
234
+ })
235
+ : options.apiKey;
221
236
 
222
237
  const loadGoogleVertexProject = () =>
223
238
  loadSetting({
@@ -21,10 +21,13 @@ export type { GoogleVertexProvider };
21
21
  export function createGoogleVertex(
22
22
  options: GoogleVertexProviderSettings = {},
23
23
  ): GoogleVertexProvider {
24
- const apiKey = loadOptionalSetting({
25
- settingValue: options.apiKey,
26
- environmentVariableName: 'GOOGLE_VERTEX_API_KEY',
27
- });
24
+ const apiKey =
25
+ typeof options.apiKey === 'string' || options.apiKey == null
26
+ ? loadOptionalSetting({
27
+ settingValue: options.apiKey,
28
+ environmentVariableName: 'GOOGLE_VERTEX_API_KEY',
29
+ })
30
+ : options.apiKey;
28
31
 
29
32
  if (apiKey) {
30
33
  return createGoogleVertexOriginal(options);