MCPcopy
hub / github.com/simstudioai/sim / processHostedKeyCost

Function processHostedKeyCost

apps/sim/tools/index.ts:544–569  ·  view source on GitHub ↗

* Calculate and log hosted key cost for a tool execution. * Logs to usageLog for audit trail and returns cost + metadata for output.

(
  tool: ToolConfig,
  params: Record<string, unknown>,
  response: Record<string, unknown>,
  executionContext: ExecutionContext | undefined,
  requestId: string
)

Source from the content-addressed store, hash-verified

542 * Logs to usageLog for audit trail and returns cost + metadata for output.
543 */
544async function processHostedKeyCost(
545 tool: ToolConfig,
546 params: Record<string, unknown>,
547 response: Record<string, unknown>,
548 executionContext: ExecutionContext | undefined,
549 requestId: string
550): Promise<HostedKeyCostResult> {
551 if (!tool.hosting?.pricing) {
552 return { cost: 0 }
553 }
554
555 const { cost, metadata } = calculateToolCost(tool.hosting.pricing, params, response)
556
557 if (cost <= 0) return { cost: 0 }
558
559 const { userId } = resolveToolScope(params, executionContext)
560
561 if (!userId) return { cost, metadata }
562
563 logger.debug(
564 `[${requestId}] Hosted key cost for ${tool.id}: $${cost}`,
565 metadata ? { metadata } : {}
566 )
567
568 return { cost, metadata }
569}
570
571/**
572 * Report custom dimension usage after successful hosted-key tool execution.

Callers 1

Calls 3

calculateToolCostFunction · 0.85
resolveToolScopeFunction · 0.85
debugMethod · 0.80

Tested by

no test coverage detected