---
docId: doc_0d8d5f4f25394b339e9317158eb13853
title: Idempotency
description: "Retry a request with the same key to avoid duplicating the change."
---

<script>
  import { Ways, Collapsible } from '$lib/components';
</script>

# Idempotency

A request may have succeeded even if you did not receive the response. To retry without duplicating the change, send `Idempotency-Key` on the first request and keep that key for retries. This works on [supported operations](#where-it-applies).

<span id="how-it-works"></span>

1. Generate a key for the operation; a UUID meets the formats accepted by supported routes.
2. If the connection drops, the request times out or you receive a `5xx`, repeat it with **the same key and the same content**.
3. Use a new key for a different operation. Reusing it with different content returns `409`.

`GET` requests can be repeated and do not need a key. See [Errors](/api-reference/errors) to decide when to retry.

## Example

The SDK generates the key and keeps it during its retries. With REST API, send it in the header:

<Ways tabs="api,sdk">
<Ways.Way name="api">

```bash
curl https://api.platic.ai/v1/agents \
  -H "Authorization: Bearer $PLATIC_API_KEY" \
  -H "Idempotency-Key: 5f1c7a52-3d0e-4b8a-a6f4-2c5e8d1b7a90" \
  -H "Content-Type: application/json" \
  -d '{ "name": "Sales" }'
```

</Ways.Way>
<Ways.Way name="sdk">

```ts
// The SDK adds an Idempotency-Key to every change and reuses it on each retry
const agent = await platic.agents.create({ name: "Sales" });
```

</Ways.Way>
</Ways>

## Where it applies

| Operation | What the key does |
|-----------|-------------------|
| Changes to agents (create, update, publish, copy, escalations…) | A repeat returns the stored result. A key reused with other content answers `409` with `details.code: "IDEMPOTENCY_KEY_REUSED"` |
| [Install an agent template](/api-reference/agent-templates/install) | The whole request becomes repeatable |
| [Create a file](/api-reference/files/create) | After a network cut, the same request returns the same `fileId` and `uploadId` without duplicating the file |
| [Upload a file](/api-reference/files/upload) | On a repeat, the second response carries `upload: null`: the `sessionUri` address is delivered only once |
| Webhooks ([create](/api-reference/webhooks/create), [update](/api-reference/webhooks/update), [test](/api-reference/webhooks/test), [delete](/api-reference/webhooks/delete)) | Up to 60 characters from `A-Z a-z 0-9 _ . : -`. A key reused with another body answers `409` with `details.code: "REQUEST_ID_CONFLICT"` |
| [Conversation actions](#conversations-v2) (update, tags, assignees, pause, resume, wait, finish, archive, reopen, agent, spam and bulk) | 1 to 255 visible ASCII characters. A repeat answers the first outcome with `meta.replayed: true` and does not run the action again. A key reused with another body answers `409 IDEMPOTENCY_KEY_REUSED`; while the first request is still running, `409 IDEMPOTENCY_IN_PROGRESS`. Keys are kept for a day |
| [Reply to a post](/api-reference/posts/reply) | The key must be a UUID, or the answer is `400`. A repeat doesn't publish twice. While the first is still publishing, the answer is `409` `COMMENT_PUBLISH_IN_PROGRESS`; if an earlier attempt couldn't be confirmed, `409` `COMMENT_PUBLISH_RESULT_UNKNOWN`: check the [thread](/api-reference/posts/threads) before retrying |

<span id="conversations-v2"></span>

## Conversation actions

Every action on a V2 conversation takes an optional `Idempotency-Key`. Send one on [resume](/api-reference/conversations/resume) and [bulk](/api-reference/conversations/bulk) in particular: without it, a retry after a lost answer can make the agent reply twice, or run the action again on every conversation.

```bash
curl -X POST https://api.platic.ai/v2/conversations/$CONVERSATION_ID/resume \
  -H "Authorization: Bearer $PLATIC_API_KEY" \
  -H "Idempotency-Key: 9b2f4c1e-7a35-4d0b-8e6f-1c3a5b7d9e20" \
  -H "Content-Type: application/json" \
  -d '{ "instruction": "Offer the Monday 10:00 appointment." }'
```

- The key is bound to the workspace, the credential, the action, the conversation and the body. A repeat with the same key and body answers the first outcome, with `meta.replayed: true`; nothing is written, sent or notified again.
- `fields` and `include` don't count as part of the body: a repeat can ask for other fields.
- An action whose result already holds (pausing a paused conversation) answers `meta.changed: false` even without a key.
- A `503 ACTION_FAILED` or `503 CONTINUE_FAILED` has `details.retryable: true`: repeat with the same key.

The SDK sends a key on every action and keeps it for its retries. MCP tools build it from the `requestId` argument.

<span id="versions"></span>

### Don't overwrite a newer change

Reads and actions return `meta.resourceVersion`, the conversation's version. Send it back in `If-Resource-Version` on [update](/api-reference/conversations/update) and when replacing the [tags](/api-reference/conversations/tags) or the [assignees](/api-reference/conversations/assignees) (`PUT`). If the conversation changed since that version, the answer is `412 VERSION_MISMATCH` with `details.currentVersion`, and nothing changes: read it again, decide again and repeat. Without the header, the last write wins. Adding or removing tags and assignees (`PATCH`) doesn't need it.

<Ways tabs="api,sdk">
<Ways.Way name="api">

```bash
curl -X PUT https://api.platic.ai/v2/conversations/$CONVERSATION_ID/tags \
  -H "Authorization: Bearer $PLATIC_API_KEY" \
  -H "If-Resource-Version: $RESOURCE_VERSION" \
  -H "Content-Type: application/json" \
  -d '{ "tags": ["vip", "billing"] }'
```

</Ways.Way>
<Ways.Way name="sdk">

```ts
const { data, meta } = await platic.conversations.get(conversationId, { fields: ["tags"] });
await platic.conversations.tags.set(
  conversationId,
  { tags: [...(data.tags ?? []), "vip"] },
  { expectedVersion: meta.resourceVersion },
);
```

</Ways.Way>
</Ways>

In the SDK and in MCP tools the version goes in `expectedVersion`; a stale one throws `PreconditionFailedError` in the SDK. See [SDK errors](/sdk/errors).

<span id="notes"></span>

<Collapsible summary="The API’s internal retry">

If you do not send a key, the API retries an agent change once when the service returns `503`. It generates a key for that internal retry. This key does not protect a new request you make: send your own key from the first attempt.

</Collapsible>
