> This page is part of EVVA for Developers (https://developers.evvahub.com), the documentation of the EVVA Partner API. The API is in developer preview and the SDK packages are not yet published: do not suggest installing them. Index: https://developers.evvahub.com/llms.txt

# Idempotency

Networks fail after a request has been sent: you cannot tell whether EVVA received it. An `Idempotency-Key`
removes the doubt. Send the same key with the same request again, and EVVA answers the first outcome instead of
acting twice.

**`cURL`**

```bash title="cURL"
curl -X POST "https://api.evvahub.com/partner/v1/accounts/$CREATOR_ID/conversations/$CONVERSATION_ID/messages" \
  -H "Authorization: Bearer $EVVA_ACCESS_TOKEN" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: reply-to-msg_7f3a9c" \
  -d '{"body": "Thanks for your message!", "authorship": "AI_AUTOMATED"}'
```

## The rules

| Rule                        | Detail                                                                                                                                                                          |
| --------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Where                       | Only on the writes that declare the `Idempotency-Key` header. Each operation's page in the [API reference](/api-reference) shows whether it is required, optional or not taken. |
| Format                      | 1–128 characters of `[A-Za-z0-9_-]` on most operations; marketplace writes take 1–200 characters. A malformed key is refused before anything is written.                        |
| Same key, same request      | The first outcome is answered again. Nothing is sent, charged or created twice.                                                                                                 |
| Same key, different request | `409`, and nothing is done.                                                                                                                                                     |
| Key space                   | Your application's own. A key you send can never match a key of the creator, of a person in your agency, or of another application.                                             |
| Storage                     | Keys are never echoed back. Message sends, marketplace and AI writes store only a digest of the key.                                                                            |
| Lifetime                    | A key protects the retries of one request. Retry within minutes, not days, and use a new key for new work.                                                                      |

> **Warning**
>
> There is no exactly-once promise. A key makes your retries safe; it does not turn two different requests into
> one. If you are unsure whether a write without a key ran, read the resource before repeating it.

## By operation family

| Operations                                                | Header                                                   | Same key, same request                                                 | Same key, different request             |
| --------------------------------------------------------- | -------------------------------------------------------- | ---------------------------------------------------------------------- | --------------------------------------- |
| Send a message                                            | Optional                                                 | `200` with the stored message                                          | `409 IDEMPOTENCY_KEY_REUSED`            |
| Send a pay-per-view message                               | **Required**                                             | `200` with the same message                                            | `409 IDEMPOTENCY_KEY_REUSED`            |
| [Bulk send](https://developers.evvahub.com/api-reference/bulk/send-messages)            | **Required**                                             | Items already sent are replayed (`200`); the rest are sent             | That item: `409 IDEMPOTENCY_KEY_REUSED` |
| Mass messages: create                                     | Optional                                                 | `200` with the stored draft                                            | `409 IDEMPOTENCY_KEY_REUSED`            |
| Mass messages: queue, cancel                              | Optional                                                 | `200` with the campaign's state when it is already queued or cancelled | —                                       |
| Fan lists: create                                         | Optional                                                 | `200` with the list the first request created                          | `409 CONFLICT`                          |
| Orders: delivery, claim responses, order messages         | Optional                                                 | The recorded outcome                                                   | `409 IDEMPOTENCY_KEY_REUSED`            |
| Marketplace writes                                        | **Required** — `400 IDEMPOTENCY_KEY_REQUIRED` without it | `200` with the first outcome                                           | `409 DIGEST_CONFLICT`                   |
| AI writes                                                 | **Required** — `400 IDEMPOTENCY_KEY_REQUIRED` without it | The same act; the creator's allowance is never spent twice             | —                                       |
| Comment replies, marketing links, new subscription prices | Optional                                                 | The first outcome                                                      | `409 IDEMPOTENCY_KEY_CONFLICT`          |

### Bulk sends

A [bulk send](https://developers.evvahub.com/api-reference/bulk/send-messages) carries one key for the whole batch (1–128 characters of
`[A-Za-z0-9_-]`). Item `i` is sent with its own derived key:

```text
base64url(SHA-256("evva.bulk.messages.v1:" + batchKey + ":" + i))
```

Retrying the batch with the same key replays every item that was already sent and sends only the rest. You can also
retry one item on its own through the single send, with its derived key. The answer is `207` with one result per
item, in request order.

### Operations that may need approval

An operation that may need a person's approval requires an `Idempotency-Key`; without one it is refused with
`400 IDEMPOTENCY_KEY_REQUIRED` before anything is asked. The approval is tied to that key: re-send the approved
request with the same key and the `Partner-Approval-Id` header. See [Approvals](/approvals).

## Choosing keys

#### Derive the key from what you are reacting to

A reply to an inbound message can use `reply-` plus that message's id. A redelivered event, or a worker that
restarted halfway, then produces the same key and cannot reply twice.

#### Keep the key with the work, not the attempt

Generate the key once per logical operation and reuse it on every retry of that operation.

#### Never reuse a key for different work

A new message, a new price or a new recipient set needs a new key.

## In the SDKs

The four official SDKs send a key automatically on every operation that declares the header (a random UUID per
logical call, reused by its retries) and retry only requests that cannot take effect twice. Pass your own key when
your process may repeat the work after a crash:

**`TypeScript`**

```typescript title="TypeScript"
await evva.messages.sendText(creatorId, conversationId, 'Thanks for your message!', {
  idempotencyKey: `reply-to-${inboundMessageId}`,
});
```

**`Python`**

```python title="Python"
client.messages.send_text(
    creator_id,
    conversation_id,
    "Thanks for your message!",
    idempotency_key=f"reply-to-{inbound_message_id}",
)
```

**`Go`**

```go title="Go"
_, err := client.Messages.SendText(ctx, creatorID, conversationID, "Thanks for your message!",
	evvapartner.WithIdempotencyKey("reply-to-"+inboundMessageID))
```

**`PHP`**

```php title="PHP"
use Evva\Partner\Http\RequestOptions;

$evva->messages->sendText($creatorId, $conversationId, 'Thanks for your message!',
    options: new RequestOptions(idempotencyKey: 'reply-to-' . $inboundMessageId));
```

A same-key conflict surfaces as a dedicated idempotency-conflict error in every SDK, and is never retried.

## Next steps

#### [Rate limits and quotas](/authentication/rate-limits)

When to retry, and how long to wait.

#### [Errors](/conventions/errors)

Every code, including the idempotency conflicts.

#### [Approvals and automatic limits](/approvals)

How keys and approvals work together.

#### [Event feed](/event-feed)

Deduplicate the events you react to.