@codehz/ai 0.1.7 → 0.1.8
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/dist/index.mjs +5 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/helpers/usage-mapping.ts +6 -6
package/dist/index.mjs
CHANGED
|
@@ -1062,19 +1062,19 @@ function usageFromOpenAIResponses(raw) {
|
|
|
1062
1062
|
}
|
|
1063
1063
|
/** Anthropic Messages `usage`(message_start / message_delta) */
|
|
1064
1064
|
function usageFromAnthropicMessages(raw) {
|
|
1065
|
-
const
|
|
1065
|
+
const uncachedInputTokens = num(raw.input_tokens);
|
|
1066
1066
|
const outputTokens = num(raw.output_tokens);
|
|
1067
1067
|
const cacheWriteInputTokens = num(raw.cache_creation_input_tokens);
|
|
1068
1068
|
const cachedInputTokens = num(raw.cache_read_input_tokens);
|
|
1069
1069
|
const inputParts = [
|
|
1070
|
-
|
|
1070
|
+
uncachedInputTokens,
|
|
1071
1071
|
cacheWriteInputTokens,
|
|
1072
1072
|
cachedInputTokens
|
|
1073
1073
|
].filter((n) => n !== void 0);
|
|
1074
|
-
const
|
|
1075
|
-
const totalTokens =
|
|
1074
|
+
const inputTokens = inputParts.length > 0 ? inputParts.reduce((sum, n) => sum + n, 0) : void 0;
|
|
1075
|
+
const totalTokens = inputTokens !== void 0 && outputTokens !== void 0 ? inputTokens + outputTokens : void 0;
|
|
1076
1076
|
let billableInputTokens;
|
|
1077
|
-
if (
|
|
1077
|
+
if (uncachedInputTokens !== void 0 || cacheWriteInputTokens !== void 0) billableInputTokens = (uncachedInputTokens ?? 0) + (cacheWriteInputTokens ?? 0);
|
|
1078
1078
|
return record({
|
|
1079
1079
|
inputTokens,
|
|
1080
1080
|
outputTokens,
|