---
docId: doc_fc1dbbb37f7e4c40b6ddd26054d04875
title: Retries
description: "Choose the retry count and check which operations are sent only once."
sidebarTitle: Retries
---

# Retries

The SDK retries supported operations after network failures or busy-service responses. Set `maxRetries` to choose how many retries: 2 by default. Calls that could repeat an action are sent once.

## What is retried

| Failure | Retried |
|---|---|
| Network failure, no answer | Yes |
| An attempt that exceeds `timeoutMs` | Yes |
| Status 408, 429, 500, 502, 503, 504 | Yes |
| Any other status, including 409 | No |
| A call you aborted with `signal` | No |

## How long it waits

The first wait is `retryDelayMs` (500 ms). It doubles on each attempt, up to `maxRetryDelayMs` (8 seconds), with jitter. If the answer has a `Retry-After`, the SDK waits at least that long. If `Retry-After` is longer than `maxRetryDelayMs`, it does not wait: it throws the error, with `retryAfterMs` set.

```ts
const platic = new Platic({
  apiKey: process.env.PLATIC_API_KEY!,
  maxRetries: 4,
  retryDelayMs: 1_000,
  maxRetryDelayMs: 15_000,
});

// Fail fast on one call
await platic.agents.get(agentId, { maxRetries: 0 });
```

`maxRetries` is an integer from 0 to 10. When the retries run out, you get the last error: an API error class, `PlaticTimeoutError` or `PlaticConnectionError`. `error.request.attempts` says how many times the request was sent.

<span id="changes-are-safe-to-retry"></span>

## How duplicates are avoided

For operations that support idempotency, the SDK generates one `Idempotency-Key` per call (`platic-sdk-` and a random UUID). It keeps the key for every attempt so the API recognizes the same request, creates the resource once and completes unfinished copies or files without duplicating them. See [Idempotency](/api-reference/idempotency).

These operations are retried without a key because repeating them keeps the same result:

- Changing a contact, channel or web chat.
- Deleting a tag or archiving an escalation.
- Changing, taking or closing a case.
- Changing or disconnecting an AI provider.
- Skipping or completing an agent template's pending items.
- Enabling, pausing, testing or querying a database connection.

<span id="conversation-actions"></span>

### Conversation actions

Every conversation action (`update`, `tags`, `assignees`, `pause`, `resume`, `wait`, `finish`, `archive`, `reopen`, `setAgent`, `setSpam` and `bulk`) is sent with one `Idempotency-Key`, the same on every attempt. A retry after a network failure, a timeout, `503 ACTION_FAILED` or `503 CONTINUE_FAILED` returns the first outcome, with `meta.replayed: true`: `resume` never makes the agent reply twice and `bulk` never acts twice on a conversation.

The SDK also asks again, up to `maxRetries` times, after two short-lived conflicts: `409 IDEMPOTENCY_IN_PROGRESS` (an earlier attempt of the same call is still running) and, for `resume` and `wait`, `409 AGENT_STOPPING` (a previous reply is still stopping right after a pause). Other `409` answers are thrown at once.

Conversation reads and searches only read, so they are retried like any other read, `503 SEARCH_UNAVAILABLE` included.

## Calls that are sent once

The SDK does not retry the following calls: repeating them could duplicate an action or a delivery. If you lose the response, look for the result before calling again.

- Chat turns, sending a message, a template or a campaign, and every action on a comment.
- Creating, changing or deleting a template.
- Testing a custom API.
- Creating, changing or deleting a database connection.
- Starting a channel connection and choosing what it installs.
- Creating a web chat, a campaign, a tag or a custom field.
- Deleting an agent, a secret, a campaign or a custom field.
- Rotating or revoking a secret, and disconnecting an agent's tool.
- Estimating an eval, and suggesting a file's metadata.
- Adding a note to a case, changing an escalation, and installing an agent template.
- Connecting or verifying an AI provider's key.

Publishing, replying and replying privately to a comment take a `clientToken` (a UUID). Send the same one again and the API returns the first result instead of publishing twice. The SDK leaves the token to you.

## After a connection error

`PlaticConnectionError` means no answer arrived. The change may have been applied. Read the resource, then decide:

```ts
import { PlaticConnectionError } from "platic-sdk";

try {
  await platic.chat.send({ agentId, message: "Hello" });
} catch (error) {
  if (error instanceof PlaticConnectionError) {
    // A chat turn is never retried: check the chat before sending again.
    const chats = await platic.chat.list({ limit: 1 });
    console.log(chats.data[0]);
  } else {
    throw error;
  }
}
```

## Next steps

- [The client](/sdk/client): timeouts and the retry options.
- [Errors](/sdk/errors)
- [Idempotency in the API](/api-reference/idempotency)
