REST ReferenceUsage, Keys & Billing

Usage, Keys & Billing

Monitor usage and quota, cap overage spend, rotate API keys and open the Stripe billing portal from the Air Pixels Data API.

curl https://api.airpixels.com/v1/usage \
  -H "Authorization: Bearer $AP_KEY"
{
  "data": {
    "plan": "builder",
    "plan_name": "Builder",
    "status": "active",
    "month": "2026-11-01",
    "calls_used": 8,
    "calls_included": 25000,
    "calls_remaining": 24992,
    "hard_cap": false,
    "overage_calls": 0,
    "overage_usd_per_call": 0.004,
    "estimated_overage_usd": 0,
    "spending_cap_usd": null,
    "resets_at": "2026-12-01T00:00:00Z",
    "rate_limit": 5,
    "rate_window_seconds": 1,
    "datasets": ["hardware_index", "field_performance", "service_rates"],
    "hardware_index_fields": "full",
    "key_prefix": "ap_live_••••"
  },
  "meta": {
    "plan": "builder",
    "calls_used": 8,
    "calls_included": 25000,
    "attribution": "Data: Air Pixels (airpixels.com)"
  }
}
curl -X POST https://api.airpixels.com/v1/usage/spending-cap \
  -H "Authorization: Bearer $AP_KEY" \
  -H "Content-Type: application/json" \
  -d '{"max_overage_usd": 25}'
curl -X POST https://api.airpixels.com/v1/keys/rotate \
  -H "Authorization: Bearer $AP_KEY"
{
  "data": {
    "api_key": "ap_live_••••",
    "key_prefix": "ap_live_••••",
    "created_at": "2026-11-06T19:37:16.410Z",
    "revoked_key_prefix": "ap_live_••••"
  },
  "meta": {
    "plan": "builder",
    "calls_used": 10,
    "calls_included": 25000,
    "attribution": "Data: Air Pixels (airpixels.com)"
  }
}
curl -X POST https://api.airpixels.com/v1/billing-portal \
  -H "Authorization: Bearer $AP_KEY"
{
  "data": {
    "url": "https://billing.stripe.com/p/session/..."
  }
}

Read your quota, set a spend cap, rotate a leaked key and open the billing portal, all from the API. These endpoints are free and never counted against your quota, so you can automate them in monitoring scripts and CI without touching your metered usage.

Send your key as a bearer token on every request. See Authentication for key formats and error behavior.

Endpoints

MethodPathWhat it doesPlan
GET/v1/usageCurrent month's usage, quota, rate limit and plan stateAll plans
POST/v1/usage/spending-capSet or remove a maximum overage budgetBuilder, Operator
POST/v1/keys/rotateIssue a new key and revoke the calling keyAll plans
POST/v1/billing-portalReturn a single-use Stripe Billing Portal linkBuilder, Operator

POST /keys/rotate and POST /billing-portal take no request body. All four endpoints work in every account status, including past-due and canceled accounts.

Check usage

GET /v1/usage returns your quota and consumption for the current calendar month, plus the rate limit that applies to the key making the call.

The data object contains your account state:

FieldTypeDescription
planstringPlan slug, for example builder or operator.
plan_namestringDisplay name of the plan.
statusstringAccount status: active, past due or canceled. Metered calls are rejected on past-due and canceled accounts, but this endpoint keeps working.
monthstringFirst day of the quota month in UTC, for example 2026-11-01.
calls_usedintegerMetered calls made this month by every key on the account.
calls_includedinteger or nullCalls included in your plan this month. null on unlimited contracts.
calls_remaininginteger or nullCalls left before overage begins. null on unlimited contracts.
hard_capbooleanWhether the plan stops at included calls. false means overage is billed.
overage_callsintegerCalls made beyond calls_included this month.
overage_usd_per_callnumberPrice per overage call on your plan. 0 when the plan does not bill overage.
estimated_overage_usdnumberoverage_calls times overage_usd_per_call, rounded to cents. Your invoice is authoritative.
spending_cap_usdnumber or nullCurrent maximum overage budget in USD. null when no cap is set.
resets_atstringISO 8601 timestamp of the next quota reset.
rate_limitintegerRequests allowed per window for the calling key.
rate_window_secondsintegerLength of the rate limit window in seconds.
datasetsarray of stringsDataset identifiers your plan can query.
hardware_index_fieldsstringField access level on the hardware index dataset, for example full.
key_prefixstringPrefix of the key that made this call, for log correlation.

Quota is counted per account and shared by all of that account's keys. It runs on the calendar month in UTC, not your Stripe billing period, and resets at 00:00 UTC on the 1st. resets_at gives the exact moment. For included calls, overage prices and rate limit windows per plan, see Plans and limits.

Set a spending cap

POST /v1/usage/spending-cap sets a maximum overage budget so a runaway script cannot bill without limit. Builder and Operator keep serving requests past the included calls and bill the overage; this endpoint puts a ceiling on that spend.

The request body has one field:

FieldTypeDescription
max_overage_usdnumber or nullMaximum overage spend in USD, from 0 to 1,000,000. Send null to remove the cap.

The response is your /v1/usage object with spending_cap_usd set to the new value. The cap only applies on Builder and Operator; other plans get 403 not_in_plan.

The cap is converted to a call count with integer division, so requests stop once your included calls plus the overage your cap allows are used:

calls allowed = calls_included + floor(max_overage_usd / overage_usd_per_call)

On Builder, included calls are 25,000 and overage is $0.004 per call. A $25 cap therefore stops at 25,000 plus floor(25 / 0.004), which is 6,250 overage calls:

25,000 + 6,250 = 31,250 calls

A spending cap stops billable calls. Once the limit is reached this month, metered requests return 429 quota_exceeded instead of being served. The cap does not send an alert and keep serving, so size it as the total you are willing to spend, not a warning threshold.

Rotate a key

POST /v1/keys/rotate issues a new API key and revokes the key that made the call, immediately. Rotation is free and takes no request body.

The data object contains:

FieldTypeDescription
api_keystringThe new key, shown only in this response. Store it before the response is lost.
key_prefixstringPrefix of the new key, for logging and identification.
created_atstringISO 8601 timestamp when the new key was created.
revoked_key_prefixstringPrefix of the key that was revoked by this call.

Rotation is immediate and irreversible. Any process still using the old key starts getting 401 on its next request, so deploy the new key before or at the same time as you rotate. For key handling practices, see Authentication.

Open the billing portal

POST /v1/billing-portal returns a single-use Stripe Billing Portal link, so you can update a card, download invoices, change billing details or cancel from your own tooling. It is free and takes no request body.

The link is in data.url. Open it in a browser within a few minutes, before the session expires. It is available on Stripe-billed plans (Builder and Operator); Explorer and contract accounts get 403 not_in_plan and manage billing through their contract.

Endpoints that always work

Usage, key rotation and the billing portal keep working in every account status, including past-due and canceled accounts. When a past-due account crosses its 7-day grace period, metered calls start returning 402 subscription_inactive, but these endpoints stay available so you can read your quota, rotate a key and open the portal to fix billing. A canceled account gets 402 on metered calls until it is reactivated.

The free endpoints below are never counted against your quota, and rejected requests (any 400, 401, 402, 403 and both kinds of 429) are not counted either:

GET  /v1/usage
POST /v1/usage/spending-cap
POST /v1/keys/rotate
POST /v1/billing-portal
GET  /v1/openapi.json
GET  /v1/changelog
GET  /v1

CORS preflights and MCP initialize, ping, tools/list and notifications are also free.

Errors

StatusCodeMeaningFix
400bad_requestThe spending cap value is out of range or not a number.Send max_overage_usd between 0 and 1,000,000, or null to remove the cap.
401missing_key / invalid_key / key_revokedThe bearer token is missing, malformed or was revoked (for example by rotation).Send a current key in the Authorization header. If you just rotated, use the new api_key.
402subscription_inactiveThe account is past due beyond its 7-day grace period, or canceled.Open the billing portal and settle the invoice. These account endpoints keep working during 402.
403not_in_planThe plan does not include spending caps or the billing portal.Set caps on Builder or Operator; contract accounts manage billing directly.
429rate_limitedThe key exceeded its rate limit window.Back off and retry after the window; check rate_limit and rate_window_seconds from /v1/usage.
429quota_exceededThe account used its included calls plus the spend-cap allowance this month.Raise or remove the spending cap, or wait for resets_at.

Rate limits and quota are documented in Plans and limits. For the shape of successful responses across the API, see the REST overview.