Idempotency
Retry tool executions and creates safely with the Idempotency-Key header: rules, replays and conflicts.
Networks fail at the worst moment: your request reached the API, the tool ran, and the response
never came back. An Idempotency-Key lets you retry such a request without running it twice.
How it works
Send a key you choose with the request. The first request with that key runs normally and its
response is stored for 24 hours. A retry with the same key and the same request does not run
again: it gets the stored status and body, plus the header Idempotent-Replayed: true.
curl -X POST "https://<your-host>/api/v1/tools/GITHUB_CREATE_ISSUE/execute" \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: create-issue:ticket-4821" \
-d '{"user_id":"user_123","arguments":{"owner":"acme","repo":"widgets","title":"Bug report"}}'A replayed execution creates no new log entry and does not count toward your usage.
Supported routes
| Route | What a replay protects against |
|---|---|
POST /api/v1/tools/{slug}/execute | Running a tool (an email, an issue) twice |
POST /api/v1/connected_accounts | Creating two connection attempts |
POST /api/v1/triggers | Creating the same trigger twice |
Other routes ignore the header. Creating API keys and MCP user URLs is excluded on purpose: their responses contain a secret that is only stored hashed, and a stored replay would keep a copy.
Key rules
- 1 to 255 printable ASCII characters, no spaces. Anything else returns
400 validation_errorwith the problem onfieldErrors["Idempotency-Key"]. The SDK checks the key before sending and throwsToolwireErrorwith codeinvalid_idempotency_key. - Keys are scoped to the project: two API keys of one project share them, other projects never see them.
- Use one key per logical operation, for example
create-issue:<your ticket id>or a UUID you store with the job. Never reuse a key for a different request.
Outcomes
| Situation | Response |
|---|---|
| First request | Runs normally |
| Same key, same request, first one finished | The stored status and body, Idempotent-Replayed: true |
| Same key, same request, first one still running | 409 idempotency_in_progress with Retry-After: 1 |
| Same key, different body, path or query | 422 idempotency_key_reused |
| The first response was larger than 1 MB | 409 idempotency_replay_unavailable, find the result in the logs |
| More than 24 hours later | Runs again as a new request |
Responses are stored only when the outcome is final: 2xx and 4xx other than 409 and 429.
A 5xx, a 409 (for example connection_busy) or a 429 is not stored, so retrying with the same
key runs the request again. Stored responses are encrypted.
With the SDK
tools.execute, connectedAccounts.initiate and triggers.create send a fresh key on every
call by default (when the runtime has crypto.randomUUID), and the SDK reuses it for its own
retries. Each takes { idempotencyKey } as its last argument. Pass your own key when you retry
across processes or restarts:
// One key per logical operation. Reuse it when you retry the same call yourself.
const idempotencyKey = `create-issue:${ticketId}`;
const result = await toolwire.tools.execute(
"GITHUB_CREATE_ISSUE",
{ userId: "user_123", arguments: { owner: "acme", repo: "widgets", title: "Bug report" } },
{ idempotencyKey },
);The provider adapters (Claude, OpenAI, Vercel AI SDK, LangChain) send a new key for each tool call, so a retried model turn does not run the same tool call twice. See Rate limits for which errors the SDK retries.

