IdempotencyAll pages

Idempotency

Send an Idempotency-Key with every create, so a retry after a timeout never asks a person twice.

Why#

A request can time out after the task was created. Without protection, retrying it creates a second task, and someone gets asked twice. With an Idempotency-Key, the retry returns the task you already have.

How it works#

Send an Idempotency-Key header, up to 255 characters, with POST /v1/tasks and with webhook posts. Use something that identifies the real-world request, such as your order number, or a UUID you store with it.

  • The first request creates the task: 201 Created.
  • The same key with the same body returns the original task: 200 OK with Idempotent-Replayed: true. Concurrent retries still create only one task.
  • The same key with a different body is 409 idempotency_conflict: you are reusing a key for a different request.
curl https://api.tasktohuman.com/v1/tasks \
  -H "Authorization: Bearer $TTH_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: refund-4821" \
  -d '{
    "task_type": "approve_refund",
    "title": "Refund €249 to order #4821?",
    "payload": {
      "order_id": "4821",
      "amount": 249,
      "reason": "Arrived damaged",
      "customer_email": "marta@example.com"
    },
    "deadline_minutes": 120
  }'
200 response: the original task
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Idempotent-Replayed: true

{
  "id": "01a1e3a7-6489-7106-aa3a-c976287f9999",
  "state": "notified",
  "task_type": "approve_refund",
  "title": "Refund €249 to order #4821?",
  "test": false,
  "owner": {
    "id": "01a1dcba-b57a-7aa2-b6b1-05d81545c2ba",
    "name": "Ana"
  },
  "expires_at": "2026-11-16T11:19:20.713Z",
  "created_at": "2026-11-16T09:19:20.713Z",
  "finished_at": null,
  "escalations": 0,
  "decision": null
}
curl https://api.tasktohuman.com/v1/tasks \
  -H "Authorization: Bearer $TTH_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: refund-4821" \
  -d '{
    "task_type": "approve_refund",
    "title": "Refund €250 to order #4821?",
    "payload": {
      "order_id": "4821",
      "amount": 250,
      "reason": "Arrived damaged",
      "customer_email": "marta@example.com"
    },
    "deadline_minutes": 120
  }'
409 response
HTTP/1.1 409 Conflict
Content-Type: application/problem+json

{
  "type": "https://tools.ietf.org/html/rfc9110#section-15.5.10",
  "title": "This idempotency key was already used with a different request.",
  "status": 409,
  "code": "idempotency_conflict",
  "traceId": "00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01"
}

Scope#

  • A key is unique per workspace and mode: a tth_test_ key and a tth_live_ key never replay each other's tasks.
  • A key lasts as long as its task exists.
  • "Same body" means the same JSON content for POST /v1/tasks (spacing doesn't matter), approvers and chain included, and the same raw bytes for webhooks.
  • An MCP create_task call takes its key as the idempotency_key argument. A key used on /v1 and on MCP in the same workspace is a conflict.
  • Without the header there is no protection: every request creates a task.
  • A request refused for credits (402 not_enough_credits) leaves no trace: retry with the same key after buying credits (Credits).

Retrying safely#

Retry on a network error, a timeout, a 429 (after Retry-After) or a 5xx, always with the same key and body. Don't retry a 4xx other than 429 unchanged: it will fail the same way.