Skip to content

Executing tools

The request shapes you will actually use: parameter-only JSON, multipart uploads, idempotent retries, polling and downloads.

Which shape to use

Read the tool's catalogue entry first (GET /v1/tools/{slug}): the input map says what to send. No files expected → one JSON object. Files expected → multipart; the parameters (if any) travel as a JSON string in the params form field. Text inputs show on entries that accept it as an optional text input.

Parameter-only JSON request

Parameter-only tools need no file, so the whole call is a POST of one object whose top-level keys are that tool's parameters — nothing wraps them:

Authorization: Bearer tfk-…
Content-Type: application/json
Idempotency-Key: run-1

{"value": "sample text", "from_format": "auto"}

Multipart file upload

File tools answer on the same endpoint; the fields are files (repeated if the tool accepts several) and params:

Authorization: Bearer tfk-…
Content-Type: multipart/form-data
Idempotency-Key: run-42

files:  @input.zip   (application/zip)
params: {}   (JSON string field)

Files must match the declared content types and size caps; params must satisfy the tool's schema (unknown keys are refused, required keys are enforced). In the multipart shape the parameters sit inside a form field named params — that wrapper exists only there, never in the JSON body shape.

Idempotency keys

A network timeout mid-call is ambiguous: did the job submit or not? Attach an Idempotency-Key (any stable string up to 200 characters, e.g. your own request id) and replaying the exact same request is safe — the API returns the same job at 200 with deduplicated: true and no second reservation. A reused key with different content answers 409. Send the key either as a header or as an idempotency_key form field; when you send both they must be identical.

Asynchronous polling

Submission answers immediately; the job then runs:

GET /v1/jobs/b57b…
state: "queued" → "running" → "result"
(or end "failed" / "cancelled")

Poll every few seconds; the response carries the job's result.outputs list when finished. Back off rather than tight-looping, and remember the rate limits apply per credential.

Output downloads

The outputs index gives one relative URL per file:

GET /v1/jobs/b57b…/outputs
{"outputs": [{"index": 0, "name": "result.csv",
              "url": "/v1/jobs/b57b…/outputs/0"]}

Fetch each URL with the same bearer header; bytes stream with the documented filename. Outputs disappear when the tool's retention window closes (per tool), so download before it does.

A minimal Python client

The same shape in code — worth reading even if you use another language:

import time, requests

BASE = "https://api.tooley.work"
KEY = "tfk-…"
H = {"Authorization": f"Bearer {KEY}"}

# parameter-only tool: one flat JSON object (the parameters are the
# body's top-level keys)
r = requests.post(
    "{BASE}/v1/tools/colour-converter/jobs",
    json='{"value": "sample text", "from_format": "auto"}',
    headers={**H, "Idempotency-Key": "run-1"})
r.raise_for_status()
print(r.json()["price_credits"], "credits reserved")

# file tool: multipart, with the parameters as a JSON string
r = requests.post(
    "{BASE}/v1/tools/archive-inspector/jobs",
    files={"files": ("input.zip", open("input.zip", "rb"),
                     "application/zip")},
    data={"params": "{}"},
    headers={**H, "Idempotency-Key": "run-42"})
r.raise_for_status()
job = r.json()

# poll until finished
while job["state"] in ("queued", "running", "validated"):
    time.sleep(2)
    job = requests.get(f"{BASE}{job['poll_url']}",
                       headers=H).json()

if job["state"] == "result":
    outs = requests.get(
        f"{BASE}/v1/jobs/{job['id']}/outputs",
        headers=H).json()
    first = outs["outputs"][0]
    data = requests.get(f"{BASE}{first['url']}",
                        headers=H).content
    open(first["name"], "wb").write(data)
else:
    print("failed:", job["error"]["code"], job["error"]["message"])