Advanced: fees

Preview a calculation chain

Runs an amount through a calculation chain and returns the result with a step-by-step ledger.

POST /calculation-chains/preview

Runs an amount through a calculation chain and returns the result with a step-by-step ledger. Nothing is saved.

  • Pass either calculation_chain_id (a saved chain you can read; 404 otherwise) or an inline expanded calculation_chain, which wins if both are given.
  • Amounts are rounded half-up to 8 decimal places after every step.
  • If a step cannot compute, the response is still 200: final is null, and the failing ledger entry carries an error.
  • With to_home: true the result is also converted into your account's base currency (USD unless you changed it); the chain's own output_auto does not change this. An API key must not send home_currency (422).
  • 422 when your base currency is not in the official catalog; 503 when your account settings cannot be read right now.

Usage

NameDescription
AuthenticationAPI key required
Credit costFree

Request body

FieldTypeRequiredDescription
start_amountnumber or stringNoAmount to run through the chain, as an exact decimal. Default: 100.
start_currencystringYesCurrency code of start_amount, e.g. USD.
calculation_chainobject or nullNoInline fully expanded chain, in the same shape as for validation. Takes precedence over calculation_chain_id.
calculation_chain_idinteger or nullNoID of a saved chain visible to you. Required when calculation_chain is not given.
to_homebooleanNoConvert the final amount into your home currency: your account's base currency (USD by default). Off by default, when the result stays in the chain's final currency. Default: false.
home_currencyobject or nullNoNot available to your API key: leave it out (422 otherwise).

Responses

StatusDescriptionSchema
200Successful ResponseEnvelope_PreviewOut_
401Authentication is missing or invalidErrorEnvelope
403The credential is valid but not allowed to call this operationErrorEnvelope
404The requested resource does not existErrorEnvelope
422A parameter or the request body is invalidErrorEnvelope
429Too many requests to this endpoint; retry laterErrorEnvelope
503The service is temporarily unavailable; retry laterErrorEnvelope

Models

CreditMeta

Credit accounting for a billable request.

FieldTypeRequiredDescription
costintegerYesCredits this request costs.
remainingintegerYesEstimated credit balance left after this request. A hint rather than a ledger: concurrent requests can make it slightly off.

Envelope_PreviewOut_

FieldTypeRequiredDescription
dataPreviewOutYesThe endpoint payload.
metaMetaYesRequest metadata.

ErrorBody

Details of a failed request.

FieldTypeRequiredDescription
codestringYesStable machine-readable error code. Branch on this value, not on message.
messagestringYesHuman-readable explanation. The wording may change.
detailsobject or nullNoOptional structured context, such as the list of validation errors or, for credit_insufficient, the required and remaining credits.

ErrorEnvelope

Error response: the error in error plus request metadata in meta.

FieldTypeRequiredDescription
errorErrorBodyYesWhat went wrong.
metaMetaYesRequest metadata.

Meta

Request metadata included in every enveloped response.

FieldTypeRequiredDescription
request_idstringYesUnique identifier of this request, identical to the X-Request-ID response header. Quote it when contacting support.
billableboolean or nullNoWhether the request is billed in credits. Present only on metered endpoints; false means the request is free, for example because it costs nothing or your subscription covers it.
creditCreditMeta or nullNoCost of the request and your estimated remaining balance. Present only when billable is true.
pagePageMeta or nullNoPaging state. Present only on a response that lists a page.

PageMeta

Where a paged list stands after this page.

FieldTypeRequiredDescription
limitintegerYesPage size actually applied to this request.
has_nextbooleanYesWhether another page follows.
next_cursorstring or nullYesPass it back unchanged as cursor to get the next page; null once the list is complete.

PreviewOut

Result of running an amount through a calculation chain.

FieldTypeRequiredDescription
finalstring or nullYesFinal amount as a decimal string (8 decimal places); null if a step failed.
final_currencystring or nullYesCurrency code of final; null if a step failed.
start_amountstringYesThe starting amount, as a decimal string.
start_currencystringYesCurrency code of the starting amount.
expressionstringYesReadable arithmetic of the run, for display only; ends in = ERROR when a step failed. Use ledger for processing.
ledgerarray of objectYesOne entry per executed step, plus the conversion into your home currency when to_home is set: position, kind, operator_id, operator_name, summary, input_amount, input_currency, output_amount, output_currency, detail (step specifics such as group member results) and error (set when the step failed). Execution stops at the first failed step.

Download the public OpenAPI schema