Skip to Content

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"
PropertyValue
HeaderIdempotency-Key
Length1 to 255 characters
Kept24 hours
ScopeYour 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.

CaseAnswerDo
The key was used for another request409 CONFLICTUse a new key for a new request
The first request is still running409 CONFLICTWait for Retry-After, then repeat
The key is empty or too long400 INVALID_REQUESTSend 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 5xx answer, such as 502 UPSTREAM_UNAVAILABLE.
  • A 429 RATE_LIMITED answer.
  • 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.

PropertyIdempotencyCache
AnswersYour own first answerAnyone's recent answer
Kept24 hoursPer endpoint, minutes to 30 days
NeedsA key you sendNothing
CostFreeFree

Next Steps