Beta API. See the stability policy.
Idempotency
Sometimes a request goes out and you never see the answer, because the network dropped or your program crashed. If you send it again, you might start a second run. An idempotency key stops that. Send the same key again and ThrustLab gives you the answer to the first request instead of doing the work twice.
Add a key to a request
Put a header called Idempotency-Key on any request that changes something: POST, PATCH or DELETE. Pick any text that's unique for that piece of work, such as a job number and attempt:
curl -X POST https://thrustlab.com/v1/projects -H "Authorization: Bearer $THRUSTLAB_API_KEY" -H "Idempotency-Key: job-42" -H "Content-Type: application/json" -d '{"name": "Quad frame test"}'Send that request twice and you get one project and the same response both times. ThrustLab remembers a key for 24 hours.
The Python library adds a random key to every change for you, so its automatic retries are safe. Pass your own only when you retry from somewhere else, such as a job queue.
What happens when a key comes back
- Same key, same request: you get the saved response from the first time.
- Same key, different request: you get a
409with the codeidempotency_key_reused_with_different_body. A key stands for one request. It covers the method, the address and the body, so you can't reuse it for a different endpoint either. Use a new key. - Same key, first request still running: you get a
409with the codeidempotency_request_in_progress. Wait a moment and send it again. You'll get the first request's answer, and the work still happens only once. - Key longer than 255 characters: you get a
400with the codeidempotency_key_too_long.
Errors that aren't saved
If a request fails because of your account, ThrustLab doesn't save the failure under the key. That way you can fix the problem and send the same request with the same key. This covers 402 (not enough compute units) and 403 (for example, an email you haven't verified, or a feature that needs the Pro plan). A 429 or any server error (5xx) isn't saved either, so retrying always gets a fresh try.
Other errors, such as a 400 for a bad value, are saved. If you fix the request, use a new key.