Docs / API reference

Idempotency

Network errors happen. An idempotency key lets you retry a POST request and be sure the action happens only once, so a timeout never leaves you with two pods billing in parallel.

How it works

Send a unique Idempotency-Key header with any POST request, on both the control plane and the runtime host. The first request is processed normally and its response (status code and body) is stored for 24 hours, scoped to your organization. Any repeat of the same key within that window returns the stored response with an extra Idempotent-Replayed: true header, without performing the action again.

$ curl -X POST https://api.apipods.com/v1/pods \
  -H "Authorization: Bearer $APIPODS_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: 5f0c2c1e-8a4b-4f7e-9a61-0d2b7c3e9f14" \
  -d '{"name": "llama-finetune", "gpuTypeId": "NVIDIA_H100_80GB_SXM", "image": "apipods/pytorch:2.9.0-py3.12-cuda12.8.1"}'
Tip: The SDKs generate an idempotency key automatically for every POST and reuse it across their built-in retries. Pass your own key when you retry at a higher level, for example from a job queue.

Rules

  • Keys are any string up to 255 characters. Use a UUID v4.
  • GET and DELETE are idempotent by definition and ignore the header. PATCH and PUT set absolute values, so repeating them is already safe.
  • Reusing a key with a different request body or path returns 409 idempotency_conflict.
  • If the first request with a key is still being processed, a concurrent repeat also returns 409 idempotency_conflict. Wait a moment and retry.
  • Responses with 5xx status codes are not stored, so retrying them with the same key runs the request again. Validation errors (400) are stored.
  • On /run, the same key returns the original job ID instead of queuing a second job.

Conflict response

409 Conflict
{
  "error": {
    "type": "invalid_request",
    "code": "idempotency_conflict",
    "message": "This Idempotency-Key was already used with a different request body.",
    "param": null,
    "requestId": "req_4x8m2k9q7w3tnc"
  }
}