# Tools runs

> Run one tool once, wait for it or poll it, read what happened to it, cancel it, and delete its input and output.

- Human-readable page: https://dashboard.sproutsdata.ai/docs/api-reference/tools-runs
- This document: https://dashboard.sproutsdata.ai/docs/agents/api-reference/tools-runs
- Index of every agent document: https://dashboard.sproutsdata.ai/llms.txt
- API base URL: https://api.sproutsdata.ai

## Summary

`POST /tools/v1/runs` runs one tool once with one input. It answers 200 when the run ended within `wait_seconds`, else 202 with a `Location` to poll. Other routes list runs, read one, read its event log, cancel it, and delete its stored input and output.

## Rules

### Starting

- Scope `dsp.tools.write` to start, cancel and delete; `dsp.tools.read` to list and read.
- Body: `tool` (required, `area/name`, e.g. `amazon/product`), `input` (an object matching the tool's `input_schema`), `wait_seconds` (how long to wait for the run in the call). The wait is capped at 20 seconds whatever is sent. Body at most 64 KiB (413 `request.too_large`).
- 200: the run ended in time; read `status` (any final status). 202: still going; the body is the run so far and `Location` names `GET /tools/v1/runs/{run_id}`.
- Refusals before a run is queued (bad input, a switched-off tool, the balance, too many runs in flight) are problems, not runs.
- `Idempotency-Key` optional, strongly advised (1 to 120 characters from `A-Z a-z 0-9 . _ : -`): a retry within 24 hours returns the first run (`replayed: true`) and never runs or charges the tool again. The same key for another tool or another caller: 409 `tools.idempotency_key_reused`.
- 504 `upstream.timeout` on a start: the run may still finish. Check `GET /tools/v1/runs` (or retry with the same `Idempotency-Key`) before starting another; a second start without the key can pay twice.

### Statuses and polling

- `status`: `queued`, `running` (in progress); `succeeded`, `no_match`, `rejected`, `failed`, `unresolved`, `cancelled`, `expired` (final). `output` is set once `succeeded`. `queue_position` and `queue_reason` (`capacity`, `paused`) explain a wait.
- Poll `GET /tools/v1/runs/{run_id}` every few seconds until final (polling routes allow 600 requests a minute per workspace). The tool's `latency.typical_seconds` sets expectations.
- `GET /tools/v1/runs/{run_id}/events`: the run's history (`queued`, `starting`, `running`, `retry_scheduled`, `waiting`, `cancel_requested`, `finished`), kept with the run. A JSON list, not a stream. Free; does not settle the charge.
- `GET /tools/v1/runs`: the caller's own runs, newest first, without output; filters `tool`, `status`; `limit` default 20, max 100; page with `cursor` = `next_cursor` until it is null.
- Run ids look like `run_` followed by 32 hex characters. The same id reads the run in usage history (`GET /v1/usage/history/{run_id}`).

### Billing

- A start holds the most the run can cost (the quote's `max_credits`); 402 `credits.insufficient` if the balance cannot cover it.
- When the run ends it is charged for what it returned (ceil(`billable_units` / 10) × the tool's price per 10 records; a single-response tool: its price per call); the rest of the hold is released. `cost.credits_charged` and, once settled, `meta.credits_charged` show the charge.
- A run that ends `cancelled` costs nothing. Canceling a run that already finished: 409.
- 503 `tools.not_priced`: the tool has no price and cannot run. 503 `tools.units_mismatch`: the run was canceled and nothing was charged.

### Deleting

- `DELETE /tools/v1/runs/{run_id}` (204) removes a finished run's input and output now; the run stays listed with its status and cost, and reads `payload_deleted: true`. A run still queued or running: 409, cancel it first. Changes no charge. `payload_expires_at` says when stored data would be removed anyway.

## Operations

### POST /tools/v1/runs

Start Run

- URL: `POST https://api.sproutsdata.ai/tools/v1/runs`
- Scopes (any one): `dsp.tools.write`
- Cost: billed: an answer with results spends credits, an empty one is free
- Idempotency-Key header: optional

Run one tool once.

Answers 200 when the run finished within `wait_seconds` (any final status:
`succeeded`, `no_match`, `failed` and so on), else 202 with the run so far
and a `Location` to poll. Refusals before the run is queued (bad input, a
switched-off tool, the spend cap, too many runs in flight) are RFC 9457
errors.

Send `Idempotency-Key` to make a retry safe: a repeated key returns the
first run and never runs the tool again.

Headers:

- `Idempotency-Key` (string): Send one to make a retry safe: a retry with the same key on the same UTC day is charged once.

Request body (JSON, required):

- `tool` (string, required): Limits: at most 80 characters.
- `input` (object)
- `wait_seconds` (number or null): Limits: at least 0.

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

- `cost` (object, required)
  - `credits_charged` (number, required)
  - `price_credits` (number or null, required)
- `created_at` (string (date-time), required)
- `deadline_at` (string (date-time), required)
- `run_id` (string, required)
- `status` (string, required): One of: `"queued"`, `"running"`, `"succeeded"`, `"no_match"`, `"rejected"`, `"failed"`, `"unresolved"`, `"cancelled"`, `"expired"`.
- `tool` (string, required)
- `units` (integer, required)
- `billable_units` (integer or null)
- `completed_at` (string (date-time) or null)
- `error` (object or null)
  - `code` (string, required)
  - `message` (string, required)
- `estimated_start_seconds` (integer or null)
- `input` (object or null)
- `latency_ms` (integer or null)
- `output` (any)
- `payload_deleted` (boolean): Default `false`.
- `payload_expires_at` (string (date-time) or null)
- `queue_position` (integer or null)
- `queue_reason` (string or null): One of: `"capacity"`, `"paused"`.
- `replayed` (boolean): Default `false`.
- `synthetic` (boolean): Default `false`.
- `units_bound` (integer or null)

Errors:

- 401: No usable credential (`auth.unauthorized`).
- 403: Not allowed: the workspace (`auth.tenant_not_allowed`) or the key's scope.
- 404: No such tool, group or run for this workspace (`tools.*_not_found`).
- 409: A finished run (`tools.run_finished`), or an Idempotency-Key reused for another input (`tools.idempotency_conflict`).
- 410: A retired tool (`tools.tool_disabled`).
- 413: The body is too large (`request.too_large`).
- 422: Validation Error
- 429: Too many requests (`rate_limit.exceeded`), runs in flight (`tools.too_many_runs`) or today's spend (`tools.spend_cap_exceeded`).
- 501: Tools are not served by this deployment (`not_implemented`).
- 503: Tools could not be reached (`upstream.unavailable`), or a tool is switched off (`tools.tool_disabled`, `service.unavailable`).
- 504: Tools did not answer in time (`upstream.timeout`). A run may still finish.

Example request:

```bash
curl -X POST "https://api.sproutsdata.ai/tools/v1/runs" \
  -H "X-API-Key: $SPROUTS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
       "tool": "amazon/product",
       "input": {
         "asin": "B0CP9YB3Q4"
       },
       "wait_seconds": 20
     }'
```

### GET /tools/v1/runs

List Runs

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

The caller's own runs, newest first, without their output. Only the credential that started a run can see it, as with usage history.

Query parameters:

- `tool` (string or null): Limits: at most 80 characters.
- `status` (string or null): Limits: at most 16 characters.
- `limit` (integer): Default `20`. Limits: 1 to 100.
- `cursor` (string or null): Limits: at most 40 characters.

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

- `items` (array of object, required)
  - `cost` (object, required)
    - `credits_charged` (number, required)
    - `price_credits` (number or null, required)
  - `created_at` (string (date-time), required)
  - `deadline_at` (string (date-time), required)
  - `run_id` (string, required)
  - `status` (string, required): One of: `"queued"`, `"running"`, `"succeeded"`, `"no_match"`, `"rejected"`, `"failed"`, `"unresolved"`, `"cancelled"`, `"expired"`.
  - `tool` (string, required)
  - `units` (integer, required)
  - `billable_units` (integer or null)
  - `completed_at` (string (date-time) or null)
  - `error` (object or null)
    - `code` (string, required)
    - `message` (string, required)
  - `estimated_start_seconds` (integer or null)
  - `input` (object or null)
  - `latency_ms` (integer or null)
  - `output` (any)
  - `payload_deleted` (boolean): Default `false`.
  - `payload_expires_at` (string (date-time) or null)
  - `queue_position` (integer or null)
  - `queue_reason` (string or null): One of: `"capacity"`, `"paused"`.
  - `replayed` (boolean): Default `false`.
  - `synthetic` (boolean): Default `false`.
  - `units_bound` (integer or null)
- `next_cursor` (string or null)

Errors:

- 401: No usable credential (`auth.unauthorized`).
- 403: Not allowed: the workspace (`auth.tenant_not_allowed`) or the key's scope.
- 422: Validation Error
- 429: Too many requests (`rate_limit.exceeded`), runs in flight (`tools.too_many_runs`) or today's spend (`tools.spend_cap_exceeded`).
- 501: Tools are not served by this deployment (`not_implemented`).
- 503: Tools could not be reached (`upstream.unavailable`), or a tool is switched off (`tools.tool_disabled`, `service.unavailable`).
- 504: Tools did not answer in time (`upstream.timeout`). A run may still finish.

Example request:

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

### GET /tools/v1/runs/{run_id}

Get Run

- URL: `GET https://api.sproutsdata.ai/tools/v1/runs/{run_id}`
- Scopes (any one): `dsp.tools.read`
- Cost: free

One run: its status, and its output once it has succeeded.

Path parameters:

- `run_id` (string, required)

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

- `cost` (object, required)
  - `credits_charged` (number, required)
  - `price_credits` (number or null, required)
- `created_at` (string (date-time), required)
- `deadline_at` (string (date-time), required)
- `run_id` (string, required)
- `status` (string, required): One of: `"queued"`, `"running"`, `"succeeded"`, `"no_match"`, `"rejected"`, `"failed"`, `"unresolved"`, `"cancelled"`, `"expired"`.
- `tool` (string, required)
- `units` (integer, required)
- `billable_units` (integer or null)
- `completed_at` (string (date-time) or null)
- `error` (object or null)
  - `code` (string, required)
  - `message` (string, required)
- `estimated_start_seconds` (integer or null)
- `input` (object or null)
- `latency_ms` (integer or null)
- `output` (any)
- `payload_deleted` (boolean): Default `false`.
- `payload_expires_at` (string (date-time) or null)
- `queue_position` (integer or null)
- `queue_reason` (string or null): One of: `"capacity"`, `"paused"`.
- `replayed` (boolean): Default `false`.
- `synthetic` (boolean): Default `false`.
- `units_bound` (integer or null)

Errors:

- 401: No usable credential (`auth.unauthorized`).
- 403: Not allowed: the workspace (`auth.tenant_not_allowed`) or the key's scope.
- 404: No such tool, group or run for this workspace (`tools.*_not_found`).
- 422: Validation Error
- 429: Too many requests (`rate_limit.exceeded`), runs in flight (`tools.too_many_runs`) or today's spend (`tools.spend_cap_exceeded`).
- 501: Tools are not served by this deployment (`not_implemented`).
- 503: Tools could not be reached (`upstream.unavailable`), or a tool is switched off (`tools.tool_disabled`, `service.unavailable`).
- 504: Tools did not answer in time (`upstream.timeout`). A run may still finish.

Example request:

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

### GET /tools/v1/runs/{run_id}/events

Get Run Events

- URL: `GET https://api.sproutsdata.ai/tools/v1/runs/{run_id}/events`
- Scopes (any one): `dsp.tools.read`
- Cost: free

What happened to one run, in order: queued, started, running, any
retry or cancel, finished. Kept with the run, so a run can be traced long
after it ended. Never names who served it.

Path parameters:

- `run_id` (string, required)

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

- `items` (array of object, required)
  - `at` (string (date-time), required)
  - `status` (string, required): One of: `"queued"`, `"running"`, `"succeeded"`, `"no_match"`, `"rejected"`, `"failed"`, `"unresolved"`, `"cancelled"`, `"expired"`.
  - `type` (string, required): One of: `"queued"`, `"starting"`, `"running"`, `"retry_scheduled"`, `"waiting"`, `"cancel_requested"`, `"finished"`.
- `run_id` (string, required)

Errors:

- 401: No usable credential (`auth.unauthorized`).
- 403: Not allowed: the workspace (`auth.tenant_not_allowed`) or the key's scope.
- 404: No such tool, group or run for this workspace (`tools.*_not_found`).
- 422: Validation Error
- 429: Too many requests (`rate_limit.exceeded`), runs in flight (`tools.too_many_runs`) or today's spend (`tools.spend_cap_exceeded`).
- 501: Tools are not served by this deployment (`not_implemented`).
- 503: Tools could not be reached (`upstream.unavailable`), or a tool is switched off (`tools.tool_disabled`, `service.unavailable`).
- 504: Tools did not answer in time (`upstream.timeout`). A run may still finish.

Example request:

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

### POST /tools/v1/runs/{run_id}/cancel

Cancel Run

- URL: `POST https://api.sproutsdata.ai/tools/v1/runs/{run_id}/cancel`
- Scopes (any one): `dsp.tools.write`
- Cost: free

Stop a run. It ends as `cancelled` and costs nothing. A run that already
finished answers 409.

Path parameters:

- `run_id` (string, required)

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

- `cost` (object, required)
  - `credits_charged` (number, required)
  - `price_credits` (number or null, required)
- `created_at` (string (date-time), required)
- `deadline_at` (string (date-time), required)
- `run_id` (string, required)
- `status` (string, required): One of: `"queued"`, `"running"`, `"succeeded"`, `"no_match"`, `"rejected"`, `"failed"`, `"unresolved"`, `"cancelled"`, `"expired"`.
- `tool` (string, required)
- `units` (integer, required)
- `billable_units` (integer or null)
- `completed_at` (string (date-time) or null)
- `error` (object or null)
  - `code` (string, required)
  - `message` (string, required)
- `estimated_start_seconds` (integer or null)
- `input` (object or null)
- `latency_ms` (integer or null)
- `output` (any)
- `payload_deleted` (boolean): Default `false`.
- `payload_expires_at` (string (date-time) or null)
- `queue_position` (integer or null)
- `queue_reason` (string or null): One of: `"capacity"`, `"paused"`.
- `replayed` (boolean): Default `false`.
- `synthetic` (boolean): Default `false`.
- `units_bound` (integer or null)

Errors:

- 401: No usable credential (`auth.unauthorized`).
- 403: Not allowed: the workspace (`auth.tenant_not_allowed`) or the key's scope.
- 404: No such tool, group or run for this workspace (`tools.*_not_found`).
- 409: A finished run (`tools.run_finished`), or an Idempotency-Key reused for another input (`tools.idempotency_conflict`).
- 413: The body is too large (`request.too_large`).
- 422: Validation Error
- 429: Too many requests (`rate_limit.exceeded`), runs in flight (`tools.too_many_runs`) or today's spend (`tools.spend_cap_exceeded`).
- 501: Tools are not served by this deployment (`not_implemented`).
- 503: Tools could not be reached (`upstream.unavailable`), or a tool is switched off (`tools.tool_disabled`, `service.unavailable`).
- 504: Tools did not answer in time (`upstream.timeout`). A run may still finish.

Example request:

```bash
curl -X POST "https://api.sproutsdata.ai/tools/v1/runs/run_4b1e9c2a7d3f4e5a8b6c0d1e2f3a4b5c/cancel" \
  -H "X-API-Key: $SPROUTS_API_KEY"
```

### DELETE /tools/v1/runs/{run_id}

Tools Delete Run

- URL: `DELETE https://api.sproutsdata.ai/tools/v1/runs/{run_id}`
- Scopes (any one): `dsp.tools.write`
- Cost: free

Delete a finished run's input and output now. The run stays in your runs and in
usage with its status and what it cost; it reads ``payload_deleted``. You may delete the
runs you can read: your own, your API keys', and as a workspace admin every run of the
workspace. A run still queued or running answers 409: cancel it first. Changes no
charge.

Path parameters:

- `run_id` (string, required)

Response 204: Successful Response

Errors:

- 422: Validation Error

Example request:

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

## See also

- https://dashboard.sproutsdata.ai/docs/agents/guides/tools
- https://dashboard.sproutsdata.ai/docs/agents/api-reference/tools-catalog
- https://dashboard.sproutsdata.ai/docs/agents/guides/idempotency
