SDKsAll pages

SDKs

The official TypeScript and Python libraries: create a task, wait for the decision and verify the signed callback, with retries and idempotency built in.

Two official SDKs wrap the public API. They create, read, list and cancel tasks, wait for a decision, and check the signature of a callback. Both have no runtime dependencies, send an Idempotency-Key with every create and retry safely. They are open source under the Apache License 2.0, in the tasktohuman-integrations repository.

TypeScriptPython
Package@tasktohuman/sdk on npmtasktohuman on PyPI
Sourcesdks/typescriptsdks/python
Runs onNode.js 22 or later (ESM, with type declarations)Python 3.10 or newer, standard library only
ClientTaskToHumanTaskToHuman, and AsyncTaskToHuman for asyncio
OverviewTypeScript SDKPython SDK

Use them on your server only: the client holds your API key, which must never reach a web page or an app you ship.

Install#

npm install @tasktohuman/sdk

Create a key in the app under API & webhooks, then API keys, and keep it in the TTH_API_KEY environment variable. Start with a test key (tth_test_…): it works exactly like a live one but notifies only you. See Test mode.

Create a task and wait for the decision#

import { TaskToHuman } from "@tasktohuman/sdk";

const tth = new TaskToHuman({ apiKey: process.env.TTH_API_KEY! }); // tth_live_… or tth_test_…

const task = await tth.createTask(
  {
    task_type: "approve_refund",
    title: "Refund €249 to order #4821?",
    payload: { order_id: "4821", amount: 249, reason: "Arrived damaged" },
    deadline_minutes: 120,
  },
  // Names the real-world request: sending it again returns the same task instead of asking twice.
  { idempotencyKey: "refund-4821" },
);

const done = await tth.waitForDecision(task.id, { timeoutMs: 15 * 60_000 });
if (done.decision && !done.decision.automatic && ["approved", "edited"].includes(done.decision.action)) {
  // A person approved. For "edited", the changed values are in done.decision.payload.
}

Act on a decision only when automatic is false: a task type's default action can finish an unanswered task as approved, with the state expired (see the decision).

Waiting checks the task at once, then after 5 seconds, doubling up to 60 seconds, and raises a WaitTimeoutError (with the last task read) when the time is up. It suits scripts, tests and short agent turns. In production, give the task a callback_url (or set one on the task type) and verify the callback: the decision arrives within seconds, survives restarts and does not use your rate limit.

Verify a callback#

Both SDKs check the TTH-Signature header against the raw body, as described in Callbacks and signatures, and return the parsed task. A refused callback raises SignatureVerificationError, with a reason (missing_header, malformed_header, timestamp_out_of_tolerance or no_matching_signature). A missing or empty secret raises a TypeError, so an unset environment variable can't turn the check off.

import express from "express";
import { SignatureVerificationError, verifyCallback } from "@tasktohuman/sdk";

const app = express();

// express.raw keeps the exact bytes that were signed.
app.post("/hooks/tasktohuman", express.raw({ type: "application/json" }), async (req, res) => {
  let task;
  try {
    task = await verifyCallback({ body: req.body, headers: req.headers, secret: process.env.TTH_SIGNING_SECRET! });
  } catch (error) {
    if (error instanceof SignatureVerificationError) return res.sendStatus(400);
    throw error;
  }
  // Skip a TTH-Event-Id you already handled (a delivery can arrive twice), answer within 10 seconds,
  // and act only on a person's decision: task.decision?.automatic === false.
  res.sendStatus(204);
});

While a rotated secret overlaps, pass both secrets to cover your own deploy: secret: [newSecret, oldSecret] in TypeScript, verify_callback(body, headers, [new_secret, old_secret]) in Python.

What else they do#

  • Every call of /v1: get, list (one page, or every page with listAllTasks / iter_tasks) and cancel tasks, list task types and humans, the key's workspace and the plan's entitlements, and download the files a person sent with an answer.
  • Typed errors that carry the API's code, as the Errors page lists them, including NotEnoughCreditsError when a task is refused for lack of credits.
  • Retries on 429, server errors and network errors, with the same idempotency key, so a retry never asks a person twice. Redirects are refused, so your key only ever goes to the API.

The README of each SDK in the repository lists every method and option. Prefer a no-code tool? See No-code integrations.