Documentation
Idempotency
Repeat a request safely with an Idempotency-Key, so a retry never runs or costs twice.
A request that timed out on your side may still have run, and been charged. Send an Idempotency-Key with it, and a retry with the same key returns the first answer instead of running again.
Send a Key
Add the header to any request. Use a new key for each request you mean to make, such as a UUID.
curl -G https://api.socialapi.sh/v1/tiktok/post/transcript \
-H "Authorization: Bearer $SOCIALAPI_API_KEY" \
-H "Idempotency-Key: 6f1c2a52-7f3e-4b0e-9a55-0d3f2b8e4c11" \
--data-urlencode "id=7711414040114892045"| Property | Value |
|---|---|
| Header | Idempotency-Key |
| Length | 1 to 255 characters |
| Kept | 24 hours |
| Scope | Your workspace |
In the TypeScript SDK, pass it in a call's second argument: { headers: { "Idempotency-Key": key } }.
Repeat a Request
Within 24 hours, the same key with the same request (the same method, path and query) returns the first answer's status and body, with the header Idempotent-Replayed: true. Another API key of the same workspace gets it too.
The repeat costs nothing, and does not count against your rate limit.
When a Key Is Refused
A key is refused in three cases, each with its own answer.
| Case | Answer | Do |
|---|---|---|
| The key was used for another request | 409 CONFLICT | Use a new key for a new request |
| The first request is still running | 409 CONFLICT | Wait for Retry-After, then repeat |
| The key is empty or too long | 400 INVALID_REQUEST | Send 1 to 255 characters |
Answers That Are Not Kept
A key keeps the first answer that settles the request. Some answers do not settle it, so the key is freed and the next request with it runs afresh.
- A
5xxanswer, such as502 UPSTREAM_UNAVAILABLE. - A
429 RATE_LIMITEDanswer. - An answer over 1 MB.
These answers cost nothing, so running the request again is safe.
Idempotency and the Cache
They solve different problems. Use both.
| Property | Idempotency | Cache |
|---|---|---|
| Answers | Your own first answer | Anyone's recent answer |
| Kept | 24 hours | Per endpoint, minutes to 30 days |
| Needs | A key you send | Nothing |
| Cost | Free | Free |