@ai-sdk/xai 3.0.55 → 3.0.56

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-sdk/xai",
3
- "version": "3.0.55",
3
+ "version": "3.0.56",
4
4
  "license": "Apache-2.0",
5
5
  "sideEffects": false,
6
6
  "main": "./dist/index.js",
@@ -30,8 +30,8 @@
30
30
  },
31
31
  "dependencies": {
32
32
  "@ai-sdk/openai-compatible": "2.0.30",
33
- "@ai-sdk/provider": "3.0.8",
34
- "@ai-sdk/provider-utils": "4.0.15"
33
+ "@ai-sdk/provider-utils": "4.0.15",
34
+ "@ai-sdk/provider": "3.0.8"
35
35
  },
36
36
  "devDependencies": {
37
37
  "@types/node": "20.17.24",
@@ -6,10 +6,16 @@ export function convertXaiChatUsage(usage: XaiChatUsage): LanguageModelV3Usage {
6
6
  const reasoningTokens =
7
7
  usage.completion_tokens_details?.reasoning_tokens ?? 0;
8
8
 
9
+ const promptTokensIncludesCached = cacheReadTokens <= usage.prompt_tokens;
10
+
9
11
  return {
10
12
  inputTokens: {
11
- total: usage.prompt_tokens,
12
- noCache: usage.prompt_tokens - cacheReadTokens,
13
+ total: promptTokensIncludesCached
14
+ ? usage.prompt_tokens
15
+ : usage.prompt_tokens + cacheReadTokens,
16
+ noCache: promptTokensIncludesCached
17
+ ? usage.prompt_tokens - cacheReadTokens
18
+ : usage.prompt_tokens,
13
19
  cacheRead: cacheReadTokens,
14
20
  cacheWrite: undefined,
15
21
  },
@@ -7,10 +7,16 @@ export function convertXaiResponsesUsage(
7
7
  const cacheReadTokens = usage.input_tokens_details?.cached_tokens ?? 0;
8
8
  const reasoningTokens = usage.output_tokens_details?.reasoning_tokens ?? 0;
9
9
 
10
+ const inputTokensIncludesCached = cacheReadTokens <= usage.input_tokens;
11
+
10
12
  return {
11
13
  inputTokens: {
12
- total: usage.input_tokens,
13
- noCache: usage.input_tokens - cacheReadTokens,
14
+ total: inputTokensIncludesCached
15
+ ? usage.input_tokens
16
+ : usage.input_tokens + cacheReadTokens,
17
+ noCache: inputTokensIncludesCached
18
+ ? usage.input_tokens - cacheReadTokens
19
+ : usage.input_tokens,
14
20
  cacheRead: cacheReadTokens,
15
21
  cacheWrite: undefined,
16
22
  },