Tolvi AI
9 operations in the Tolvi API, version 1. Paths are relative to https://api.tolvi.co.uk. Every amount is integer pence.
Get the firm’s token balance, expiry and this month’s use
GET/api/v1/ai/balance
- Scopes
engagements:read
Responses
200 OK, application/json
Body: object (AiBalance).
| Field | Type | Description |
|---|---|---|
balancerequired | integer | Tokens available now (unexpired). |
heldrequired | integer | Held for calls in progress. |
spendablerequired | integer | |
capacityrequired | integer | Original size of the live lots (for the 20% / 5% alerts). |
levelrequired | string (AiBalanceLevel) | One of: |
nextExpiryrequired | object (AiTokenExpiry)nullable | |
nextExpiry.tokensrequired | integer | |
nextExpiry.onrequired | string (date-time) | |
usedThisMonthrequired | integer | |
myUsedThisMonthrequired | integer | |
myLimitrequired | integernullable | |
enabledrequired | boolean |
Errors: 400 Bad request, 401 Unauthorised, 403 Forbidden, 429 Too many requests, as problem details (application/problem+json).
Token use by month, person, feature, engagement or model, with recent ledger entries
GET/api/v1/ai/usage
- Scopes
engagements:read
Parameters
| Name | In | Type | Description |
|---|---|---|---|
groupBy | query | string (AiUsageGroupBy) | One of: |
from | query | string (date) | |
to | query | string (date) |
Responses
200 OK, application/json
Body: object (AiUsage).
| Field | Type | Description |
|---|---|---|
groupByrequired | string (AiUsageGroupBy) | One of: |
groupsrequired | array of AiUsageGroup | |
groups[].keyrequired | string | |
groups[].labelrequired | string | |
groups[].tokensrequired | integer | Tolvi AI tokens charged. |
groups[].callsrequired | integer | |
groups[].inputTokensrequired | integer | |
groups[].outputTokensrequired | integer | |
groups[].providerCostPencerequired | integer | Provider cost in pence (at the configured exchange rate). |
totalrequired | integer | |
recentrequired | array of AiLedgerEntry | The 50 most recent ledger entries. |
recent[].idrequired | string | |
recent[].atrequired | string (date-time) | |
recent[].typerequired | string (AiLedgerEntryType) | One of: |
recent[].tokensrequired | integer | Positive for credits, negative for usage and expiry. |
recent[].userIdrequired | string (uuid)nullable | |
recent[].engagementIdrequired | string (uuid)nullable | |
recent[].featurerequired | stringnullable | |
recent[].modelrequired | stringnullable |
Errors: 400 Bad request, 401 Unauthorised, 403 Forbidden, 429 Too many requests, as problem details (application/problem+json).
List the token packs and prices (net, VAT, gross in pence)
GET/api/v1/ai/packs
- Scopes
engagements:read
VAT is 0 and gross equals net while Tolvi is not VAT-registered (vatRegistered false).
Responses
200 OK, application/json
Body: object (AiPacks).
| Field | Type | Description |
|---|---|---|
versionrequired | string | |
currencyrequired | string | |
vatRegisteredrequired | boolean | Whether Tolvi charges VAT on its prices. False: no VAT is charged, so vatPence is 0 and grossPence is the net price. |
packsrequired | array of AiPack | |
packs[].idrequired | string (TokenPackId) | One of: |
packs[].namerequired | string | |
packs[].tokensrequired | integer | |
packs[].netPencerequired | integer | Net price in pence. |
packs[].vatPencerequired | integer | VAT in pence: 0 while Tolvi is not VAT-registered. |
packs[].grossPencerequired | integer | Net plus VAT, in pence (the net price while Tolvi is not VAT-registered). |
Errors: 400 Bad request, 401 Unauthorised, 403 Forbidden, 429 Too many requests, as problem details (application/problem+json).
Buy a token pack (Stripe Checkout)
POST/api/v1/ai/checkout
- Scopes
settings:adminandengagements:read- Access
- A signed-in Tolvi session only, never an API token.
Partners and admins (or admins only, per the firm’s AI settings). The tokens are credited when Stripe confirms payment.
Request body
Required. application/json: object (AiCheckoutRequest).
| Field | Type | Description |
|---|---|---|
packIdrequired | string (TokenPackId) | One of: |
Responses
200 OK, application/json
Body: object (AiCheckout).
| Field | Type | Description |
|---|---|---|
sessionIdrequired | string | |
urlrequired | string (uri) | Send the browser here (Stripe Checkout). |
packrequired | object (AiPack) | |
pack.idrequired | string (TokenPackId) | One of: |
pack.namerequired | string | |
pack.tokensrequired | integer | |
pack.netPencerequired | integer | Net price in pence. |
pack.vatPencerequired | integer | VAT in pence: 0 while Tolvi is not VAT-registered. |
pack.grossPencerequired | integer | Net plus VAT, in pence (the net price while Tolvi is not VAT-registered). |
Errors: 400 Bad request, 401 Unauthorised, 403 Forbidden, 429 Too many requests, as problem details (application/problem+json).
List recent AI suggestions
GET/api/v1/ai/suggestions
- Scopes
engagements:read
Parameters
| Name | In | Type | Description |
|---|---|---|---|
engagementId | query | string (uuid) |
Responses
200 OK, application/json
Body: array of AiSuggestion.
An AI draft. A person accepts (then applies it through the normal endpoints) or discards it.
| Field | Type | Description |
|---|---|---|
[].idrequired | string (uuid) | |
[].featurerequired | string (AiFeature) | One of: |
[].engagementIdrequired | string (uuid)nullable | |
[].sectionCoderequired | stringnullable | |
[].outputrequired | object | The feature’s structured output (see @tolvi/ai output schemas). |
[].tokensrequired | integer | Tolvi AI tokens charged. |
[].modelrequired | string | |
[].promptVersionrequired | string | |
[].statusrequired | string (AiSuggestionStatus) | One of: |
[].createdAtrequired | string (date-time) | |
[].decidedByrequired | string (uuid)nullable | |
[].decidedAtrequired | string (date-time)nullable | |
[].estimate | integer | The estimate shown before running. |
Errors: 400 Bad request, 401 Unauthorised, 403 Forbidden, 429 Too many requests, as problem details (application/problem+json).
Get an AI suggestion
GET/api/v1/ai/suggestions/{id}
- Scopes
engagements:read
Parameters
| Name | In | Type | Description |
|---|---|---|---|
idrequired | path | string (uuid) |
Responses
200 OK, application/json
Body: object (AiSuggestion).
An AI draft. A person accepts (then applies it through the normal endpoints) or discards it.
| Field | Type | Description |
|---|---|---|
idrequired | string (uuid) | |
featurerequired | string (AiFeature) | One of: |
engagementIdrequired | string (uuid)nullable | |
sectionCoderequired | stringnullable | |
outputrequired | object | The feature’s structured output (see @tolvi/ai output schemas). |
tokensrequired | integer | Tolvi AI tokens charged. |
modelrequired | string | |
promptVersionrequired | string | |
statusrequired | string (AiSuggestionStatus) | One of: |
createdAtrequired | string (date-time) | |
decidedByrequired | string (uuid)nullable | |
decidedAtrequired | string (date-time)nullable | |
estimate | integer | The estimate shown before running. |
Errors: 400 Bad request, 401 Unauthorised, 403 Forbidden, 404 Not found, 429 Too many requests, as problem details (application/problem+json).
Accept an AI suggestion
POST/api/v1/ai/suggestions/{id}/accept
- Scopes
engagements:writeandengagements:read
Records the decision; the person then applies it (e.g. saves the note) through the normal endpoints.
Parameters
| Name | In | Type | Description |
|---|---|---|---|
idrequired | path | string (uuid) |
Responses
200 OK, application/json
Body: object (AiSuggestion).
An AI draft. A person accepts (then applies it through the normal endpoints) or discards it.
The fields are as shown above.
Errors: 400 Bad request, 401 Unauthorised, 403 Forbidden, 404 Not found, 429 Too many requests, as problem details (application/problem+json).
Discard an AI suggestion
POST/api/v1/ai/suggestions/{id}/discard
- Scopes
engagements:writeandengagements:read
Parameters
| Name | In | Type | Description |
|---|---|---|---|
idrequired | path | string (uuid) |
Responses
200 OK, application/json
Body: object (AiSuggestion).
An AI draft. A person accepts (then applies it through the normal endpoints) or discards it.
The fields are as shown above.
Errors: 400 Bad request, 401 Unauthorised, 403 Forbidden, 404 Not found, 429 Too many requests, as problem details (application/problem+json).
Run a Tolvi AI feature
POST/api/v1/ai/{feature}
- Scopes
engagements:writeandengagements:read- Retries
- Send an
Idempotency-Keyto make retries safe.
Estimate → reserve → run → settle against the firm’s token ledger. Returns a suggestion (status proposed). With estimateOnly, returns the estimate instead (AiEstimate). 402 when the balance cannot cover the estimate; 403 when the feature is off or your monthly limit is used.
Parameters
| Name | In | Type | Description |
|---|---|---|---|
featurerequired | path | string (AiFeature) | One of: |
Idempotency-Key | header | string | A unique key (1-255 visible characters) to make retries safe. Replayed for 24 hours. 1 to 255 characters |
Request body
Required. application/json: object (AiRequest).
engagementId is required. explain_movements: sectionCode (and optionally accountCodes); review_assistant: optional sectionCode; check_evidence: evidenceId (and optionally the ticked account in accountCodes); ask_tolvi: question (and history).
| Field | Type | Description |
|---|---|---|
engagementIdrequired | string (uuid) | |
sectionCode | string | |
accountCodes | array of string | up to 200 items |
evidenceId | string (uuid) | |
question | string | up to 4000 characters |
history | array of AskHistoryTurn | up to 20 items |
history[].questionrequired | string | up to 4000 characters |
history[].answerrequired | string | up to 20000 characters |
estimateOnly | boolean | Only estimate the cost; nothing is reserved or run. |
Responses
200 OK, application/json
Body: one of: object (AiSuggestion), object (AiEstimate).
Errors: 400 Bad request, 401 Unauthorised, 403 Forbidden, 404 Not found, 409 Conflict, 422 Unprocessable content, 429 Too many requests, as problem details (application/problem+json).