Skip to content
Developers

    Safe retries

    Markdown
    How the Idempotency-Key header makes tiktornado API changes safe to retry. Which requests need it, replays, 409 and 422 answers, and the 24-hour window.

    A request can fail or time out after the change was made. The Idempotency-Key header lets you send it again without making the change twice: you get the first answer back instead.

    Which requests need it

    RequestNeeds Idempotency-Key
    POST /postsYes
    PATCH /posts/{postId}Yes
    DELETE /posts/{postId}Yes
    PUT /accounts/{accountId}/queueYes
    POST /comments/{commentId}/repliesYes
    POST /uploadsNo. A repeat simply gives you a new upload link
    Every GETNo

    A change sent without the header, or with a value that isn't 1 to 255 visible ASCII characters (no spaces), answers 400 idempotency_key_required and nothing runs.

    In MCP, every tool that changes something takes an idempotencyKey argument and sends it as this header.

    How it works

    Make up a new value for each change, such as a UUID, and send it with the request:

    curl -X DELETE https://api.tiktornado.com/api/v1/posts/k174wq9nrm6t2f0bd3xh8pz5a87v1c2e \
      -H "Authorization: Bearer $TIKTORNADO_API_KEY" \
      -H "Idempotency-Key: 0c8e2a4f-1b7d-4e5a-9c3f-6d2b8a1e7f40"

    Then, for the next 24 hours:

    • Same key, same request: the same method, path and body get the first answer back, with the same status and the header Idempotent-Replayed: true. The change is not made again.
    • Same key, different request: a different method, path or body answers 422 idempotency_key_reused.
    • Same key while the first is still running: answers 409 idempotency_in_progress. Wait a moment and send it again.

    "Same body" means the same bytes. Build the JSON once and resend that exact text: the same fields in another order, or with other spacing, count as a different body.

    Keys belong to the API key that sent them. The same Idempotency-Key sent with two different API keys is two separate requests.

    What is stored

    Once a change has passed the key, scope and rate limit checks, its answer is stored under the Idempotency-Key for 24 hours. That includes refusals: if POST /posts answered 400 schedule_too_soon, the same key and body get that 400 again. To try again with a new time, send the new body with a new key.

    These answers are not stored, so the same key runs the request again:

    • 429 slow_down: wait, then retry with the same key.
    • 500 unknown_error and 503 service_unavailable: our side failed. Retry with the same key.
    • 401, and a 403 or 409 or 422 from the checks before the change runs.

    If a request is cut off before it finishes, its key frees up after 15 minutes and a retry runs it again. tiktornado still makes the change only once: the first request can no longer save once the retry has taken the key over.

    What is safe to retry

    SituationWhat to do
    A GET failed or timed outSend it again
    POST /uploads failed or timed outAsk for a new link
    A change timed out, or the connection droppedSend it again with the same key and the same body
    A change answered 429, 500 or 503Wait, then send it again with the same key and the same body
    A change answered 409Wait a moment, then send it again with the same key
    A change answered 400 or 404Fix the request, then send it with a new key

    Example

    curl https://api.tiktornado.com/api/v1/posts \
      -H "Authorization: Bearer $TIKTORNADO_API_KEY" \
      -H "Content-Type: application/json" \
      -H "Idempotency-Key: 5b0f9c3e-8d21-4f6a-9a7e-2c4d1e8b7f30" \
      -d '{"accountId": "j971x2c4ajrq0w8sd5e8fxz3a57v2k8m", "kind": "video", "mediaRefs": ["https://media.example.com/uploads/2b81de/morning-run.mp4"], "postNow": true}'

    If this times out, run the exact same command again. Either the post was saved and you get its first answer, or it wasn't and it is saved now. Both times you end up with one post.