npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@croco/llm-metering

v0.0.2

Published

LLM 토큰 사용량과 비용을 기록하고 quota를 강제하는 LLM 미터링 패키지입니다.

Downloads

45

Readme

@croco/llm-metering

LLM 토큰 사용량과 비용을 기록하고 quota를 강제하는 LLM 미터링 패키지입니다.

설치

pnpm add @croco/llm-metering

사용법

import { LlmMeteringService } from "@croco/llm-metering";

const metering = new LlmMeteringService({
  meteringService,
  eventBus,
});

await metering.recordUsage({
  tenantId: "tenant-123",
  modelId: "gpt-4o-mini",
  provider: "openai",
  usage: {
    promptTokens: 120,
    completionTokens: 80,
    totalTokens: 200,
    accuracy: "EXACT",
  },
  idempotencyKey: "req-1",
});
import { AiMetered, setLlmMeteringService } from "@croco/llm-metering";

setLlmMeteringService(metering);

class LlmFacade {
  @AiMetered()
  async generate(): Promise<unknown> {
    return llmService.generate({ modelId: "default", prompt: "안녕" });
  }
}

API 레퍼런스

핵심 클래스

  • LlmMeteringService, 토큰 사용량 기록, 비용 계산, quota 확인을 담당합니다.
  • PricingTable, 공급자와 모델별 가격표를 조회하고 비용을 계산합니다.

데코레이터와 유틸리티

  • @AiMetered, 메서드 결과에서 사용량을 추출해 자동 기록합니다.
  • setLlmMeteringService, getLlmMeteringService, 데코레이터용 전역 서비스를 관리합니다.
  • createMeteredAsyncIterable, 스트리밍 완료 시 사용량을 기록합니다.
  • extractUsageFromChunk, 청크에서 usage와 모델 정보를 추출합니다.

주요 타입

  • LlmUsageEvent, LlmCostRecord, LlmMeteringServiceOptions
  • LlmUsageRecord, LlmEmbeddingUsageRecord, LlmCostBudget, ModelPricing

이벤트와 문제 타입

  • 이벤트: LlmUsageRecordedEvent, LlmCostBudgetExceededEvent
  • 문제 타입: LlmMeteringRecordFailedProblem, LlmQuotaExceededProblem, LlmCostLimitExceededProblem, PricingNotFoundProblem

구현 포인트

  • 내부적으로 @croco/metering-corellm.prompt_tokens, llm.completion_tokens, llm.cost_usd 같은 meter를 기록합니다.
  • 스트리밍 응답과 임베딩 결과 모두 같은 서비스에서 다룰 수 있습니다.
  • 가격표를 커스텀하면 공급자별 실제 과금 단가를 반영할 수 있습니다.