Constaia
Endpoints

Balance and usage

Reference for GET /v1/balance and GET /v1/usage: pack credits, free tier, reservations and daily usage by document type, with examples.

Esta página ainda não está traduzida para o seu idioma. Mostramos a versão em inglês.

Two read-only endpoints to find out how many credits you have left and what you spent them on. Neither spends credits.

Method and routeWhat it does
GET /v1/balanceCurrent account balance.
GET /v1/usageUsage aggregated by day, document type and endpoint.

Prices and charging rules in Credits and billing and on the pricing page.

GET /v1/balance

curl https://api.constaia.com/v1/balance \
  -H "Authorization: Bearer $CONSTAIA_API_KEY"
Response
{
  "object": "balance",
  "credits_available": 1000,
  "credits_reserved": 2,
  "free_tier_remaining": 118.4,
  "credits_spendable": 1118.4,
  "free_tier_resets_at": "2026-10-01T00:00:00.000Z"
}
FieldDescription
credits_availableCredits from purchased packs that you can spend. It does not include the free tier.
credits_reservedCredits reserved by analyses in progress. They are charged when the analysis finishes according to the real page count, and released if it fails.
free_tier_remainingWhat is left of this month's free tier (150 credits per month).
credits_spendableWhat you can spend right now: credits_available + free_tier_remaining.
free_tier_resets_atWhen the free tier renews: the 1st of each month at 00:00 UTC. Unused credits do not roll over.

What you can spend right now is credits_spendable (credits_available + free_tier_remaining). The free tier is consumed first and then the packs, oldest first. Values can have decimals because classify costs 0.2 credits.

The balance belongs to the account: it returns the same with a test key as with a live key. Test keys do not spend credits.

If the balance drops below the threshold you set in the dashboard, you receive the credits.low webhook (live mode only, once until you top up).

GET /v1/usage

ParameterFormatDefault
fromYYYY-MM-DD29 days ago (30 days counting today).
toYYYY-MM-DDToday.

A wrong date format returns 422 invalid_parameter. Usage covers only the key's mode: with a test key you see test usage; with a live key, real usage.

curl -G https://api.constaia.com/v1/usage \
  -H "Authorization: Bearer $CONSTAIA_API_KEY" \
  -d from=2026-09-01 -d to=2026-09-30
Response
{
  "object": "usage",
  "from": "2026-09-01",
  "to": "2026-09-30",
  "livemode": true,
  "data": [
    { "date": "2026-09-28", "type": "es_dni", "kind": "analysis", "livemode": true, "count": 12, "pages": 14, "credits": 12 },
    { "date": "2026-09-28", "type": "invoice", "kind": "classification", "livemode": true, "count": 5, "pages": 7, "credits": 1 },
    { "date": "2026-09-29", "type": "payment_receipt", "kind": "analysis", "livemode": true, "count": 3, "pages": 3, "credits": 3 }
  ],
  "totals": { "count": 20, "pages": 24, "credits": 16 }
}
FieldDescription
from, toRange applied.
livemodeMode of the key used.
data[]One row per day, document type and kind, sorted by date.
data[].dateDay (YYYY-MM-DD).
data[].typeDetected document type.
data[].kindanalysis (analyze and batches) or classification (classify).
data[].countNumber of documents.
data[].pagesPages processed.
data[].creditsCredits charged. 0 in test mode.
totalsSum of count, pages and credits over the range.

Failed analyses are not charged. Details in Credits and billing.

Example: check the balance before a batch

check-balance.ts
import { Constaia } from "@constaia/sdk";

const constaia = new Constaia();

const balance = await constaia.balance();
const spendable = balance.credits_available + balance.free_tier_remaining;
const needed = 80; // e.g. 80 documents of up to 2 pages

if (constaia.livemode && spendable < needed) {
  throw new Error(`Not enough credits: ${spendable} available, ${needed} needed`);
}

const usage = await constaia.usage({ from: "2026-09-01", to: "2026-09-30" });
console.log(`September: ${usage.totals.count} documents, ${usage.totals.credits} credits`);

Next steps

Nesta página