# DurableIdempotencyKeyHandler

Package: [Microsoft.Orleans.Durable.Http](/orleans/docs/api/csharp/microsoft.orleans.durable.http/) 10.0.0-alpha.1

[Source](https://github.com/dotnet/orleans/blob/4e887e9c914a2f2647fb3c81de963511521dd9cb/src/Orleans.Durable.Http/DurableIdempotencyKeyHandler.cs#L33)

```csharp
public sealed class DurableIdempotencyKeyHandler : DelegatingHandler
```

Adds an `Idempotency-Key` header which identifies the running durable task to each request that a durable task sends, so every attempt and replay of the task sends the same key.

## Remarks

The key is a hash of the service, the grain which runs the task, the task's identifier, and its [DurableTaskContext](/orleans/docs/api/csharp/microsoft.orleans.durable.abstractions/orleans.durable.tasks.durabletaskcontext/): 43 URL-safe base64 characters which are equal for every attempt and replay of one run of the task, and distinct for every other task, including a later run of the same task identifier, whose earlier keys a server may still hold. A step which sends one request, such as `DurableTask.Run(ct => client.PostAsJsonAsync(...))`, therefore makes that request idempotent at servers which honor the header, including a retry of the step after a failure or a deactivation. A step which sends several requests to different operations gives each its own step, such as with [DurableTaskExtensions](/orleans/docs/api/csharp/microsoft.orleans.durable.abstractions/orleans.durable.tasks.durabletaskextensions/), or sets their keys itself.

A request with a safe method, such as `GET`, a request which already carries the header, and a request which code outside a durable task sends are unchanged. Register the handler before handlers which retry requests, so their retries carry the key.

## Constructors

- [DurableIdempotencyKeyHandler(IGrainContextAccessor, IOptions&lt;ClusterOptions&gt;)](/orleans/docs/api/csharp/microsoft.orleans.durable.http/orleans.durable.http.durableidempotencykeyhandler/constructors/constructor-orleans-runtime-igraincontextaccessor-microsoft-extensions-options-i-12fff5a5/)

## Methods

- [Send(HttpRequestMessage, CancellationToken)](/orleans/docs/api/csharp/microsoft.orleans.durable.http/orleans.durable.http.durableidempotencykeyhandler/methods/send-system-net-http-httprequestmessage-system-threading-cancellationtoken-9c8feab0/)
- [SendAsync(HttpRequestMessage, CancellationToken)](/orleans/docs/api/csharp/microsoft.orleans.durable.http/orleans.durable.http.durableidempotencykeyhandler/methods/sendasync-system-net-http-httprequestmessage-system-threading-cancellationtoken-0e9d6619/)
