# Balance and spend

> Read your workspace's credit balance and ledger from the API, see what each call cost, and handle a balance that cannot pay.

- Human-readable page: https://dashboard.sproutsdata.ai/docs/guides/credits/balance-and-spend
- This document: https://dashboard.sproutsdata.ai/docs/agents/guides/credits/balance-and-spend
- Index of every agent document: https://dashboard.sproutsdata.ai/llms.txt
- API base URL: https://api.sproutsdata.ai

## Summary

Read the workspace balance (`GET /v1/credits`), the credit ledger (`GET /v1/credits/transactions`), and each call's cost (`meta.credits_charged`). Quote before spending with `POST /v1/credits/quote`. All three routes need `dsp.usage.read` and are free.

## Balance fields (`GET /v1/credits`)

| Field       | Meaning                                                                            |
| ----------- | ---------------------------------------------------------------------------------- |
| `available` | Spendable now. Check this before spending.                                         |
| `balance`   | Credits in the wallet; negative while in debt.                                     |
| `reserved`  | Held for work in progress (agent runs).                                            |
| `debt`      | Owed after a refund or dispute; repaid first.                                      |
| `status`    | `active` or `frozen` (frozen: billed calls get 402 `credits.wallet_frozen`).       |
| `has_paid`  | Workspace has ever bought credits (needed for whole records in lists and exports). |
| `rate_card` | Price list name in use.                                                            |
| `stale`     | `true`: ledger unreachable; figures are the last read and may be behind.           |

## Ledger (`GET /v1/credits/transactions`)

- Newest first. Query `limit` (default 50, max 100) and `cursor` (max 500 chars). Answer: `results[]`, `next_cursor` (null on the last page).
- Entry: `id`, `kind`, `credits` (signed: + in, - spent), `balance_after`, `action` (the billed action, or null), `source` (for grants, for example `signup`, `referral`), `created_at`.
- For per-call detail (request, results, cost) use `GET /v1/usage/history`.

## Cost on each answer

- `meta.credits_charged`: cost of this call. `0` when nothing charged (empty answer, same-day retry with the same `Idempotency-Key`). `null` when not metered.
- `meta.credits_balance`: available after this call, excluding credits held for running agent runs; `null` when unknown.
- CSV export made at once: header `X-Credits-Charged`.
- `POST /v1/lists/{list_id}/items`, `GET /v1/lists/{list_id}/items`: top-level `credits_charged`.
- Agent run, enrichment job: `credits_charged` on the run or job, settled when it ends.
- Tool run: `meta.credits_charged` on the run.

## Insufficient balance

- 402 `credits.insufficient` before anything runs; nothing charged. `extra.required_credits`, `extra.available_credits`.
- Work that holds its maximum first (agent runs, enrichment, tool runs) is refused when the maximum does not fit.
- Action: send a smaller request that fits, or have an owner or billing member buy credits in the dashboard (`/credits`), then retry. Credits cannot be bought through the API.

## Operations

### GET /v1/credits

The workspace's credits

- URL: `GET https://api.sproutsdata.ai/v1/credits`
- Scopes (any one): `dsp.usage.read`
- Cost: free

Response 200 (application/json): Successful Response
Response fields:

- `available` (number, required): What can be spent now.
- `balance` (number, required): Credits in the wallet (negative while in debt).
- `debt` (number, required): Owed after a refund or dispute; repaid first.
- `has_paid` (boolean, required): Whether the workspace has ever bought credits.
- `rate_card` (string, required): The price list calls are charged by.
- `reserved` (number, required): Held for work in progress (agent runs).
- `status` (string, required): `active`, or `frozen` by Sprouts staff.
- `stale` (boolean): The ledger could not be reached: this is the last balance read, and may be behind. Default `false`.

Errors:

- 401: No credential, or one that does not verify (`auth.unauthorized`).
- 403: The credential lacks the scope this route needs (`auth.insufficient_scope`), or the signed-in user has not chosen a workspace (`auth.workspace_required`).
- 503: A service this request needs is unavailable, or the API is at capacity. See `Retry-After`.

Example request:

```bash
curl "https://api.sproutsdata.ai/v1/credits" \
  -H "X-API-Key: $SPROUTS_API_KEY"
```

### GET /v1/credits/transactions

The workspace's credit history, newest first

- URL: `GET https://api.sproutsdata.ai/v1/credits/transactions`
- Scopes (any one): `dsp.usage.read`
- Cost: free

Query parameters:

- `limit` (integer): Default `50`. Limits: 1 to 100.
- `cursor` (string or null): Limits: at most 500 characters.

Response 200 (application/json): Successful Response
Response fields:

- `results` (array of object, required)
  - `balance_after` (number, required)
  - `created_at` (string, required)
  - `credits` (number, required): Signed: + credits in, - credits spent.
  - `id` (string, required)
  - `kind` (string, required)
  - `action` (string or null)
  - `source` (string or null): For grants: `signup`, `referral`, ...
- `next_cursor` (string or null)

Errors:

- 401: No credential, or one that does not verify (`auth.unauthorized`).
- 403: The credential lacks the scope this route needs (`auth.insufficient_scope`), or the signed-in user has not chosen a workspace (`auth.workspace_required`).
- 422: Validation Error
- 503: A service this request needs is unavailable, or the API is at capacity. See `Retry-After`.

Example request:

```bash
curl "https://api.sproutsdata.ai/v1/credits/transactions?limit=20" \
  -H "X-API-Key: $SPROUTS_API_KEY"
```

### POST /v1/credits/quote

What a call would cost, from the live price list

- URL: `POST https://api.sproutsdata.ai/v1/credits/quote`
- Scopes (any one): `dsp.usage.read`
- Cost: free

Holds nothing and costs nothing. `available` and `covered` are from the balance read
moments ago, when there is one; a quote never waits on the ledger.

Request body (JSON, required):

- `operation` (string, required): The billable calls, named for what a caller does. One of: `"search"`, `"search_auto"`, `"similar"`, `"relationships"`, `"institutions"`, `"lookup"`, `"org_chart"`, `"agent_run"`, `"enrichment"`.
- `effort` (string or null): `agent_run` only, and required for it. The earlier names (`minimal`, `low`, `medium`, `high`, `xhigh`) are still accepted. One of: `"quick"`, `"basic"`, `"standard"`, `"detailed"`, `"maximum"`, `"auto"`, `"minimal"`, `"low"`, `"medium"`, `"high"`, `"xhigh"`.
- `fields` (array of string or null): `enrichment` only: the fields asked for each of `rows` records. The quote is then every one of them found, each field at its own price (a phone number costs more than an email). One of: `"EMAIL"`, `"PHONE"`, `"DOMAIN"`, `"LINKEDIN_URL"`. Limits: 1 to 4 items.
- `rows` (integer): Rows on the page (paged operations, up to 100), records found (`lookup`, up to 1,000), or for `enrichment`: records when `fields` is given (up to 10,000, a job's most), else values at one price (up to 30,000). Ignored by flat operations and agent runs. An enrichment quote over 30,000 credits is refused, as the job would be. Default `10`. Limits: 0 to 30000.
- `start` (integer): Rows of the same search already paid for (the next page's offset): only the rows beyond them are charged. Default `0`. Limits: 0 to 100000.

Response 200 (application/json): Successful Response
Response fields:

- `basis` (string, required): `page`: these rows of a search; `records`: per record found; `call`: flat, whatever it returns; `run`: an agent run at that effort; `run_up_to`: `auto` holds this much and is charged at the effort it chooses; `values_up_to`: enrichment holds this much (every value asked for) and is charged only for the values newly found. One of: `"page"`, `"records"`, `"call"`, `"run"`, `"run_up_to"`, `"values_up_to"`.
- `credits` (number, required): What the call would be charged, in credits.
- `operation` (string, required): The billable calls, named for what a caller does. One of: `"search"`, `"search_auto"`, `"similar"`, `"relationships"`, `"institutions"`, `"lookup"`, `"org_chart"`, `"agent_run"`, `"enrichment"`.
- `rate_card` (string, required): The price list this quote is from.
- `available` (number or null): What the workspace can spend now, in credits; `null` when not known.
- `covered` (boolean or null): Whether `available` covers this quote; `null` when not known.

Errors:

- 401: No credential, or one that does not verify (`auth.unauthorized`).
- 403: The credential lacks the scope this route needs (`auth.insufficient_scope`), or the signed-in user has not chosen a workspace (`auth.workspace_required`).
- 422: The request is invalid (`request.invalid`), or its cursor is (`pagination.*`).

Example request:

```bash
curl -X POST "https://api.sproutsdata.ai/v1/credits/quote" \
  -H "X-API-Key: $SPROUTS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
       "operation": "search",
       "rows": 50
     }'
```

## See also

- `https://dashboard.sproutsdata.ai/docs/agents/guides/credits`
- `https://dashboard.sproutsdata.ai/docs/agents/guides/credits/buying-credits`
- `https://dashboard.sproutsdata.ai/docs/agents/guides/usage-history`
