1import { ApifyClient } from 'apify-client';
2
3
4
5const client = new ApifyClient({
6 token: '<YOUR_API_TOKEN>',
7});
8
9
10const input = {
11 "rawData": [
12 {
13 "timestamp": "2026-02-01T10:00:00Z",
14 "model": "gpt-4o-mini",
15 "prompt_tokens": 500,
16 "completion_tokens": 200,
17 "feature": "chatbot",
18 "user_id": "user123"
19 }
20 ],
21 "priceTable": {
22 "gpt-4o": {
23 "inputPer1K": 0.0025,
24 "outputPer1K": 0.01
25 },
26 "gpt-4o-mini": {
27 "inputPer1K": 0.00015,
28 "outputPer1K": 0.0006
29 },
30 "claude-3-5-sonnet": {
31 "inputPer1K": 0.003,
32 "outputPer1K": 0.015
33 }
34 },
35 "anomalyDetection": {
36 "enabled": true,
37 "thresholdMultiplier": 2.5,
38 "groupByFeature": false
39 },
40 "enforcement": {
41 "enabled": false,
42 "maxDailyCost": 100,
43 "action": "warn"
44 },
45 "idempotency": {
46 "enabled": false,
47 "ttlHours": 168,
48 "allowedLateHours": 48
49 },
50 "n8n": {
51 "enabled": false,
52 "source": {
53 "type": "raw",
54 "rawEvents": []
55 },
56 "mapping": {
57 "workflowIdField": "workflowId",
58 "workflowNameField": "workflowName",
59 "nodeIdField": "nodeId",
60 "nodeNameField": "nodeName",
61 "environmentField": "env",
62 "tenantIdField": "tenantId",
63 "userIdField": "userId",
64 "runIdField": "runId",
65 "eventIdField": "eventId",
66 "timestampField": "timestamp"
67 },
68 "defaults": {
69 "environment": "prod"
70 },
71 "derive": {
72 "workflowNameFrom": "workflowId",
73 "nodeIdFrom": "nodeName",
74 "hashPrompt": true
75 }
76 },
77 "privacy": {
78 "redactIdsInLogs": true,
79 "redactStrategy": "partial"
80 },
81 "retention": {
82 "rawDays": 90,
83 "aggregateDays": 365
84 },
85 "webhookUrl": ""
86};
87
88
89const run = await client.actor("quantifiable_bouquet/ai-cost-audit-anomaly-detection").call(input);
90
91
92console.log('Results from dataset');
93console.log(`๐พ Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
94const { items } = await client.dataset(run.defaultDatasetId).listItems();
95items.forEach((item) => {
96 console.dir(item);
97});
98
99