Overview

The Pricing API is the single source of truth for compute-usage cost calculation on the Allternit platform. Cost is always derived server-side from the measured quantity, unit, and resource type reported by the ACU (computer-use) Python gateway. The gateway posts usage events to this surface, and the platform computes computed_cost_cents from the canonical rate card in cmd/allternit-api/src/pricing.rs. Never trust a client-supplied cost. Pricing and margin logic lives in exactly one place so it can change without touching every caller.

Base URL

For local development:

Authentication

Pricing routes are internal-only and gated by service-to-service authentication, not the standard Clerk bearer-token middleware. The caller must supply a shared secret in the x-allternit-internal-token header. *In local development, a localhost-only bypass is allowed when no internal token is configured. In production, missing or invalid tokens fail closed with 401 Unauthorized. See Authentication for platform authentication details.

Rate card

Costs are computed in cents per unit. The default rates are: These defaults are placeholders pending final margin decisions. Override any rate at runtime with an environment variable:
For example:
The environment key is derived from the resource_type:unit pair by upper-casing the string and replacing non-alphanumeric characters with underscores. Unknown resource_type:unit pairs price at zero rather than erroring, so unrecognized meters do not block ingestion or silently invent a price.

Endpoints

Ingest a usage event

Records one usage event. The request body carries the measured quantity and metadata; the response returns the cost in cents computed by the platform. The call is idempotent on idempotency_key — retrying a delivery with the same key is a no-op, not a double charge.

Request body

Example request

Example response

The cost is rounded to the nearest cent: 300 seconds × 0.02 cents/second = 6 cents.

Response fields

Error codes

Idempotency

The ingestion route is idempotent on idempotency_key. If two requests arrive with the same key, only the first is inserted; the second returns the same computed_cost_cents without creating a duplicate row. Always supply a stable idempotency_key when retrying network failures.