CostTracker (pipeline/cost-tracker.ts)

oh-my-openclaw · src/pipeline/cost-tracker.ts · typescript · MIT
payments

CostTracker tracks token usage and budget metrics for AI agents.

// Source: https://github.com/clawflint/oh-my-openclaw | License: MIT | Copyright 2026 clawflint
// Provided via justclaw.it.com; keep this notice with the code.
import type { TokenUsage, CostControlsConfig } from '../types/index.js';

interface AgentUsage { input: number; output: number; costUsd: number; }

export interface CostSummary {
  totalCost: number;
  budgetRemaining: number;
  budgetPercent: number;
  agentBreakdown: Array<{ agent: string; cost: number; tokens: { input: number; output: number } }>;
}

export class CostTracker {
  private budget: CostControlsConfig;
  private usage: Map<string, AgentUsage> = new Map();

  constructor(budget: CostControlsConfig) { this.budget = budget; }

  recordUsage(agent: string, tokens: TokenUsage): void {
    const existing = this.usage.get(

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key