Idempotency

Idempotency means that sending the same request twice has the same effect as sending it once. It protects you from doing something twice by accident, such as creating two projects or paying for two runs when a network error made you retry.

The library handles this for you in most cases. This page explains how, and when to add your own key.

What the library does for you

Every write the library sends (POST, PUT, PATCH and DELETE) carries an Idempotency-Key header. The library makes up a fresh random key for each call. If it has to retry that call, it sends the same key again, so the server runs the work once and gives the same answer each time.

Reads (GET) don't need a key.

Add your own key

A key made by the library is new for every call. If your own code retries a call, for example because your script crashed and started again, the second call gets a new key, and the work runs again.

To prevent that, pass an idempotency_key that you choose. Every method that writes takes one:

python
from thrustlab import Client

client = Client()

project = client.projects.create(
    name="Nightly build 2026-11-18",
    idempotency_key="nightly-2026-11-18-project",
)

Run this twice and you get the same project back. The second run doesn't make a second project. Pick a key that names the one piece of work, such as a build number, and make it unique for each piece of work. A key can be up to 255 characters.

What the server remembers

  • The server keeps the answer for 24 hours.
  • Keys belong to your API key. Two keys can use the same text without clashing.
  • A key is tied to the whole request: the method, the address and the body. Sending the same key with something different fails with a ConflictError and the code idempotency_key_reused_with_different_body.
  • If the first request is still running when the second arrives, the second waits briefly. If the first is not done, you get a ConflictError with the code idempotency_request_in_progress. Try again a little later to get the finished answer.

Failures are not remembered

The server only remembers an outcome that is final. It forgets a 429, a 402, a 403 and any 5xx error. So when a call fails because you ran out of compute units, you can fix that and send it again with the same key. It runs as a new request.

An answer such as 422, which says the request itself is wrong, is remembered. Change the request and use a new key.