@ai-sdk/google 4.0.0-canary.69 → 4.0.0-canary.70

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 CHANGED
@@ -1,5 +1,11 @@
1
1
  # @ai-sdk/google
2
2
 
3
+ ## 4.0.0-canary.70
4
+
5
+ ### Patch Changes
6
+
7
+ - aeea161: feat(google): read `serviceTier` from `x-gemini-service-tier` response header in Gemini API and use PayGo for Vertex
8
+
3
9
  ## 4.0.0-canary.69
4
10
 
5
11
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -41,6 +41,8 @@ declare const googleLanguageModelOptions: _ai_sdk_provider_utils.LazySchema<{
41
41
  } | undefined;
42
42
  streamFunctionCallArguments?: boolean | undefined;
43
43
  serviceTier?: "standard" | "flex" | "priority" | undefined;
44
+ sharedRequestType?: "standard" | "flex" | "priority" | undefined;
45
+ requestType?: "shared" | undefined;
44
46
  }>;
45
47
  type GoogleLanguageModelOptions = InferSchema<typeof googleLanguageModelOptions>;
46
48
 
@@ -189,7 +191,6 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
189
191
  blocked?: boolean | null | undefined;
190
192
  }[] | null | undefined;
191
193
  } | null | undefined;
192
- serviceTier?: string | null | undefined;
193
194
  }>;
194
195
  type GroundingMetadataSchema = NonNullable<InferSchema<typeof responseSchema>['candidates'][number]['groundingMetadata']>;
195
196
  type UrlContextMetadataSchema = NonNullable<InferSchema<typeof responseSchema>['candidates'][number]['urlContextMetadata']>;
package/dist/index.js CHANGED
@@ -7,7 +7,7 @@ import {
7
7
  } from "@ai-sdk/provider-utils";
8
8
 
9
9
  // src/version.ts
10
- var VERSION = true ? "4.0.0-canary.69" : "0.0.0-test";
10
+ var VERSION = true ? "4.0.0-canary.70" : "0.0.0-test";
11
11
 
12
12
  // src/google-embedding-model.ts
13
13
  import {
@@ -989,17 +989,32 @@ var googleLanguageModelOptions = lazySchema4(
989
989
  */
990
990
  streamFunctionCallArguments: z4.boolean().optional(),
991
991
  /**
992
- * Optional. The service tier to use for the request.
992
+ * Optional. The service tier to use for the request. Sent as the
993
+ * `serviceTier` body field. Gemini API only.
993
994
  */
994
- serviceTier: z4.enum(["standard", "flex", "priority"]).optional()
995
+ serviceTier: z4.enum(["standard", "flex", "priority"]).optional(),
996
+ /**
997
+ * Optional. Vertex AI only. Sent as the
998
+ * `X-Vertex-AI-LLM-Shared-Request-Type` request header to select a
999
+ * shared (PayGo) tier. With Provisioned Throughput allocated and
1000
+ * `requestType` unset, the request falls back to this tier only if
1001
+ * PT capacity is exhausted.
1002
+ *
1003
+ * https://docs.cloud.google.com/vertex-ai/generative-ai/docs/priority-paygo
1004
+ * https://docs.cloud.google.com/vertex-ai/generative-ai/docs/flex-paygo
1005
+ */
1006
+ sharedRequestType: z4.enum(["priority", "flex", "standard"]).optional(),
1007
+ /**
1008
+ * Optional. Vertex AI only. Sent as the `X-Vertex-AI-LLM-Request-Type`
1009
+ * request header. Set to `'shared'` together with `sharedRequestType`
1010
+ * to bypass Provisioned Throughput entirely.
1011
+ *
1012
+ * https://docs.cloud.google.com/vertex-ai/generative-ai/docs/priority-paygo
1013
+ */
1014
+ requestType: z4.enum(["shared"]).optional()
995
1015
  })
996
1016
  )
997
1017
  );
998
- var VertexServiceTierMap = {
999
- standard: "SERVICE_TIER_STANDARD",
1000
- flex: "SERVICE_TIER_FLEX",
1001
- priority: "SERVICE_TIER_PRIORITY"
1002
- };
1003
1018
 
1004
1019
  // src/google-prepare-tools.ts
1005
1020
  import {
@@ -1580,10 +1595,27 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1580
1595
  message: `'streamFunctionCallArguments' is only supported on the Vertex AI API and will be ignored with the current Google provider (${this.config.provider}). See https://docs.cloud.google.com/vertex-ai/generative-ai/docs/multimodal/function-calling#streaming-fc`
1581
1596
  });
1582
1597
  }
1583
- let sanitizedServiceTier = googleOptions == null ? void 0 : googleOptions.serviceTier;
1584
1598
  if ((googleOptions == null ? void 0 : googleOptions.serviceTier) && isVertexProvider) {
1585
- sanitizedServiceTier = VertexServiceTierMap[googleOptions.serviceTier];
1599
+ warnings.push({
1600
+ type: "other",
1601
+ message: "'serviceTier' is a Gemini API option and is not supported on Vertex AI. Use 'sharedRequestType' (and optionally 'requestType') instead. See https://docs.cloud.google.com/vertex-ai/generative-ai/docs/priority-paygo"
1602
+ });
1603
+ }
1604
+ if (((googleOptions == null ? void 0 : googleOptions.sharedRequestType) || (googleOptions == null ? void 0 : googleOptions.requestType)) && !isVertexProvider) {
1605
+ warnings.push({
1606
+ type: "other",
1607
+ message: `'sharedRequestType' and 'requestType' are Vertex AI options and are ignored with the current Google provider (${this.config.provider}).`
1608
+ });
1586
1609
  }
1610
+ const vertexPaygoHeaders = isVertexProvider && ((googleOptions == null ? void 0 : googleOptions.sharedRequestType) || (googleOptions == null ? void 0 : googleOptions.requestType)) ? {
1611
+ ...googleOptions.sharedRequestType && {
1612
+ "X-Vertex-AI-LLM-Shared-Request-Type": googleOptions.sharedRequestType
1613
+ },
1614
+ ...googleOptions.requestType && {
1615
+ "X-Vertex-AI-LLM-Request-Type": googleOptions.requestType
1616
+ }
1617
+ } : void 0;
1618
+ const bodyServiceTier = isVertexProvider ? void 0 : googleOptions == null ? void 0 : googleOptions.serviceTier;
1587
1619
  const isGemmaModel = this.modelId.toLowerCase().startsWith("gemma-");
1588
1620
  const supportsFunctionResponseParts = this.modelId.startsWith("gemini-3");
1589
1621
  const { contents, systemInstruction } = convertToGoogleMessages(prompt, {
@@ -1658,21 +1690,23 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1658
1690
  toolConfig,
1659
1691
  cachedContent: googleOptions == null ? void 0 : googleOptions.cachedContent,
1660
1692
  labels: googleOptions == null ? void 0 : googleOptions.labels,
1661
- serviceTier: sanitizedServiceTier
1693
+ serviceTier: bodyServiceTier
1662
1694
  },
1663
1695
  warnings: [...warnings, ...toolWarnings],
1664
- providerOptionsNames
1696
+ providerOptionsNames,
1697
+ extraHeaders: vertexPaygoHeaders
1665
1698
  };
1666
1699
  }
1667
1700
  async doGenerate(options) {
1668
1701
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r;
1669
- const { args, warnings, providerOptionsNames } = await this.getArgs(options);
1702
+ const { args, warnings, providerOptionsNames, extraHeaders } = await this.getArgs(options);
1670
1703
  const wrapProviderMetadata = (payload) => Object.fromEntries(
1671
1704
  providerOptionsNames.map((name) => [name, payload])
1672
1705
  );
1673
1706
  const mergedHeaders = combineHeaders2(
1674
1707
  this.config.headers ? await resolve2(this.config.headers) : void 0,
1675
- options.headers
1708
+ options.headers,
1709
+ extraHeaders
1676
1710
  );
1677
1711
  const {
1678
1712
  responseHeaders,
@@ -1821,7 +1855,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1821
1855
  safetyRatings: (_p = candidate.safetyRatings) != null ? _p : null,
1822
1856
  usageMetadata: usageMetadata != null ? usageMetadata : null,
1823
1857
  finishMessage: (_q = candidate.finishMessage) != null ? _q : null,
1824
- serviceTier: (_r = response.serviceTier) != null ? _r : null
1858
+ serviceTier: (_r = responseHeaders == null ? void 0 : responseHeaders["x-gemini-service-tier"]) != null ? _r : null
1825
1859
  }),
1826
1860
  request: { body: args },
1827
1861
  response: {
@@ -1832,16 +1866,15 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1832
1866
  };
1833
1867
  }
1834
1868
  async doStream(options) {
1835
- const { args, warnings, providerOptionsNames } = await this.getArgs(
1836
- options,
1837
- { isStreaming: true }
1838
- );
1869
+ var _a;
1870
+ const { args, warnings, providerOptionsNames, extraHeaders } = await this.getArgs(options, { isStreaming: true });
1839
1871
  const wrapProviderMetadata = (payload) => Object.fromEntries(
1840
1872
  providerOptionsNames.map((name) => [name, payload])
1841
1873
  );
1842
1874
  const headers = combineHeaders2(
1843
1875
  this.config.headers ? await resolve2(this.config.headers) : void 0,
1844
- options.headers
1876
+ options.headers,
1877
+ extraHeaders
1845
1878
  );
1846
1879
  const { responseHeaders, value: response } = await postJsonToApi2({
1847
1880
  url: `${this.config.baseURL}/${getModelPath(
@@ -1862,7 +1895,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1862
1895
  let providerMetadata = void 0;
1863
1896
  let lastGroundingMetadata = null;
1864
1897
  let lastUrlContextMetadata = null;
1865
- let serviceTier = null;
1898
+ const serviceTier = (_a = responseHeaders == null ? void 0 : responseHeaders["x-gemini-service-tier"]) != null ? _a : null;
1866
1899
  const generateId3 = this.config.generateId;
1867
1900
  let hasToolCalls = false;
1868
1901
  let currentTextBlockId = null;
@@ -1907,7 +1940,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1907
1940
  controller.enqueue({ type: "stream-start", warnings });
1908
1941
  },
1909
1942
  transform(chunk, controller) {
1910
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
1943
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
1911
1944
  if (options.includeRawChunks) {
1912
1945
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
1913
1946
  }
@@ -1920,10 +1953,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1920
1953
  if (usageMetadata != null) {
1921
1954
  usage = usageMetadata;
1922
1955
  }
1923
- if (value.serviceTier != null) {
1924
- serviceTier = value.serviceTier;
1925
- }
1926
- const candidate = (_a = value.candidates) == null ? void 0 : _a[0];
1956
+ const candidate = (_a2 = value.candidates) == null ? void 0 : _a2[0];
1927
1957
  if (candidate == null) {
1928
1958
  return;
1929
1959
  }
@@ -2574,8 +2604,7 @@ var responseSchema = lazySchema5(
2574
2604
  promptFeedback: z5.object({
2575
2605
  blockReason: z5.string().nullish(),
2576
2606
  safetyRatings: z5.array(getSafetyRatingSchema()).nullish()
2577
- }).nullish(),
2578
- serviceTier: z5.string().nullish()
2607
+ }).nullish()
2579
2608
  })
2580
2609
  )
2581
2610
  );
@@ -2596,8 +2625,7 @@ var chunkSchema = lazySchema5(
2596
2625
  promptFeedback: z5.object({
2597
2626
  blockReason: z5.string().nullish(),
2598
2627
  safetyRatings: z5.array(getSafetyRatingSchema()).nullish()
2599
- }).nullish(),
2600
- serviceTier: z5.string().nullish()
2628
+ }).nullish()
2601
2629
  })
2602
2630
  )
2603
2631
  );