@kaiban/sdk 0.1.5 → 0.1.7

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.
@@ -4,6 +4,7 @@ import { AgentsClient } from './resources/AgentsClient';
4
4
  import { BoardsClient } from './resources/BoardsClient';
5
5
  import { CardsClient } from './resources/CardsClient';
6
6
  import { ExternalChannelsClient } from './resources/ExternalChannelsClient';
7
+ import { ModelCost } from './resources/ModelCost';
7
8
  import { ResourcesClient } from './resources/ResourcesClient';
8
9
  import { TeamsClient } from './resources/TeamsClient';
9
10
  /**
@@ -30,6 +31,8 @@ export interface KaibanClient {
30
31
  resources: ResourcesClient;
31
32
  /** Client for managing external channels */
32
33
  external_channels: ExternalChannelsClient;
34
+ /** Client for calculate model usage costs*/
35
+ costs: ModelCost;
33
36
  }
34
37
  /**
35
38
  * Create a Kaiban SDK client instance
@@ -4,6 +4,7 @@ import { AgentsClient } from './resources/AgentsClient';
4
4
  import { BoardsClient } from './resources/BoardsClient';
5
5
  import { CardsClient } from './resources/CardsClient';
6
6
  import { ExternalChannelsClient } from './resources/ExternalChannelsClient';
7
+ import { ModelCost } from './resources/ModelCost';
7
8
  import { ResourcesClient } from './resources/ResourcesClient';
8
9
  import { TeamsClient } from './resources/TeamsClient';
9
10
  /**
@@ -45,5 +46,6 @@ export function createKaibanClient(config) {
45
46
  boards: new BoardsClient(http),
46
47
  resources: new ResourcesClient(http),
47
48
  external_channels: new ExternalChannelsClient(http),
49
+ costs: new ModelCost(),
48
50
  };
49
51
  }
@@ -0,0 +1,8 @@
1
+ import { ModelCostInput, ModelCostOutput } from '../../types/entities/costs';
2
+ export declare class ModelCost {
3
+ calculateCosts(costs: ModelCostInput[]): {
4
+ totalCost: number;
5
+ totalTokens: number;
6
+ costsByModel: ModelCostOutput[];
7
+ };
8
+ }
@@ -0,0 +1,83 @@
1
+ const MODELS_COST = {
2
+ 'gpt-4o-mini': {
3
+ input_price: 0.6,
4
+ output_price: 2.4,
5
+ per_tokens: 1000000,
6
+ },
7
+ 'gpt-5-mini': {
8
+ input_price: 0.25,
9
+ output_price: 2.0,
10
+ per_tokens: 1000000,
11
+ },
12
+ 'gpt-5': {
13
+ input_price: 1.5,
14
+ output_price: 10.0,
15
+ per_tokens: 1000000,
16
+ },
17
+ 'gpt-5-nano': {
18
+ input_price: 0.05,
19
+ output_price: 0.4,
20
+ per_tokens: 1000000,
21
+ },
22
+ 'gpt-4o': {
23
+ input_price: 5.0,
24
+ output_price: 20.0,
25
+ per_tokens: 1000000,
26
+ },
27
+ 'text-embedding-3-small': {
28
+ input_price: 0.02,
29
+ output_price: 0.0,
30
+ per_tokens: 1000000,
31
+ },
32
+ };
33
+ export class ModelCost {
34
+ calculateCosts(costs) {
35
+ let totalCost = 0;
36
+ let totalTokens = 0;
37
+ const costsByModel = costs.map((line) => {
38
+ const modelConfig = MODELS_COST[line.model];
39
+ const reasoning = line.reasoningTokens ?? 0;
40
+ // Output tokens charged = visible output + reasoning tokens
41
+ const chargedOutputTokens = line.outputTokens + reasoning;
42
+ // If the model is not configured, return a neutral line with zero cost
43
+ if (!modelConfig) {
44
+ const modelTotalTokens = line.inputTokens + chargedOutputTokens;
45
+ return {
46
+ model: line.model,
47
+ inputTokens: line.inputTokens,
48
+ outputTokens: line.outputTokens,
49
+ reasoningTokens: reasoning,
50
+ chargedOutputTokens,
51
+ totalTokens: modelTotalTokens,
52
+ inputCost: 0,
53
+ outputCost: 0,
54
+ totalCost: 0,
55
+ };
56
+ }
57
+ // Cost of input tokens
58
+ const inputCost = (line.inputTokens * modelConfig.input_price) / modelConfig.per_tokens;
59
+ // Cost of output tokens (includes reasoning)
60
+ const outputCost = (chargedOutputTokens * modelConfig.output_price) / modelConfig.per_tokens;
61
+ const modelTotalCost = inputCost + outputCost;
62
+ const modelTotalTokens = line.inputTokens + chargedOutputTokens;
63
+ totalCost += modelTotalCost;
64
+ totalTokens += modelTotalTokens;
65
+ return {
66
+ model: line.model,
67
+ inputTokens: line.inputTokens,
68
+ outputTokens: line.outputTokens,
69
+ reasoningTokens: reasoning,
70
+ chargedOutputTokens,
71
+ totalTokens: modelTotalTokens,
72
+ inputCost,
73
+ outputCost,
74
+ totalCost: modelTotalCost,
75
+ };
76
+ });
77
+ return {
78
+ totalCost,
79
+ totalTokens,
80
+ costsByModel,
81
+ };
82
+ }
83
+ }
@@ -0,0 +1,11 @@
1
+ import { Activity } from './activities';
2
+ export declare const A2ADataPartType: {
3
+ readonly KAIBAN_ACTIVITY: "kaiban_activity";
4
+ };
5
+ export interface KaibanActivityPart {
6
+ kind: 'data';
7
+ data: {
8
+ type: typeof A2ADataPartType.KAIBAN_ACTIVITY;
9
+ activity: Activity;
10
+ };
11
+ }
@@ -0,0 +1,3 @@
1
+ export const A2ADataPartType = {
2
+ KAIBAN_ACTIVITY: 'kaiban_activity',
3
+ };
@@ -0,0 +1,17 @@
1
+ export interface ModelCostInput {
2
+ model: string;
3
+ inputTokens: number;
4
+ outputTokens: number;
5
+ reasoningTokens?: number;
6
+ }
7
+ export interface ModelCostOutput {
8
+ model: string;
9
+ inputTokens: number;
10
+ outputTokens: number;
11
+ reasoningTokens: number;
12
+ chargedOutputTokens: number;
13
+ totalTokens: number;
14
+ inputCost: number;
15
+ outputCost: number;
16
+ totalCost: number;
17
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -1,3 +1,4 @@
1
+ export * from './a2a-dataparts';
1
2
  export * from './activities';
2
3
  export * from './agent';
3
4
  export * from './board';
@@ -1,3 +1,4 @@
1
+ export * from './a2a-dataparts';
1
2
  export * from './activities';
2
3
  export * from './agent';
3
4
  export * from './board';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kaiban/sdk",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
4
4
  "description": "Official TypeScript SDK for the Kaiban API",
5
5
  "keywords": [
6
6
  "kaiban",