@ai-sdk/xai 3.0.49 → 3.0.51

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,17 @@
1
1
  # @ai-sdk/xai
2
2
 
3
+ ## 3.0.51
4
+
5
+ ### Patch Changes
6
+
7
+ - e1d5111: fix(provider/xai): correct usage token calculation for reasoning models
8
+
9
+ ## 3.0.50
10
+
11
+ ### Patch Changes
12
+
13
+ - de16a00: fix(xai): add dummy usage data when response.usage is missing
14
+
3
15
  ## 3.0.49
4
16
 
5
17
  ### Patch Changes
package/dist/index.js CHANGED
@@ -168,8 +168,8 @@ function convertXaiChatUsage(usage) {
168
168
  cacheWrite: void 0
169
169
  },
170
170
  outputTokens: {
171
- total: usage.completion_tokens,
172
- text: usage.completion_tokens - reasoningTokens,
171
+ total: usage.completion_tokens + reasoningTokens,
172
+ text: usage.completion_tokens,
173
173
  reasoning: reasoningTokens
174
174
  },
175
175
  raw: usage
@@ -561,8 +561,10 @@ var XaiChatLanguageModel = class {
561
561
  unified: mapXaiFinishReason(choice.finish_reason),
562
562
  raw: (_b = choice.finish_reason) != null ? _b : void 0
563
563
  },
564
- usage: convertXaiChatUsage(response.usage),
565
- // defined when there is no error
564
+ usage: response.usage ? convertXaiChatUsage(response.usage) : {
565
+ inputTokens: { total: 0, noCache: 0, cacheRead: 0, cacheWrite: 0 },
566
+ outputTokens: { total: 0, text: 0, reasoning: 0 }
567
+ },
566
568
  request: { body },
567
569
  response: {
568
570
  ...getResponseMetadata(response),
@@ -774,7 +776,19 @@ var XaiChatLanguageModel = class {
774
776
  });
775
777
  }
776
778
  }
777
- controller.enqueue({ type: "finish", finishReason, usage });
779
+ controller.enqueue({
780
+ type: "finish",
781
+ finishReason,
782
+ usage: usage != null ? usage : {
783
+ inputTokens: {
784
+ total: 0,
785
+ noCache: 0,
786
+ cacheRead: 0,
787
+ cacheWrite: 0
788
+ },
789
+ outputTokens: { total: 0, text: 0, reasoning: 0 }
790
+ }
791
+ });
778
792
  }
779
793
  })
780
794
  ),
@@ -2425,7 +2439,19 @@ var XaiResponsesLanguageModel = class {
2425
2439
  });
2426
2440
  }
2427
2441
  }
2428
- controller.enqueue({ type: "finish", finishReason, usage });
2442
+ controller.enqueue({
2443
+ type: "finish",
2444
+ finishReason,
2445
+ usage: usage != null ? usage : {
2446
+ inputTokens: {
2447
+ total: 0,
2448
+ noCache: 0,
2449
+ cacheRead: 0,
2450
+ cacheWrite: 0
2451
+ },
2452
+ outputTokens: { total: 0, text: 0, reasoning: 0 }
2453
+ }
2454
+ });
2429
2455
  }
2430
2456
  })
2431
2457
  ),
@@ -2490,7 +2516,7 @@ var xaiTools = {
2490
2516
  };
2491
2517
 
2492
2518
  // src/version.ts
2493
- var VERSION = true ? "3.0.49" : "0.0.0-test";
2519
+ var VERSION = true ? "3.0.51" : "0.0.0-test";
2494
2520
 
2495
2521
  // src/xai-provider.ts
2496
2522
  var xaiErrorStructure = {