> For the complete documentation index, see [llms.txt](https://docs.themochi.app/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.themochi.app/troubleshooting-and-safety/idempotency.md).

# Retry writes safely

A **write** changes Mochi data. An **idempotency key** lets Mochi recognize a retry of the same write, so a lost response does not accidentally create the same change twice.

Every public write request requires an `Idempotency-Key` header containing a UUID version 4 (UUID4):

```http
Idempotency-Key: 7ec24839-9134-4f51-9ee6-1e4c9049d9d3
```

## Choose when to create or reuse a key

* Create a new UUID4 for each new change you intend to make.
* Reuse the original key only when retrying the same HTTP method, path, and intended input.
* If the client times out, retry first with the original key. The first request may have completed after the client disconnected.
* Never use a new key merely because the response was lost. That can create a duplicate change.

Mochi keeps successful responses for 24 hours. A recognized retry returns the original status and body and includes:

```http
Idempotent-Replay: true
```

The saved result is also tied to the API key, method, and path. One organization cannot replay another organization's response.

If the same request is still running, Mochi may return `409`. Wait briefly and retry with the same idempotency key. Validation errors and other unsuccessful responses are not saved. Correct those requests before trying again.

For a `409`, timeout, or uncertain write result, follow [Troubleshoot API requests](/troubleshooting-and-safety/diagnose-api-failures.md). Confirm current write operations in the [canonical OpenAPI contract](https://openapi.gitbook.com/o/M0sgy6xKutCblHRqGmE5/spec/mochi-api.json).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.themochi.app/troubleshooting-and-safety/idempotency.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
