Core concepts

Wallet and billing

How jobs are paid, refunded and recorded.

API jobs are paid from a USD wallet. It is separate from the credits and subscription you use in the Astorie app: app credits can't pay for API jobs, and wallet funds can't be spent in the app.

Adding funds

Top up in the console under Billing. You can add between $5 and $1,000 at a time. Funds appear once the payment is confirmed.

How a job is paid

  1. Accepted. The job's price is moved from available_amount to reserved_amount. Other jobs can't spend it.
  2. Succeeded. The price is charged. If the final cost is lower, the difference goes back to available.
  3. Failed, or canceled before it started. The whole amount goes back to available.

An example, starting with $10.00 and a job priced at $1.00:

AfterAvailableReservedCharged
The job is accepted$9.00$1.00$0.00
It succeeds$9.00$0.00$1.00
Or it fails$10.00$0.00$0.00
Or it is canceled after the provider accepted it$9.00$0.00$1.00

Checking your balance

import { Astorie } from "@astorie/client";

const client = new Astorie();

const balance = await client.getBalance();
console.log(balance.available_amount, balance.reserved_amount);
FieldMeaning
available_amountWhat new jobs can spend. The only spendable number.
reserved_amountSet aside for jobs that haven't settled yet.
total_usable_amountAvailable plus reserved. Don't show this as spendable.
debt_amountMoney owed. While it is above zero, new jobs get 402 account_in_debt.

Needs the wallet:read scope.

Billing on a job

Each job has a billing object:

FieldMeaning
statereserved while running, then settled (charged) or released (refunded).
accepted_max_charge_amountThe price set aside when the job was accepted.
reserved_amountHow much of that is still set aside.
charged_amountWhat you paid. Zero until the job settles.
released_amountWhat went back to your wallet.
quote_idThe quote used, or null.

Your max_charge_amount ceiling isn't stored in billing. It only decides whether the job is accepted.

The ledger

GET /v1/ledger lists every movement of money in order: top-ups (fund), money set aside for a job (reserve), charges (capture) and refunds (release). Use it to reconcile your own records. See List ledger entries.