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
- Include a unique
Idempotency-Keyheader (UUIDv4 recommended) in yourPOSTrequest. - If the request succeeds, SendAPI caches the response for 24 hours using this key.
- 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
| Rule | Detail |
|---|---|
| TTL | 24 hours from first request |
| Scope | Per API key — same key used by two different API keys are independent |
| Body mismatch | If you send a different request body with the same key, a 409 Conflict is returned |
| Supported methods | POST 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.