Skip to content

Cost Control

Apiway provides budget guards for both sides of the API equation — protecting producer infrastructure from overconsumption and consumer budgets from runaway costs.

GuardProtectsLimits
Producer RU MeteringBackend infrastructureMore usage = more revenue, but limited by capacity
Consumer Cost GuardFinancial exposureMore usage = more cost, limited by budget

Protects your backend from being overwhelmed by a single consumer. Each subscription has an RU quota enforced at the gateway.

When a subscription hits its quota:

  1. Soft alert — At the configured threshold (e.g., 80%), a governance event fires. The consumer is notified. Calls continue.
  2. Hard stop — At 100%, the gateway returns 402 Payment Required. Calls are blocked until the next billing period or quota is increased.
  3. SLA upgrade — After 3+ breaches in 30 days, Apiway recommends a higher SLA tier.

Consumer Side — Consumption Budget Guard

Section titled “Consumer Side — Consumption Budget Guard”

Protects your budget from runaway outbound calls to consumed APIs. A deployment bug on a Friday evening should cost the daily budget — not the quarterly forecast.

Each consumed API subscription can have a budget ceiling:

FieldDescription
ConsumptionBudgetMaximum spend in the billing period
ConsumptionBudgetPeriodBudget reset cycle (Daily, Monthly, etc.)
ConsumptionBudgetAlertThresholdPercentage for soft warning
ConsumptionBudgetEnforceHardStopWhether to block calls at ceiling
HeaderDescription
X-Budget-LimitBudget ceiling
X-Budget-RemainingRemaining budget
X-Budget-PeriodBudget period

For APIs that call other APIs (the aggregator pattern), the gateway performs a pre-flight budget check on dependencies before forwarding the request:

  1. Check the dependency’s rate limit headroom
  2. Check the dependency’s RU budget headroom
  3. If either is insufficient, fail the request early — before consuming the caller’s resources

This prevents cascading failures where a downstream budget exhaustion wastes upstream resources.

Independent of RU metering, the gateway enforces per-subscription rate limits:

HeaderDescription
RateLimit-LimitMaximum requests per window
RateLimit-RemainingRequests remaining
RateLimit-ResetSeconds until the window resets
Retry-AfterSeconds to wait (on 429 response)

Rate limits use a fixed-window algorithm with in-memory tracking for minimal latency.

All budget and rate limit events trigger governance flows:

EventResponse
Rate limit breachedInformational — logged and reported
Budget threshold reachedNotification — consumer alerted
Budget exhaustedHard stop — calls blocked
SLA upgrade recommendedRecommendation — governance flow initiated