@ai-sdk/amazon-bedrock 4.0.114 → 4.0.115

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.
@@ -35,7 +35,7 @@ var import_provider_utils = require("@ai-sdk/provider-utils");
35
35
  var import_aws4fetch = require("aws4fetch");
36
36
 
37
37
  // src/version.ts
38
- var VERSION = true ? "4.0.114" : "0.0.0-test";
38
+ var VERSION = true ? "4.0.115" : "0.0.0-test";
39
39
 
40
40
  // src/bedrock-sigv4-fetch.ts
41
41
  function createSigV4FetchFunction(getCredentials, fetch, service = "bedrock") {
@@ -23,7 +23,7 @@ import {
23
23
  import { AwsV4Signer } from "aws4fetch";
24
24
 
25
25
  // src/version.ts
26
- var VERSION = true ? "4.0.114" : "0.0.0-test";
26
+ var VERSION = true ? "4.0.115" : "0.0.0-test";
27
27
 
28
28
  // src/bedrock-sigv4-fetch.ts
29
29
  function createSigV4FetchFunction(getCredentials, fetch, service = "bedrock") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-sdk/amazon-bedrock",
3
- "version": "4.0.114",
3
+ "version": "4.0.115",
4
4
  "license": "Apache-2.0",
5
5
  "sideEffects": false,
6
6
  "main": "./dist/index.js",
@@ -104,7 +104,7 @@ export class BedrockEmbeddingModel implements EmbeddingModelV3 {
104
104
  };
105
105
 
106
106
  const url = this.getUrl(this.modelId);
107
- const { value: response } = await postJsonToApi({
107
+ const { value: response, responseHeaders } = await postJsonToApi({
108
108
  url,
109
109
  headers: await resolve(
110
110
  combineHeaders(await resolve(this.config.headers), headers),
@@ -145,12 +145,15 @@ export class BedrockEmbeddingModel implements EmbeddingModelV3 {
145
145
  }
146
146
 
147
147
  // Extract token count based on response format
148
+ const headerTokenCount = Number(
149
+ responseHeaders?.['x-amzn-bedrock-input-token-count'],
150
+ );
148
151
  const tokens =
149
152
  'inputTextTokenCount' in response
150
153
  ? response.inputTextTokenCount // Titan response
151
154
  : 'inputTokenCount' in response
152
155
  ? (response.inputTokenCount ?? 0) // Nova response
153
- : NaN; // Cohere doesn't return token count
156
+ : headerTokenCount;
154
157
 
155
158
  return {
156
159
  embeddings: [embedding],