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 expandedcalculation_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:
finalisnull, and the failing ledger entry carries anerror. - With
to_home: truethe result is also converted into your account's base currency (USD unless you changed it); the chain's ownoutput_autodoes not change this. An API key must not sendhome_currency(422). - 422 when your base currency is not in the official catalog; 503 when your account settings cannot be read right now.
Usage
| Name | Description |
|---|---|
| Authentication | API key required |
| Credit cost | Free |
Request body
| Field | Type | Required | Description |
|---|---|---|---|
start_amount | number or string | No | Amount to run through the chain, as an exact decimal. Default: 100. |
start_currency | string | Yes | Currency code of start_amount, e.g. USD. |
calculation_chain | object or null | No | Inline fully expanded chain, in the same shape as for validation. Takes precedence over calculation_chain_id. |
calculation_chain_id | integer or null | No | ID of a saved chain visible to you. Required when calculation_chain is not given. |
to_home | boolean | No | Convert 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_currency | object or null | No | Not available to your API key: leave it out (422 otherwise). |
Responses
| Status | Description | Schema |
|---|---|---|
200 | Successful Response | Envelope_PreviewOut_ |
401 | Authentication is missing or invalid | ErrorEnvelope |
403 | The credential is valid but not allowed to call this operation | ErrorEnvelope |
404 | The requested resource does not exist | ErrorEnvelope |
422 | A parameter or the request body is invalid | ErrorEnvelope |
429 | Too many requests to this endpoint; retry later | ErrorEnvelope |
503 | The service is temporarily unavailable; retry later | ErrorEnvelope |
Models
CreditMeta
Credit accounting for a billable request.
| Field | Type | Required | Description |
|---|---|---|---|
cost | integer | Yes | Credits this request costs. |
remaining | integer | Yes | Estimated credit balance left after this request. A hint rather than a ledger: concurrent requests can make it slightly off. |
Envelope_PreviewOut_
| Field | Type | Required | Description |
|---|---|---|---|
data | PreviewOut | Yes | The endpoint payload. |
meta | Meta | Yes | Request metadata. |
ErrorBody
Details of a failed request.
| Field | Type | Required | Description |
|---|---|---|---|
code | string | Yes | Stable machine-readable error code. Branch on this value, not on message. |
message | string | Yes | Human-readable explanation. The wording may change. |
details | object or null | No | Optional 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.
Meta
Request metadata included in every enveloped response.
| Field | Type | Required | Description |
|---|---|---|---|
request_id | string | Yes | Unique identifier of this request, identical to the X-Request-ID response header. Quote it when contacting support. |
billable | boolean or null | No | Whether 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. |
credit | CreditMeta or null | No | Cost of the request and your estimated remaining balance. Present only when billable is true. |
page | PageMeta or null | No | Paging state. Present only on a response that lists a page. |
PageMeta
Where a paged list stands after this page.
| Field | Type | Required | Description |
|---|---|---|---|
limit | integer | Yes | Page size actually applied to this request. |
has_next | boolean | Yes | Whether another page follows. |
next_cursor | string or null | Yes | Pass 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.
| Field | Type | Required | Description |
|---|---|---|---|
final | string or null | Yes | Final amount as a decimal string (8 decimal places); null if a step failed. |
final_currency | string or null | Yes | Currency code of final; null if a step failed. |
start_amount | string | Yes | The starting amount, as a decimal string. |
start_currency | string | Yes | Currency code of the starting amount. |
expression | string | Yes | Readable arithmetic of the run, for display only; ends in = ERROR when a step failed. Use ledger for processing. |
ledger | array of object | Yes | One 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. |