agentskit.js

costGuard

Auto-generated API reference for costGuard.

Function: costGuard()

costGuard(options): any

Defined in: cost-guard.ts:127

A cost-guarded observer. Tracks token usage from llm:end events, computes running cost, aborts the run when the budget is exceeded.

Usage:

const controller = new AbortController()
const runtime = createRuntime({
  adapter,
  observers: [costGuard({ budgetUsd: 0.10, controller })],
})

try {
  await runtime.run('long task', { signal: controller.signal })
} catch (err) {
  if ((err as Error).name === 'AbortError') {
    console.log('Aborted due to cost budget.')
  }
}

#Parameters

#options

CostGuardOptions

#Returns

any

Explore nearby

✎ Edit this page on GitHub·Found a problem? Open an issue →·How to contribute →

On this page