Skip to content

The open alternative to Salesforce, designed for AI.

Bill xAI x_search calls against AI credits (#29082)

Charles Bochetccd35add0e11
diff --git a/packages/twenty-server/src/engine/metadata-modules/ai/ai-billing/utils/count-native-web-search-calls-from-steps.util.ts b/packages/twenty-server/src/engine/metadata-modules/ai/ai-billing/utils/count-native-web-search-calls-from-steps.util.ts
index 03ff9f293c7..4958bc217be 100644
--- a/packages/twenty-server/src/engine/metadata-modules/ai/ai-billing/utils/count-native-web-search-calls-from-steps.util.ts
+++ b/packages/twenty-server/src/engine/metadata-modules/ai/ai-billing/utils/count-native-web-search-calls-from-steps.util.ts
@@ -1,4 +1,12 @@
-const WEB_SEARCH_TOOL_NAME = 'web_search';
+import { NATIVE_MODEL_TOOLS_BY_SDK_PACKAGE } from 'src/engine/metadata-modules/ai/ai-models/constants/native-model-tools-by-sdk-package.const';
+import { type NativeModelTools } from 'src/engine/metadata-modules/ai/ai-models/types/native-model-tools.type';
+
+const NATIVE_SEARCH_TOOL_NAMES = new Set(
+ Object.values<NativeModelTools>(NATIVE_MODEL_TOOLS_BY_SDK_PACKAGE).flatMap(
+ (nativeTools) =>
+ Object.values(nativeTools).map((nativeTool) => nativeTool.directToolName),
+ ),
+);
export const countNativeWebSearchCallsFromSteps = (
steps: { toolCalls: { toolName: string }[] }[],
@@ -6,8 +14,8 @@ export const countNativeWebSearchCallsFromSteps = (
steps.reduce(
(count, step) =>
count +
- step.toolCalls.filter(
- (toolCall) => toolCall.toolName === WEB_SEARCH_TOOL_NAME,
+ step.toolCalls.filter((toolCall) =>
+ NATIVE_SEARCH_TOOL_NAMES.has(toolCall.toolName),
).length,
0,
);