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

@reaatech/otel-cost-exporter-core

v0.1.0

Published

Core domain types, schemas, and semantic conventions for LLM cost metrics

Readme

@reaatech/otel-cost-exporter-core

npm version License: MIT CI

Status: Pre-1.0 — APIs may change in minor versions. Pin to a specific version in production.

Core domain types, Zod schemas, GenAI semantic conventions, and shared utilities for the @reaatech/otel-cost-exporter-* ecosystem. This package is the single source of truth for all LLM cost domain shapes used across the exporter monorepo.

Installation

npm install @reaatech/otel-cost-exporter-core
# or
pnpm add @reaatech/otel-cost-exporter-core

Feature Overview

  • Domain typesPriceEntry, CostBreakdown, CostSpan, AggregationKey, TelemetryContext define the canonical shapes for LLM cost data
  • Zod schemasPriceEntrySchema, CostSpanSchema, ConfigSchema for runtime validation at system boundaries
  • GenAI semantic conventionsGEN_AI_SYSTEM, GEN_AI_REQUEST_MODEL, GEN_AI_USAGE_INPUT_TOKENS, GEN_AI_USAGE_OUTPUT_TOKENS, and cache token attribute constants
  • Structured logging — Pino-based createLogger() factory with configurable level and format (JSON or pretty-print)
  • Interval parsingparseIntervalMs() converts human-readable duration strings ("24h", "5m", "30s") to milliseconds
  • ConstantsTOKENS_PER_UNIT (1,000,000), roundTo() precision helper used throughout the cost calculation pipeline
  • Zero runtime dependencies beyond pino and zod — lightweight and tree-shakeable
  • Dual ESM/CJS output — works with import and require

Quick Start

import { CostSpanSchema, type CostSpan, createLogger } from "@reaatech/otel-cost-exporter-core";

// Validate a CostSpan at the boundary
const rawSpan = JSON.parse(incomingJson);
const span: CostSpan = CostSpanSchema.parse(rawSpan);

// Create a logger
const logger = createLogger("info", "json");
logger.info({ spanId: span.spanId, model: span.model }, "Processing span");

Exports

Domain Types

| Export | Description | |--------|-------------| | PriceEntry | Pricing for a single model: inputTokenPrice, outputTokenPrice, optional cacheReadPrice, cacheCreationPrice, effectiveDate | | CostBreakdown | Computed costs: inputCostUsd, outputCostUsd, optional cacheReadCostUsd, cacheCreationCostUsd | | CostSpan | Normalized span: spanId, traceId, provider, model, inputTokens, outputTokens, cacheReadTokens?, cacheCreationTokens?, costUsd, costBreakdown, telemetry, timestamp, startTime, endTime, durationMs, status, errorMessage? | | AggregationKey | { provider, model, environment?, ns? } — key for grouping spans by dimensions | | TelemetryContext | Deployment metadata: environment?, ns (namespace), service? |

Zod Schemas

| Export | Description | |--------|-------------| | PriceEntrySchema | Validates pricing entries — positive token prices, ISO 8601 effective date | | CostSpanSchema | Validates span structure with nested cost breakdown and telemetry context | | ConfigSchema | Full configuration validation — pricing, metrics, export, and logging sections |

GenAI Semantic Conventions

| Export | Attribute Name | |--------|---------------| | GEN_AI_SYSTEM | gen_ai.system | | GEN_AI_REQUEST_MODEL | gen_ai.request.model | | GEN_AI_USAGE_INPUT_TOKENS | gen_ai.usage.input_tokens | | GEN_AI_USAGE_OUTPUT_TOKENS | gen_ai.usage.output_tokens | | GEN_AI_USAGE_CACHE_READ_TOKENS | gen_ai.usage.cache_read_input_tokens | | GEN_AI_USAGE_CACHE_CREATION_TOKENS | gen_ai.usage.cache_creation_input_tokens | | SEMCONV_VERSION | Pinned semantic conventions version |

Constants

| Export | Value | Description | |--------|-------|-------------| | TOKENS_PER_UNIT | 1000000 | Tokens per pricing unit (1M) | | roundTo(value, decimals) | Function | Round a number to N decimal places |

Logging

| Export | Description | |--------|-------------| | createLogger(level, format) | Pino logger factory — accepts "debug" | "info" | "warn" | "error" and "json" | "text" |

Utilities

| Export | Description | |--------|-------------| | parseIntervalMs(value) | Parse a duration string ("24h", "5m", "30s", "1h30m") into milliseconds |

Usage Pattern

Every schema export has a matching type export. Use the schema for runtime validation and the type for compile-time checking:

import { PriceEntrySchema, type PriceEntry } from "@reaatech/otel-cost-exporter-core";

// Parse at the boundary — throws ZodError on invalid data
function validatePrice(raw: unknown): PriceEntry {
  return PriceEntrySchema.parse(raw);
}

Related Packages

License

MIT