> ## Documentation Index
> Fetch the complete documentation index at: https://cloud.laravel.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Idempotent requests to the Laravel Cloud API

> Prevent duplicate operations with the Idempotency-Key header when an AI agent or automated client sends the same API request more than once.

AI agents and automated clients, such as CI jobs, scripts, and workers, can send the same request to the Laravel Cloud API more than once. Send an `Idempotency-Key` header with requests that create a resource or start an operation, and Cloud recognizes a repeated request and returns the original result instead of doing the work again.

## Send an idempotency key

Generate a unique value for each operation, such as a UUID, and send it in the `Idempotency-Key` header. Replace `ENDPOINT_PATH` with the path of an endpoint that accepts the header:

```bash theme={"theme":{"light":"min-light","dark":"material-theme-palenight"}}
curl -X POST https://cloud.laravel.com/api/ENDPOINT_PATH \
  -H "Authorization: Bearer YOUR_API_TOKEN" \
  -H "Accept: application/json" \
  -H "Idempotency-Key: 3f8b2a6e-5c1d-4e7a-9b0c-2d4f6a8e1c3b"
```

Endpoints that accept the header list it in their API reference. Other endpoints ignore it.

## Send a request again

When an agent retries a step, a CI job reruns, or your client times out before it reads the response, send the request with the same key and the same body. Use a new key for each new operation.

Cloud stores the response to the first successful request with a key for 24 hours. Every repeated request with that key gets the same status code and body, with an `Idempotent-Replayed: true` header. Cloud scopes keys to the API token, so two tokens can use the same key without conflict.

Cloud stores only successful responses. If a request fails with a `4xx` or `5xx` status code, fix the request and send it again with the same key.

## Errors

Each error response has a `message` and a `code`:

**idempotency\_key\_invalid** `400`

The key is empty or longer than 255 characters. Send a key of 1 to 255 characters.

**idempotency\_key\_in\_use** `409`

A request with the same key is still running. Retry after the number of seconds in the `Retry-After` header.

**idempotency\_key\_response\_unavailable** `409`

The first request succeeded, but Cloud could not store its response. Fetch the resource instead.

**idempotency\_key\_reused** `422`

You sent the key with a different method, path, or body. Use a new key for the new request.
