Skip to main content
Charging customers for storage means knowing exactly how many bytes each one wrote — without bolting a counter onto every upload path. The S3 Strategy wraps the official AWS S3 client so that every PutObject you send is metered for you, then forwarded to Macropay as a usage event keyed to a customer. From there, a meter aggregates those bytes and a metered product price turns them into a bill. Because Macropay is your Merchant of Record, the invoice that lands also carries the right sales tax / VAT for the buyer’s jurisdiction — collected and remitted on your behalf, off your liability.
Pairs naturally with the Stream Strategy when you also serve downloads, and with the LLM Strategy if storage sits behind an AI workload.

What you’ll need

  • A Macropay organization access token (MACROPAY_ACCESS_TOKEN).
  • An S3-compatible bucket and credentials (AWS S3, Minio, R2, or any S3-API store).
  • A customer identifier to attribute each upload to.

Install

Wrap the S3 client

You build the ingestion pipeline once — pass it your S3Client, choose the S3Strategy, and name the event (s3-uploads below). At request time, .client({ customerId }) hands you a drop-in S3 client that behaves exactly like the original, except every write it sends is measured and reported.
Set customerId from whatever you trust as the source of truth — a header, a verified session, or your auth context. Macropay matches it to the customer record that owns the meter, so attribution stays accurate even under concurrency.

What gets sent

Each wrapped PutObject emits one usage event. The strategy fills in metadata.bytes automatically; the rest describes the object so you can audit, filter, or build a meter on any field.

Turn bytes into revenue

1

Create a meter

Define a meter that filters on name = "s3-uploads" and aggregates metadata.bytes. Switch the aggregation to a COUNT of events if you’d rather bill per upload than per byte.
2

Attach a metered price

Add a metered price to a product — for example, a per-GB rate, or a tier that includes a free allowance before usage charges begin.
3

Let Macropay close the loop

Usage rolls up automatically. At billing time Macropay charges the customer, applies the correct sales tax / VAT for their location, and remits it as Merchant of Record — so storage revenue never expands your tax footprint.

Beyond storage: metering agents

The same wrap-and-meter pattern powers Macropay’s AI billing. When an autonomous agent stages artifacts in S3 — render outputs, scraped corpora, generated reports — those writes become billable usage with zero extra instrumentation, and you can bill by usage, activity, or outcome rather than flat seats. Pair S3 metering with the event ingestion API to attribute both the work an agent does and the value it produces.
Need a metering pattern we don’t cover yet? Reach us at support@macropay.ai and we’ll help you wire it up.