Skip to content
Laravel Packagev13.xMIT License0+ downloadsAI Ready · Laravel Boost

API Idempotency: Retry safely, run once

API Idempotency adds Idempotency-Key handling to any Laravel route with one call: ->idempotent(). The first request reserves its key atomically and runs; retries replay the stored response, concurrent duplicates wait their turn, and uncertain outcomes stay locked instead of running twice. It is AI ready: php artisan boost:install teaches your coding agent the whole package through Laravel Boost.

$composer require pharaonic/laravel-api-idempotency

Compatibility

Each line is released for the versions in its row, read from that release's composer.json. Pick the line that matches your project; a combination not listed isn't supported. Find the right line of every package for your project.

LineLatest releasePHPLaravelStatusDocs
v13.xv13.0.0 Nov 23, 20268.3 – 8.513Current Docs: Read the v13.x docs
v12.xv12.0.0 Nov 23, 20268.2 – 8.512Maintained Docs: Read the v12.x docs
v11.xv11.0.0 Nov 23, 20268.2 – 8.411MaintainedLaravel 11 no longer gets security fixes Docs: Read the v11.x docs
v10.xv10.0.0 Nov 23, 20268.1 – 8.310MaintainedLaravel 10 no longer gets security fixes Docs: Read the v10.x docs
v9.xv9.0.0 Nov 23, 20268.0 – 8.29MaintainedLaravel 9 no longer gets security fixes Docs: Read the v9.x docs
v8.xv8.0.0 Nov 23, 20268.0 – 8.18MaintainedLaravel 8 no longer gets security fixes Docs: Read the v8.x docs
v7.xv7.0.0 Nov 23, 20268.07MaintainedLaravel 7 no longer gets security fixes Docs: Read the v7.x docs
v6.xv6.0.0 Nov 23, 20268.06MaintainedLaravel 6 no longer gets security fixes Docs: Read the v6.x docs

Maintenance

Latest release
v13.0.0
Nov 23, 2026 (21 hours ago)
Released lines
8
documented lines with a release; see compatibility
CI on develop
Tests running
latest run Nov 23, 2026

From the package's releases and its GitHub Actions. A passing run means the test suite passed on develop, on every PHP version it supports; it isn't a security review, and each release line has its own runs on GitHub. Checked hourly.

A quick look

Mark a route idempotent; clients send an Idempotency-Key header.

routes/api.php
1use App\Http\Controllers\OrderController;
2use App\Http\Controllers\PaymentController;
3use Illuminate\Support\Facades\Route;
4 
5Route::middleware('auth:api')->group(function () {
6 Route::post('orders', [OrderController::class, 'store'])->idempotent();
7 
8 // Keep payment replays for 7 days.
9 Route::post('payments', [PaymentController::class, 'store'])
10 ->idempotent(ttl: 604800);
11});
Key Features

Everything a retry-safe API needs

One route macro, a migration, and your POST endpoints survive retries, double clicks and flaky networks.

One Route Macro

Route::post(...)->idempotent() keeps the fluent chain and works with groups, apiResource() and route:cache.

Atomic Reservation

A unique insert on MySQL, MariaDB, PostgreSQL or SQLite, or a Lua script on Redis. Two simultaneous requests never both run.

Exact Replay

Retries get the stored status, body and allow-listed headers, plus Idempotency-Replayed: true. Cookies never replay.

Request Fingerprints

Built on pharaonic/php-fingerprint. Key order does not matter; types and list order do. Reusing a key for another request is a 409.

Scoped Per Principal

Keys belong to the authenticated user or your own tenant resolver, so one client never sees another's response.

Fail Closed

Crashes, 5xx responses and store outages never lead to a silent second run. Unknown outcomes stay locked until you decide.

Events and Quiet Logs

Four events for reserved, replayed, rejected and unresolved requests. Logs never carry the client's key, the user or the body.

Safe Pruning

php artisan idempotency:prune counts first and deletes with --apply, keeping unresolved records until you ask.

AI Ready

Ships Laravel Boost resources: php artisan boost:install teaches your coding agent the macro, scopes, outcomes and error codes.

FAQ

API Idempotency Questions

Quick answers about installing and using API Idempotency.

What is API Idempotency?

Opt-in HTTP idempotency for Laravel routes. Add ->idempotent() to a route and retried requests with the same Idempotency-Key replay the stored response instead of running twice. It's a free, open-source Laravel package by Pharaonic.

How do I install API Idempotency?

Run composer require pharaonic/laravel-api-idempotency in your project's root directory. For the default database store, publish the migration with php artisan vendor:publish --tag=api-idempotency-migrations and run php artisan migrate.

What does API Idempotency require?

The latest release requires PHP 8.3 – 8.5 and Laravel 13.

Does it guarantee exactly-once execution?

No package can. It guarantees that a key is never reserved twice at the same time and that an uncertain outcome is never run again automatically. For payments, also use a unique business reference and your payment provider's own idempotency key.

Database or Redis?

Both reserve keys atomically. The database store is the default and needs only the migration; Redis expires records by itself and suits high traffic. Switch with IDEMPOTENCY_STORE=redis.

What happens when a client reuses a key with a different body?

The request is refused with 409 and the code idempotency_key_conflict, and your route does not run.

Is API Idempotency free to use?

Yes. API Idempotency is open source under the MIT license, so you can use it in personal and commercial projects.

Where can I find the API Idempotency documentation?

Read the API Idempotency documentation for setup, configuration, and usage examples.

How do I report a bug or contribute to API Idempotency?

Open an issue or a pull request on GitHub, ask in GitHub Discussions, or chat with us on Discord.

Ready to dig in?

Read the full documentation for installation, configuration, scopes, fingerprints, the database and Redis stores, failure recovery, error codes, events and real-world examples.