Circle V2 API Docs
    Preparing search index...

    Function withUsageCollector

    • Meters a model's token use at construction, for LLM calls whose return shape we don't own: a legacy helper that hands back only its domain result cannot report what it spent, but the model it was handed can. Reads the same usage_metadata as sumMessageUsage, so a metered call counts identically to an agent loop.

      const { model, usage } = withUsageCollector(createChartReviewChatModel(SETTINGS));
      await someHelperThatOnlyReturnsDocuments({ model });
      recordUsage(usage());

      Type Parameters

      • T extends { callbacks?: Callbacks }

      Parameters

      • model: T

      Returns { model: T; usage: () => RunnerUsage }