Skip to content

Idempotency

SendAPI supports idempotent requests on all POST endpoints via the Idempotency-Key header. This lets you safely retry failed requests without the risk of duplicate side effects (sending a message twice, creating two sessions, etc.).

How It Works

  1. Include a unique Idempotency-Key header (UUIDv4 recommended) in your POST request.
  2. If the request succeeds, SendAPI caches the response for 24 hours using this key.
  3. Any subsequent request with the same key within the 24-hour window returns the cached response immediately — no duplicate action is taken.

Example

bash
curl -X POST https://sendapi.co/v1/whatsapp/send \
  -H "Authorization: Bearer sk_live_123456789" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: f47ac10b-58cc-4372-a567-0e02b2c3d479" \
  -d '{
    "session_id": "sess_01H8BKF...Z2T",
    "to": "+447700900000",
    "type": "text",
    "text": { "body": "Your order is confirmed!" }
  }'

If a network timeout occurs before you receive the response, retry the exact same request with the same Idempotency-Key. SendAPI will:

  • Return the original response if it already succeeded
  • Execute the request normally if it had not yet been processed

Generating Keys

Use UUIDv4 generation:

javascript
const { randomUUID } = require('crypto');
const idempotencyKey = randomUUID();
python
import uuid
idempotency_key = str(uuid.uuid4())
php
$idempotencyKey = (string) \Illuminate\Support\Str::uuid();

Idempotency Key Scope

RuleDetail
TTL24 hours from first request
ScopePer API key — same key used by two different API keys are independent
Body mismatchIf you send a different request body with the same key, a 409 Conflict is returned
Supported methodsPOST only — GET, PUT, and DELETE are naturally idempotent

SDK Support

All official SendAPI SDKs automatically generate and attach Idempotency-Key headers on POST requests. You don't need to manage this manually when using an SDK.

Released under the MIT License.