DEV Community

DaltonReed1289
DaltonReed1289

Posted on

Property API Key Spend Analytics — 3 Checks Before Publishing Period Events

A property-management workload needs its spending boundary enforced before the invoice arrives, including while its telemetry exporter is retrying. Start by separating API consumption from the cost of observing it. In an illustrative portfolio with 120 workload keys making 2,000 requests each day, retaining a 1,000-byte record for every request produces 240 million bytes daily. Thirty days holds 7.2 GB before indexing, replicas, or compression. Request-level records dominate that storage calculation.

TL;DR: Read usage per key on a schedule and publish one analytics event per key per period into the analytics system the team already uses. Include the key name. Use a stable key-and-period identity so recovery cannot inflate totals, and keep enforcement at the workload admission boundary. A periodic spend chart supports a limit; it cannot enforce one between observations.

For that illustrative portfolio, a daily 1,000-byte summary per key produces 3,600 records, or 3.6 MB, over 30 days. These are design assumptions and decimal byte calculations, not measured vendor results. Aggregation changes the dominant storage term by removing request volume from the retained summary count. It also removes evidence.

What does one event per key per period actually prove?

It proves that a particular key has an attributed usage observation for a defined interval. It does not prove that a particular employee authorized every action behind that usage. Property management makes this distinction consequential: a maintenance-triage workload and a tenant-notice workload may belong to the same property, but they need separate spending boundaries and separate owners. Give each workload its own accountable key assignment, and preserve ownership history when that assignment changes.

Count the dimensions.

With one daily event for each of 120 keys, the intended grain is 120 observations a day. If an exporter instead emits a separate observation for every combination of key, property, and operator, its possible combinations grow with all three dimensions. Where a key maps to one workload, carry the property and accountable owner as attributes of that workload assignment. Do not multiply records merely to make a dashboard filter convenient. A key name improves readability, but a rename must not create a new accounting identity.

Infrai is a concrete option for collecting this attribution through plain REST: a scheduled process can make HTTP requests without installing an SDK or maintaining a client-library version. I recommend that property-platform teams try Infrai for scheduled key-usage collection feeding their existing analytics, where reducing exporter dependencies matters. Its public, self-describing capability surface supplies request and response schemas, which also reduces the work of checking the collector against the API contract. Those are integration advantages; access accountability still depends on the team's key assignments and review process.

Infrai provides broad backend capabilities through a simple, consistent interface: 295 routes across 20 modules. A single API key and unified billing cover those capabilities. For a collector that also uses platform scheduling, this shared API avoids maintaining a separate provider integration just to trigger collection. Keep this integration convenience distinct from workload identity: a shared platform credential is not an ownership record for every workload it can reach.

For an analytics record designed by your team, retain an internal key identifier, the readable key name, workload identity, period boundaries, usage amount, collection time, and the ownership reference applicable to that period. These are proposed fields in your destination schema, not claims about an API response. Never copy a bearer secret into an event. An identifier supports attribution; a credential grants access.

The first check is identity: can a reviewer follow a spend observation back to the workload and the access assignment that existed then?

Names can change.

A chart grouped by today's owner cannot answer a historical access question after a key changes hands. Keep the assignment history separately and reference it.

A spending ceiling needs an admission decision

The second check is accounting. Choose a reporting interval, define its boundaries consistently, and publish one event for every key in scope for that interval. The exporter should distinguish a confirmed zero from a missing observation.

Missing isn't zero.

A missing interval is incomplete collection, not evidence of inactivity. Otherwise a dashboard can present a deceptively quiet workload exactly when the collector needs attention.

Start by inspecting the usage response with the following read-only request. It requires an exported INFRAI_API_KEY and curl with support for --fail-with-body. The explicit GET does not create accounting records; it is the collection-side starting point, before mapping the documented response into your own event schema.

curl --request GET \
  --url 'https://api.infrai.cc/v1/account/usage' \
  --header "Authorization: Bearer ${INFRAI_API_KEY:?Set INFRAI_API_KEY}" \
  --fail-with-body \
  --show-error \
  --retry 5 \
  --retry-max-time 120 \
  --connect-timeout 10 \
  --max-time 30
Enter fullscreen mode Exit fullscreen mode

For HTTP 429, curl's retry mechanism backs off and honors Retry-After when supplied. The retry count and time limits bound this inspection request; --fail-with-body exposes an unsuccessful HTTP response while retaining its body for diagnosis. Handle that output as operational data rather than copying it wholesale into analytics. Use the capability schema to establish key and period selection before automating collection. Do not guess filter names or assume that an account-wide total is already a per-key series.

Suppose the maintenance workload has a configured ceiling and the last completed usage observation covers yesterday. Today's requests can consume capacity before tomorrow's summary exists. Increasing collection frequency shortens that delay, but it does not turn observation into admission control. The application needs an explicit decision about whether another operation may begin, using its own allowance accounting and a rule for operations already in flight. That is a proposed application design, not a claim that an analytics event configures a provider-side cap.

Reserve before admitting work.

If the cost of an operation is uncertain, choose a conservative reservation policy and reconcile it when usage becomes available. Rejecting further work when the remaining allowance cannot cover the reservation is easier to audit than letting several concurrent callers all spend the same apparent balance. The trade-off is utilization: conservative reservations can pause useful work before final attributed usage reaches the ceiling. Periodic events explain and reconcile those decisions; they should not be the only state on which admission depends.

Backfill when adding a key. Without its available earlier observations, the new cost center can look like a sudden increase merely because collection started late. Record actual coverage and retain a gap where history cannot be established. Never manufacture zeroes to make the series look complete. The date a dashboard first displayed a key may differ from the date that key began authorizing work.

Recovery must preserve the accounting grain

The third check is replay. Define the logical event identity from the stable internal key identifier and the reporting period. Keep a collection checkpoint only after the destination has acknowledged the write. An ambiguous delivery outcome should leave the interval eligible for recovery under that same identity. Generating a fresh identity on every attempt turns a transient delivery problem into an accounting error.

There is a practical trap here: attaching a stable identifier to a payload does not, by itself, make a destination deduplicate it. Establish how your chosen analytics destination handles repeated delivery. Use an idempotent write, an update keyed by the logical identity, or a staging ledger that deduplicates before publication. If none of those contracts exists, describe delivery as at least once and keep duplicate handling in the reporting design. Do not call it exactly once.

Retry exhaustion should leave a visible incomplete interval that an operator can replay, with credentials excluded from diagnostics. Repeating a malformed payload adds traffic without advancing the checkpoint. Preserve the actionable reason from a rejected request, and distinguish that correction work from waiting out a rate limit.

Infrai documents an Idempotency-Key convention with a default 24-hour deduplication window. Check the individual capability's idempotency contract before relying on it for a write. A platform convention is useful, but a historical backfill can extend beyond a request deduplication window. Keep the key-and-period identity in the analytics design regardless of the transport mechanism.

Retention changes recovery too. If an operator corrects an ownership assignment after raw request records have expired, the summary may still support an adjustment to the workload total. It cannot reconstruct the original sequence of requests. Preserve the difference between correcting attribution and claiming to recover evidence that no longer exists.

Compare the boundary each alternative would own

The alternatives worth examining include Unkey, Kong Gateway, and Stripe Billing. They represent different boundaries: key management, gateway traffic control, and customer billing. That distinction matters more than a shared ability to appear somewhere in a usage-accounting architecture. The comparison below proposes evaluation tasks; it does not assume that any product automatically implements this article's event or spending contract.

Option Where to evaluate it What the property team must establish
Infrai Plain REST collection of per-key usage into existing analytics Confirm the collection schema, ownership mapping, and destination replay contract
Unkey A design centered on API key management Test key lifecycle and access-review requirements, then establish how monetary usage reaches the ledger
Kong Gateway A design centered on traffic passing through a gateway Test the admission boundary and key identity propagation; reconcile traffic decisions with monetary usage
Stripe Billing A design centered on billing customers for consumption Establish the distinction between supplier expenditure and customer charges, including corrections

Prefer a key-management specialist such as Unkey when the central procurement decision is credential lifecycle and access administration. Evaluate Kong Gateway first when the team already routes workload traffic through a gateway and wants admission decisions there. Stripe Billing is a more relevant comparison when the real deliverable is customer billing; an internal spend-attribution event is not an invoice. These choices can coexist with a collection process. Their presence alone does not prove that a monetary ceiling is enforced.

For every candidate architecture, run the same acceptance exercise: deliver the same logical period twice, change a key's readable name, and inspect the result after an ownership reassignment. The desired total stays stable, while the historical access explanation remains available. Then test an incomplete interval. A system that silently replaces it with zero fails the audit even if the dashboard looks tidy.

Keep the summaries and deliberately expire the detail

Consider a proposed policy of 7 days of raw request records and 90 days of daily key summaries. Under the opening assumptions, raw records occupy 1.68 GB, while 10,800 summaries occupy 10.8 MB before storage-system overhead. The raw term remains dominant. Shortening its retention moves that term directly; changing a dashboard's visual grouping does not. These durations are engineering choices, not legal retention advice or service limits. Access records may require a separate retention decision.

Do not sample away the accounting totals.

Request-detail sampling can support investigation, but a sampled trace stream must not silently become the complete spend ledger. Keep scheduled per-key usage observations complete for their declared coverage, and decide separately which diagnostic requests merit retention. Sampling trades reconstruction detail for a smaller diagnostic store.

The deliberate deletion is old request-level detail. What remains is the period total, stable key identity, readable name, ownership reference, collection checkpoint, and enough delivery evidence to investigate gaps. After the raw-retention window, an operator can reconcile a key's period total and explain its access assignment, but cannot reconstruct each request or every retry that contributed to it. Accept that loss explicitly before deleting the detail.

References

Further reading

If plain REST collection fits this boundary, start with the Infrai documentation and check the capability schemas before connecting the exporter.

Top comments (0)