Guides
Tools API
Run tools that fetch live data from websites and public sources, such as an Amazon product's current listing, priced before every run.
The Tools API is a catalog of tools, each of which fetches live data from one public source and returns it as a structured record. amazon/product, for example, reads an Amazon product page now and returns its title, price, rating and availability. Use a tool when you need what a source says at this moment, rather than what the Sprouts Data index holds.
The Tools API has its own versioned path, /tools/v1, beside the main API's /v1, and takes the same API key. Reading the catalog, quoting and reading runs need dsp.tools.read. Starting, cancelling and deleting runs, which spend credits or remove data, need dsp.tools.write. Every field is in the catalog reference and the runs reference.
Find a tool#
The catalog is free to read, and arranged in three levels: categories (such as e-commerce), groups (one per source, such as amazon), and tools.
| Request | Returns |
|---|---|
GET /tools/v1/categories | Each category's slug, name and tool_count. |
GET /tools/v1/groups | The groups, each with its summary, tool_count and min_credits (its cheapest tool's price). Filter with category or q. |
GET /tools/v1/groups/{slug} | One group with its tools. |
GET /tools/v1/tools | The tools. Filter with category or group, or pass q with a need in plain words to rank tools by relevance. |
GET /tools/v1/tools/{tool_id} | One tool in full. |
curl "https://api.sproutsdata.ai/tools/v1/tools?q=current%20price%20of%20an%20Amazon%20product" \
-H "X-API-Key: $SPROUTS_API_KEY"A tool's id is <group>/<name>, such as amazon/product, and it is two segments of the path: GET /tools/v1/tools/amazon/product. Its detail has what you need to call it:
input_schema: a JSON Schema for the run'sinput.output_schemaandexample_output: what a run returns.priceandlatency(typical_secondsandmax_seconds).status(enabled,hidden,pausedorretired) andavailable, whether it can run now. Retired, paused and hidden tools still answer by id, so a stored id always resolves.alternatives: other tools in the same group.
The input_schema of amazon/product, for example, takes either a product page url on amazon.com or a 10-character asin, and exactly one of the two:
{
"type": "object",
"additionalProperties": false,
"properties": {
"url": {
"type": "string",
"format": "uri",
"pattern": "^https://(www\\.)?amazon\\.com/[^\\s]*$",
"maxLength": 2000
},
"asin": { "type": "string", "pattern": "^[A-Z0-9]{10}$" }
},
"oneOf": [{ "required": ["url"] }, { "required": ["asin"] }]
}Check the price first#
A tool is priced per 10 records it returns, rounded up (price.basis per_10_records), and price.credits is the price of 10 records: a run that returns 10 records costs it once, 11 records twice, 50 records five times. Tools have no paging: a run returns all its records in one answer, as many as its limit input asks for (a list tool takes up to 5,000). A tool that answers with a single record is priced per call (per_call). POST /tools/v1/tools/{tool_id}/quote takes the input you would send and answers max_credits: the most a run with that input can cost, which is what a run holds. A quote is free and runs nothing.
curl -X POST "https://api.sproutsdata.ai/tools/v1/tools/amazon/product/quote" \
-H "X-API-Key: $SPROUTS_API_KEY" \
-H "Content-Type: application/json" \
-d '{ "input": { "asin": "B0CP9YB3Q4" } }'Run a tool#
POSThttps://api.sproutsdata.ai/tools/v1/runs
A run takes the tool, its input, and how long you are willing to wait for it, wait_seconds. The request waits up to that long: 10 seconds when left out, and never more than 20. Then:
200when the run finished in time, whatever its outcome: checkstatus.202when it is still going, with the run so far, aLocationheader to poll andRetry-After. PollGET /tools/v1/runs/{run_id}untilstatusis final.
curl -X POST "https://api.sproutsdata.ai/tools/v1/runs" \
-H "X-API-Key: $SPROUTS_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: $(uuidgen)" \
-d '{ "tool": "amazon/product", "input": { "asin": "B0CP9YB3Q4" }, "wait_seconds": 20 }'An input that does not match the tool's input_schema is refused with 422 and tools.input_invalid before anything runs, and nothing is charged.
Retry safely#
Send an Idempotency-Key (1 to 120 letters, digits or ._:-) to make a start safe to retry. For 24 hours, the same key returns the first run, marked replayed: true, and never runs or charges the tool again. After that, the same key starts a new run. Reusing a key for another tool, or from another credential, is 409 with tools.idempotency_key_reused; reusing it with a different input is 409 with tools.idempotency_conflict.
If a start answers 504 (upstream.timeout), the run may still have been queued. Retry with the same key, or check your runs, before starting another.
Statuses and what a run costs#
A run is queued, then running, then ends in one of these:
| Status | Meaning |
|---|---|
succeeded | It returned a result, in output. |
no_match | The source has nothing for this input. |
rejected | The source refused this input. |
failed | It did not work; error has a code and a message. |
cancelled | It was cancelled. |
expired | It did not finish in time. |
unresolved | Its outcome could not be confirmed. It is reviewed by hand. |
Before a run starts, the most it can cost (the quote's max_credits) is held from the balance; if the balance cannot cover it, the answer is 402 with credits.insufficient. Only a succeeded run is charged: its billable_units (records returned) divided by ten and rounded up, times the tool's price.credits, never more than was held. Every other outcome is charged nothing, and the hold is released. A run's cost.credits_charged reads 0 until the run is settled, and meta.credits_charged shows the charge once it is. Tools runs appear in usage history as dsp.tools.run.
Follow, cancel and delete runs#
| Request | What it does |
|---|---|
GET /tools/v1/runs/{run_id} | The run, with its input, and its output once it has succeeded. |
GET /tools/v1/runs/{run_id}/events | What happened to the run, in order: queued, starting, running, retry_scheduled, waiting, cancel_requested, finished. Kept with the run. |
POST /tools/v1/runs/{run_id}/cancel | Stops the run. It ends cancelled and costs nothing. A run that has already finished answers 409 with tools.run_finished. |
DELETE /tools/v1/runs/{run_id} | Deletes a finished run's input and output now (204). The run stays listed with its status and cost, and reads payload_deleted: true. A run still queued or running answers 409: cancel it first. |
GET /tools/v1/runs | Runs newest first, without their output. Filter by tool or status; limit 1 to 100 (default 20), and cursor from next_cursor. |
You see the runs you started. A signed-in person also sees the runs of the API keys they created, and a workspace admin sees every run of the workspace. A run's input and output are deleted automatically at payload_expires_at.
Limits#
| Refusal | Status | When |
|---|---|---|
tools.too_many_runs | 429 | The workspace has as many runs queued or running as it may. Wait for one to end. |
tools.spend_cap_exceeded | 429 | Tools have reached the day's spending limit. Retry-After says when it resets. |
tools.tool_disabled | 503 | The tool is paused for now. A retired tool answers 410 with the same code. |
tools.not_priced | 503 | The tool has no price yet, so it cannot run. Its detail reads available: false. |
request.too_large | 413 | The request body is over 64 KiB. |
Reads of runs count toward the higher polling limit (see Rate limits).