Readable or Writable stream and counts those bytes for you, emitting a metered event to Macropay as the data flows. No counters to maintain, no track() calls sprinkled through your handler.
Every byte you meter rolls up into a meter you can attach to a metered price. And because Macropay is your Merchant of Record, the tax and VAT on whatever you charge for that usage is calculated, collected, and remitted for you — globally.
Install
Wrap a stream
Construct an ingestion client with aStreamStrategy, hand it the stream you want to measure, and consume the returned wrapper exactly as you would the original. The strategy tallies bytes transparently and ships them to the meter you name in .ingest().
What gets ingested
When the stream finishes, the strategy posts a single event to your meter. Thebytes field carries the total moved through the stream:
bytes value is what your meter aggregates. Point a metered price at the meter — say, $0.10 per GB transferred — and Macropay turns the raw counts into a billable line item.
Billing agents and AI workloads
Streaming is where a lot of AI cost lives: a model response piped straight to the client, embeddings written to object storage, a retrieval pipeline fanning out documents. Wrap those streams to capture the real data volume an agent consumes. If you bill agents on activity or outcome rather than raw bytes, pair stream metering with prepaid credits to draw down a balance per event — then compare billed revenue against AI cost to see the agentic margin on every run.Related strategies
- Strategy introduction — when to reach for each one
- LLM Strategy — meter token usage from model calls
- S3 Strategy — meter bytes uploaded to object storage
- Delta Time Strategy — meter the duration of arbitrary execution