Documentation

Everything you need to integrate UsageBox into your product—from authentication to billing-grade usage metering.

Getting Started

UsageBox is an independent usage metering API. It records usage events, makes retries idempotent, handles late events, preserves raw history, and produces monthly rollups for the billing system you choose. Use this guide to learn the building blocks and wire the API into your stack in minutes.

Quickstart: your first event in 5 minutes

The minimum viable integration is a meter, an API key, and one HTTP request. You can set up products, plans, and customers later.

  1. Create a meter — the unit you want to track (API requests, tokens, gigabytes). The quick templates take one click.
  2. Create an API key — after creating it you get a personalized version of the command below, pre-filled with your real ingest keys.
  3. Send a usage event from your terminal or server:
    curl -X POST https://api.usagebox.com/api/v1/usage \
      -H 'x-api-key: YOUR_API_KEY' \
      -H "Idempotency-Key: $(uuidgen)" \
      -H 'Content-Type: application/json' \
      -d '[{
        "value": 42
      }]'
    A 200 with "processed": 1 means the event was recorded. Reuse the sameIdempotency-Key if the request needs a retry.
  4. Watch it land — aggregated usage appears per meter and month within about a minute.
subscription, product_item, and meter values are ingest keysfrom your catalog. They may be omitted for a one-resource starter account; if a supplied key does not resolve, the response explains the skip in skipped_details.

Core Concepts

Projects

Group your resources by environment or product line. Projects let you isolate data, credentials, and configuration.

Products

Represent the services you sell. Each product can expose multiple plans that define how customers are billed.

Plans

Attach commercial configuration to a product. Plans group product items and charges so usage can resolve to the correct metering context.

Meters

Capture the raw usage signals you want to bill on—API calls, seats, bandwidth, or any measurable unit.

Customers

Store account details for the companies or users whose usage you meter. Customers can hold multiple subscriptions.

Subscriptions

Connect customers to a plan. Subscriptions define the lifecycle interval and context used to resolve incoming usage events.

Usage Events

Send granular events through the API so UsageBox can resolve them to the correct subscription, product item, meter, and charge, then aggregate the quantity.

API Keys

Authenticate requests to the UsageBox API. Rotate keys per environment and restrict them to the projects they serve.

API Overview

UsageBox exposes a RESTful API. All requests are scoped to the active project and use JSON payloads.

https://api.usagebox.com/api/v1/

Authentication

Create an API key in the dashboard and send it as the x-api-key header on every request:

x-api-key: your-api-key

Two other credentials exist and are easy to confuse with this one. Authorization: Bearer … carries a Firebase ID token and is what the web dashboard uses — an API key sent this way will fail. And an X-RapidAPI-Key works only at the RapidAPI gateway, never against this origin; call through the gateway and it handles authentication for you.

Common Workflows

Define the product, plan, item, meter, and charge context that incoming usage should resolve against.

  • Create a product

    POST /api/v1/products with a name and reference code. Products act as the parent container for plans.

  • Attach one or more plans

    Use POST /api/v1/plans to group the product configuration used by subscriptions and usage resolution.

  • Map included features

    Attach the product items, meters, and charges your usage events should resolve against.

curl -X POST https://api.usagebox.com/api/v1/products \
  -H 'x-api-key: <your_api_key>' \
  -H 'Content-Type: application/json' \
  -d '{ "name": "Pro API", "description": "Metered REST API" }'

Track consumption in real time by wiring your application telemetry to UsageBox meters.

  • Define meters for each billable signal

    Create meters with POST /api/v1/meters, specifying unit names, aggregation, and the products they belong to.

  • Send usage from your app servers

    POST /api/v1/usage with batches of events. Each event requires a value; subscription, product item, and meter ingest keys are optional when the account has one safe candidate.

  • Validate metering results

    Use GET /api/v1/usage/rollups (or GET /api/v1/account_activity, or the dashboard) to confirm events resolved correctly and the expected quantities were aggregated.

curl -X POST https://api.usagebox.com/api/v1/usage \
  -H 'x-api-key: <your_api_key>' \
  -H "Idempotency-Key: $(uuidgen)" \
  -H 'Content-Type: application/json' \
  -d '[{ "value": 150 }]'

Provision customers, activate subscriptions, and preserve the lifecycle context used to attribute usage over time.

  • Create or import customers

    POST /api/v1/customers with the identifiers you use in your product (corporate ID, domain, or UUID).

  • Start subscriptions on a plan

    POST /api/v1/subscriptions to connect a customer, plan, and optional trial or contract metadata.

  • Automate renewals and pauses

    PUT /api/v1/subscriptions/{id} to change status without losing historical usage.

curl -X POST https://api.usagebox.com/api/v1/subscriptions \
  -H 'x-api-key: <your_api_key>' \
  -H 'Content-Type: application/json' \
  -d '{
    "customer_account_id": "<customer id from POST /api/v1/customers>",
    "plan_id": "<plan id from GET /api/v1/plans>"
  }'

Key API Endpoints

EndpointMethodsDescription
/api/v1/projectsGET, POST, PUTFetch your projects and select an active project.
/api/v1/productsGET, POST, PUT, DELETEList and create products in the active project.
/api/v1/plansGET, POST, PUT, DELETEManage plans and pricing tiers linked to products.
/api/v1/metersGET, POST, PUT, DELETECreate meters and inspect meter configuration.
/api/v1/customersGET, POST, PUT, DELETECreate customers and fetch their billing profile.
/api/v1/subscriptionsGET, POST, PUT, DELETEStart, update, or view subscription lifecycle state.
/api/v1/usageGET, POSTSubmit usage events, and read back recent raw events.
/api/v1/usage/rollupsGETMonthly aggregated usage per meter, as the pipeline computed it.
/api/v1/api_keysGET, POST, PATCH, DELETERotate API credentials and manage access.
/api/v1/account_activityGETInspect account activity, charges, and recorded events.

Send usage from your language

There is no SDK to install. Ingest is one POST with a JSON array, so these are complete — copy one, set UBX_API_KEY, and you are metering.

Node.js
const res = await fetch('https://api.usagebox.com/api/v1/usage', {
  method: 'POST',
  headers: {
    'x-api-key': process.env.UBX_API_KEY,
    'Idempotency-Key': crypto.randomUUID(),
    'Content-Type': 'application/json'
  },
  body: JSON.stringify([{ meter: 'meter.api-requests', value: 1 }])
})
console.log(await res.json())
Python
import os, uuid, requests

res = requests.post(
    "https://api.usagebox.com/api/v1/usage",
    headers={
        "x-api-key": os.environ["UBX_API_KEY"],
        "Idempotency-Key": str(uuid.uuid4()),
    },
    json=[{"meter": "meter.api-requests", "value": 1}],
)
print(res.json())
Go
body := `[{"meter":"meter.api-requests","value":1}]`
req, _ := http.NewRequest("POST",
    "https://api.usagebox.com/api/v1/usage", strings.NewReader(body))
req.Header.Set("x-api-key", os.Getenv("UBX_API_KEY"))
req.Header.Set("Idempotency-Key", uuid.NewString())
req.Header.Set("Content-Type", "application/json")

res, err := http.DefaultClient.Do(req)
PHP
$ch = curl_init('https://api.usagebox.com/api/v1/usage');
curl_setopt_array($ch, [
  CURLOPT_POST => true,
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_HTTPHEADER => [
    'x-api-key: ' . getenv('UBX_API_KEY'),
    'Idempotency-Key: ' . bin2hex(random_bytes(16)),
    'Content-Type: application/json',
  ],
  CURLOPT_POSTFIELDS => json_encode([['meter' => 'meter.api-requests', 'value' => 1]]),
]);
echo curl_exec($ch);

Need Help?

Documentation evolves as the platform does. Reach out if you have questions or want to share feedback.

Ready to get started?

Create an account, generate an API key, and start metering usage today.