@ai-sdk/google-vertex 5.0.132 → 5.0.134

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.
@@ -1,3 +1,4 @@
1
+ import { getGoogleVertexRequestConfig } from '../google-vertex-model-catalog-config';
1
2
  import { InvalidArgumentError } from '@ai-sdk/provider';
2
3
  import {
3
4
  createOpenAICompatible,
@@ -13,13 +14,9 @@ import {
13
14
  } from '@ai-sdk/provider-utils';
14
15
  import type { GoogleVertexMaasModelId } from './google-vertex-maas-options';
15
16
 
16
- const maxOutputTokensByModel: Record<string, number | undefined> = {
17
- 'meta/llama-4-maverick-17b-128e-instruct-maas': 8192,
18
- 'meta/llama-4-scout-17b-16e-instruct-maas': 8192,
19
- };
20
-
21
17
  function transformGoogleVertexMaasRequestBody(args: Record<string, any>) {
22
- const maxOutputTokens = maxOutputTokensByModel[args.model];
18
+ const maxOutputTokens = getGoogleVertexRequestConfig(args.model).language
19
+ ?.maxOutputTokens;
23
20
 
24
21
  return maxOutputTokens != null && args.max_tokens === undefined
25
22
  ? { ...args, max_tokens: maxOutputTokens }
@@ -67,14 +64,16 @@ export interface GoogleVertexMaasProviderSettings {
67
64
  }
68
65
 
69
66
  /**
70
- * Create a Google Vertex AI MaaS (Model as a Service) provider instance.
71
- * Uses the OpenAI-compatible Chat Completions API for partner and open models.
72
- *
73
- * @see https://cloud.google.com/vertex-ai/generative-ai/docs/maas/use-open-models
67
+ * Loads the base URL of the MaaS API from the settings or from the project and
68
+ * location. Settings are loaded on each call so environment variables are read
69
+ * at runtime.
74
70
  */
75
- export function createGoogleVertexMaas(
76
- options: GoogleVertexMaasProviderSettings = {},
77
- ): GoogleVertexMaasProvider {
71
+ export function loadGoogleVertexMaasBaseURL(
72
+ options: Pick<
73
+ GoogleVertexMaasProviderSettings,
74
+ 'baseURL' | 'project' | 'location'
75
+ >,
76
+ ): string {
78
77
  // Lazy-load settings to support loading from environment variables at runtime
79
78
  const loadLocation = () => {
80
79
  const location =
@@ -117,14 +116,23 @@ export function createGoogleVertexMaas(
117
116
  return `https://${getHost(location)}/v1/projects/${projectId}/locations/${location}/endpoints/openapi`;
118
117
  };
119
118
 
120
- const loadBaseURL = () =>
121
- withoutTrailingSlash(options.baseURL ?? '') || constructBaseURL();
119
+ return withoutTrailingSlash(options.baseURL ?? '') || constructBaseURL();
120
+ }
122
121
 
122
+ /**
123
+ * Create a Google Vertex AI MaaS (Model as a Service) provider instance.
124
+ * Uses the OpenAI-compatible Chat Completions API for partner and open models.
125
+ *
126
+ * @see https://cloud.google.com/vertex-ai/generative-ai/docs/maas/use-open-models
127
+ */
128
+ export function createGoogleVertexMaas(
129
+ options: GoogleVertexMaasProviderSettings = {},
130
+ ): GoogleVertexMaasProvider {
123
131
  let cachedProvider: GoogleVertexMaasProvider | undefined;
124
132
  const getProvider = () =>
125
133
  (cachedProvider ??= createOpenAICompatible({
126
134
  name: 'vertex.maas',
127
- baseURL: loadBaseURL(),
135
+ baseURL: loadGoogleVertexMaasBaseURL(options),
128
136
  fetch: options.fetch,
129
137
  transformRequestBody: transformGoogleVertexMaasRequestBody,
130
138
  }));