Skip to main content

Idempotency Keys for Resilient API Integrations: How-To Guide

A reused idempotency key is one documented cause of HTTP 409. This guide shows how to read the response, look for the original session when the ID is missing, and avoid a duplicate verification. Full KYC costs $0.33.

Idempotency Keys for Resilient API Integrations: How-To Guide

Contents

In this guide

Jump to the part you need.

This guide is for developers who need to avoid duplicate verification sessions after a failed or ambiguous request. It shows how to use an idempotency key where an endpoint documents support, how to read our 409 response, and how to look for the original session when the response and the session ID are both missing. A full KYC check costs $0.33. The caveat: we do not document idempotency support for every endpoint.

Last updated: November 26, 2026. Prices checked against the live Didit price feed on November 26, 2026.

Idempotency in a Didit integration: the central operational questions
What you observeWhat to do nextWhere it comes from
Request succeeded and you have a session IDStore the ID, then read GET /v3/session/{id}/decision/Sessions API overview
HTTP 409 with an error codeInspect the code. If you already have the session ID, reload the stateAPI errors
HTTP 409 without an error codeIf you have no session ID, treat the outcome as unresolvedAPI errors
Middleware HTTP 429Wait at least Retry-After, then use capped backoff with jitterRate limiting
Timeout or 5xx and no session IDThe write outcome is unknown. Do not create another session until you confirm itAPI errors
Published verification pricesFull KYC $0.33 per completed check. KYB from $2.00 per companyLive price feed, November 26, 2026

Start free in the sandbox at business.didit.me (no sales call). For developers, connect the Didit MCP server to an AI assistant through didit.me/developers/mcp. The technical entry point is the Sessions API overview, the matching product page is User Verification, and every unit price is on didit.me/pricing.

What an idempotency key does, and what Didit documents

An idempotency key identifies one logical operation. When an endpoint documents support, the client sends the same key with every attempt, so the server can tell a retry from a new request. We list a reused Idempotency-Key as one documented example of HTTP 409 in our API errors reference. That is a cause of a conflict, not proof that every endpoint accepts the header.

Use same-key retries only where the endpoint explicitly documents support. For session creation, status updates, uploads, batch endpoints and other writes, check the endpoint reference first. If support is not documented, do not present the header as a Didit guarantee.

What the key does not do:

  • It does not validate a payload. A 400 for a missing workflow_id is still a 400 on the next attempt.
  • It does not merge two different keys. Changing the key removes the retry association provided by the original key. Other endpoint constraints may still reject the write.
  • It does not replace webhook deduplication. Key your handler on event_id.
  • It does not by itself recover a session ID you never received.

vendor_data is your identifier for the entity, such as user-42. It is an entity reference, not proof that an operation is unique.

Prerequisites

  • A Didit application and API key. Newly issued keys start with sk_test_ for sandbox or sk_live_ for live, followed by 43 URL-safe characters. Older keys may have no prefix and remain valid.
  • The workflow_id of the workflow you want to run. The workflow type decides whether the session is a User Verification (KYC) session or a Business Verification (KYB) session.
  • Your entity reference for vendor_data, such as user-42.
  • curl or another HTTP client, and access to the Didit Business Console to confirm session state.

Step-by-step: create a session and handle an ambiguous result

  1. Get a sandbox key. In the Business Console open Developers, then API keys, and copy the sandbox application key. You can also create one programmatically: POST https://apx.didit.me/auth/v2/programmatic/register/ emails a 6-character code, and POST https://apx.didit.me/auth/v2/programmatic/verify-email/ returns sandbox_application.api_key. Keep the key server-side, never in a browser or mobile bundle.

  2. Check endpoint support before you rely on a key. Read the endpoint reference and the API errors page. A reused key is one documented cause of 409. If the endpoint does not document idempotency support, do not add the header as if Didit guarantees it.

  3. Create the session exactly as API Authentication shows. The documented create call is POST /v3/session/ on the verification host, authenticated with x-api-key. This is the same curl shown in API Authentication, with no extra idempotency header:

    curl -X POST https://verification.didit.me/v3/session/ \
      -H "x-api-key: $DIDIT_API_KEY" \
      -H "Content-Type: application/json" \
      -d '{"workflow_id":"<WORKFLOW_ID>","vendor_data":"user-42","callback":"https://myapp.com/return"}'
  4. If the response is lost, look for the original session before anything else. A timeout or a 5xx can leave the result of a write unknown. If you have the session_id, retrieve the decision with GET /v3/session/{id}/decision/. If the session ID is missing, check the Didit Business Console, call GET /v3/sessions/ as documented in the Sessions API overview, or look for a verified session webhook. Compare the available workflow, the entity reference and the creation time. vendor_data is an entity reference that can match several sessions, so it does not prove which session is yours. If you can confirm a match, retrieve the decision using its session_id. If the match remains uncertain, keep the operation unresolved.

  5. Handle a 409 by reading the status and the code. A reused key is one documented cause. Inspect the error code when it is present. If you already have the session ID, reload the state with GET /v3/session/{id}/decision/. If the original response was lost and you have no ID, the outcome is unresolved. Do not mint a new key to get past the conflict.

  6. Treat a middleware 429 separately. For a middleware 429, use Retry-After as the minimum delay and apply capped backoff with jitter. The rate limiting reference gives the 5s, 10s, 20s and 40s example with a small attempt ceiling. For other 429 responses, follow the endpoint's error contract.

  7. Make the webhook handler idempotent. Read the raw body before parsing. Verify X-Signature-V2 by computing HMAC-SHA256 over sorted, Unicode-preserved canonical JSON and comparing signatures in constant time. Check abs(now - X-Timestamp) <= 300 seconds. The current secret verifies X-Signature-V2. After a destination secret is rotated, the replaced secret verifies X-Signature-V2-Previous, which is sent for 24 hours after the rotation; accept a valid match on either and keep the timestamp freshness check. Then apply the event keyed on event_id, return 2xx promptly and update state idempotently. See the webhook reference.

  8. Keep review boundaries outside retries. "In Review" requires a human decision. A reviewer may act through the Console or the documented PATCH /v3/session/{id}/update-status/ API. Use the webhook status and read the decision object when present. See verification statuses and the webhook reference. Nothing in an idempotency key moves a session to "Approved".

Expected output

A successful create returns a session object. The fields you rely on include session_id, session_kind, session_url, status, workflow_id and vendor_data. Status values are exact and case-sensitive, as listed in the verification statuses reference.

{
  "session_id": "...",
  "session_kind": "user",
  ...
}
A session overview with its warnings in the Didit Business Console
After a test run, use the console to confirm the session row, its status and any warnings.

Inputs and outputs

What you send and what you read back
ItemDirectionExampleWhy it matters for retries
x-api-keyInput, headersk_test_...A wrong or expired key answers 401. Fix it before retrying
Idempotency-KeyInput, header, only where documentedA client-generated operation IDLets an endpoint that documents support recognise attempts. It is not a Didit-wide guarantee
workflow_idInput, bodyUUID of the workflowMust not change between attempts
vendor_dataInput, bodyuser-42Your entity reference. It is not proof of operation uniqueness
metadataInput, bodyFree-form JSONUse it for analytics tags or a schema version, not the key
callbackInput, bodyYour return URLUse the same value on every attempt
session_idOutputUUIDStore it when you see it. It is how you recover the decision
event_idOutput, webhookUUIDYour deduplication key on the webhook side

Failure cases and recovery

Didit status codes, what they mean for a retry, and what to do
StatusMeaning in this flowRetryRecovery
400A field failed validation, or on session creation an ordinary insufficient-credit responseAfter fixing or topping upFix what the body names, or add credit
401Key wrong, malformed, revoked or expiredAfter fixingIssue or fetch a valid key
402A check could not be paid for, as in some standalone API families such as bank account checkAfter topping upAdd credit
403No key, a scoped key without access, an IP outside the key list, or a low balance on most standalone APIs. On a contract, session create can return contract_billing_suspendedAfter fixingRead the body, then adjust the key, the balance or the billing state
404No such resource, or the session is outside the key's workflow or status limitsNoCheck the ID and the key scope
409A conflict with current state, for example a reused Idempotency-Key or a step that already ranDepends on codeRead code. If you have the session ID, reload state
410The session or invitation expiredNoCreate a replacement only when that is intended
415The body is not JSONAfter fixingSend Content-Type: application/json
429A rate limit or quota was reachedYes, after waitingFor a middleware 429, use Retry-After as the minimum delay. For other 429 responses, follow the endpoint contract
500, 502, 503Unexpected error, dependency error, or a temporary failure such as query_timeout. A timed-out session create or a 5xx can leave the outcome unknownOnly after you reconcile the original writeRead code when present, then reconcile the original write before sending another create, unless the endpoint explicitly documents a safe retry for that request. If the documented retry uses an idempotency key, reuse the original key and payload
403 with application_deletedThe key's application was deletedNoUse a key from an application that exists

Error bodies do not share one envelope, and a 500 may carry no JSON at all, so parse defensively. This snippet is from the Didit error reference:

const raw = await response.text();
let body = {};
try {
  body = JSON.parse(raw);
} catch {
  // A 5xx response may not be JSON: rely on response.status.
}
const code = body.code ?? null;
const message = body.detail ?? body.error ?? (Array.isArray(body) ? body[0] : raw);

A timeout or 5xx can leave the result of a write unknown, so reconcile the original write before sending another create, unless the endpoint explicitly documents a safe retry for that request. If the documented retry uses an idempotency key, reuse the original key and payload. If you have a session ID, retrieve the decision. If you do not, look for the original session in the Didit Business Console or through GET /v3/sessions/. Treat the operation as unresolved until you can confirm its outcome, and do not create another session in the meantime.

Sandbox checks and what to record

Run these checks in the sandbox before using a live key.

Sandbox checks for a Didit session integration
TestHow to simulateWhat to record
Confirmed successSend the documented create callThe status, any error code and the session_id. Confirm the session in the console
Lost response after request sendKill the client after the request is sent and before the response is readThe observed status, any error code and any session ID. Verify session state through the console or a known session ID
409 observationOnly on an endpoint that documents idempotency support, send the same key twiceThe observed status, any error code and any session ID. Treat replay observations as test results only
Middleware 429Simulate a middleware 429 with a Retry-After headerWhether the client waits at least Retry-After, then backs off with jitter
5xx with no JSON bodyHave a proxy return a non-JSON 500The parser falls back to the status code, and the client checks the outcome before another create
Duplicate webhookDeliver the same event_id twiceThe handler applies the status once and returns 2xx promptly

If you test the real throttle instead of a simulated one, the generic write limit is 300 requests per minute and the session-create scope is 600 per minute. The first scope to exceed its counter returns 429.

The sandbox is free on every plan and every check is mocked, so the checks above cost nothing. On live keys, billing is per completed check from prepaid credit. A full KYC check is $0.33: ID document verification $0.15, passive liveness $0.10, face match 1:1 $0.05, and device and IP analysis $0.03. KYB is priced by country and data tier from $2.00 per company, with each owner or officer taking a linked full ID check and person AML. The docs pricing page notes that some no-match database lookups and retries are billable, so read it before you assume every retry is free.

How Didit billing works: credits, auto-recharge and volume discounts
Charges are based on completed checks, so a duplicate session adds cost only when its checks complete.

Worked cost example

Take 5,000 intended KYC checks a month with AML screening on each, at list prices. KYC: 5,000 x $0.33 = $1,650.00. AML: 5,000 x $0.20 = $1,000.00. Total: $1,650.00 + $1,000.00 = $2,650.00. Together, full KYC and AML screening cost $0.53 per completed pair at list prices, since $0.33 + $0.20 = $0.53.

Now suppose 1.5% of 5,000 intended sessions each yield one duplicate and all 75 duplicates complete both checks. The added list-price usage is 5,000 x 0.015 x ($0.33 + $0.20) = 75 x $0.53 = $39.75. Charges are based on completed checks. A key can prevent a duplicate session only where the endpoint documents idempotency support. It does not guarantee those savings by itself.

On Scale the 10% discount applies to Didit prices: full KYC $0.297 and AML $0.18, so 5,000 x ($0.297 + $0.18) = 5,000 x $0.477 = $2,385.00. The difference against list is $2,650.00 - $2,385.00 = $265.00 a month. Scale itself is $299 a month with $350 of monthly credit, so model the credit and the top-up separately on the pricing page.

Use Didit with MCP from an AI assistant
Connect the Didit MCP server to an AI assistant when a coding agent is writing the integration.

Sources

Next step: open the sandbox at business.didit.me, create a test session, and record the status, any error code and any session ID. Confirm the session in the console before creating another. No sales call is needed to start.

Try it

Try this in the sandbox

Run the check this guide describes, free.

ID Verification

The product this post is about, taken from its topic. Run it free in the sandbox.

$0.15 per checkStart free

Author

Alejandro Rosas

Co-founder and CTO

Alejandro Rosas

Alejandro Rosas

Co-founder and CTO

About Didit

Questions

Frequently asked questions

What is an idempotency key in an API integration?

An idempotency key is a client-generated identifier for one logical operation, sent with attempts at that operation when an endpoint documents support. The idea is that the server can tell a retry from a new request. We list a reused Idempotency-Key as one example cause of HTTP 409 in our API errors reference. It does not establish support for every endpoint.

Does Didit support idempotency keys on session creation?

The documented POST /v3/session/ example does not use an Idempotency-Key header. Check the reference for the specific endpoint before relying on same-key retries. Our API errors reference only lists a reused key as one possible cause of 409. Use same-key retries only where the endpoint explicitly documents support. Otherwise, treat the header as undocumented for that call.

What should I do after a 409 from Didit?

A reused key is one documented cause of HTTP 409. Read the HTTP status and inspect the error code when present. If you already have the session ID, retrieve the decision with GET /v3/session/{id}/decision/. If the original response was lost and you have no ID, treat the outcome as unresolved.

How do I identify a session after a lost response?

Use a session ID you already recorded, check the Didit Business Console, call GET /v3/sessions/ or look for a verified session webhook. Compare the workflow, the entity reference and the creation time, because vendor_data can match several sessions. If you can confirm a match, call GET /v3/session/{id}/decision/ with its session_id. If the match stays uncertain, leave the operation unresolved.

When should I create a new verification session?

Create a new session only when you intentionally want a new verification. First confirm that an earlier ambiguous request did not already create one. Our API errors reference gives no retention window for idempotency keys, so do not invent a cutoff and then open a second session while the first outcome is unknown.

How long should an idempotency key stay valid?

Our API errors reference gives no retention window for idempotency keys. A general design rule is to cover your retry window, but that is not a guarantee we make. Keep the ambiguous operation unresolved until you can confirm its outcome before creating another session.

Is it safe to retry a Didit call after a timeout?

A timeout or 5xx can leave the outcome unknown, so reconcile the original write before sending another create unless the endpoint explicitly documents a safe retry, and reuse the original key and payload when that retry uses an idempotency key. For a middleware 429, use Retry-After as the minimum delay and apply capped backoff with jitter. For other 429 responses, follow the endpoint's error contract.

Which Didit errors should I retry?

For a middleware 429, wait at least as long as Retry-After before retrying. For other 429 responses, follow the endpoint's error contract. For 500, 502 and 503, the outcome can be unknown, so reconcile the original write before another create unless the endpoint explicitly documents a safe retry, and reuse the original key and payload when the documented retry uses an idempotency key. Do not retry 400, 401, 402, 403 or 415 until you have fixed what they name. After 404, check the ID and key scope, and after 410, create a replacement only when that is intended.

How do I deduplicate webhook deliveries?

Read the raw body before parsing, verify X-Signature-V2 with HMAC-SHA256 over sorted, Unicode-preserved canonical JSON in constant time, and check that abs(now - X-Timestamp) <= 300 seconds. The current secret verifies X-Signature-V2, and the replaced secret verifies X-Signature-V2-Previous when that header is present, so accept a valid match on either and keep the freshness check. Then apply the event keyed on event_id, return 2xx promptly and update state idempotently.

Do retries cost money on Didit?

Billing is per completed check from prepaid credit. A full KYC check is $0.33 and KYB starts at $2.00 per company. The docs pricing page states that some no-match database lookups and retries are billable, so check it for the endpoints you use. A duplicate session that completes checks is a billable event.

How do I test idempotency before going live?

Run the sandbox checks: confirmed success, a lost response after request send, a 409 observation where the endpoint documents support, a simulated middleware 429, a non-JSON 500 and a duplicate webhook. Record the observed status, any error code and any session ID. Verify session state through the console or a known session ID, and treat replay observations as test results only.

Can I use idempotency keys for GET requests?

You do not need to. A GET reads state, so repeating it has the same effect as calling it once. Keys belong on calls that change state, and only where the endpoint documents support.

Compliance built in

Audited, certified and attested.

We hold the certifications and build each country's rules into your flows, so you can launch anywhere without worrying. Security and Compliance center

  • Regulation encoded into your flows

    Tell us what you do and where. Didit lists the rules that apply to you, with sources, and builds the checks each country needs into one workflow.

  • Ready for AMLR

    Every requirement of the new EU anti-money laundering rules, from checking customers to human review, is already covered by a Didit check.

  • Tested in Spain's Treasury sandbox

    Spain's Treasury published its supervised sandbox report on Didit's NFC plus active liveness onboarding; SEPBLAC took part and valued the added measures positively.

  • Audited, not self-declared

    iBeta Level 1 and Level 2. Liveness tested under ISO/IEC 30107-3.

Compliance assistant

Your obligations · 3 regions

EU · AMLRCustomer due diligence, human reviewCovered
Illinois, Texas, ColoradoExplicit biometric consentCovered
Germany · Youth protectionVerified adults only (JMStV)Covered
Workflow checked. Every obligation is met
  • SOC 2 Type 2
  • ISO 27001
  • iBeta Level 1 and Level 2
  • EU regulator attestation
  • FSM youth protection
  • GDPR
  • EBA remote onboarding
  • MiCA compatible
  • FIDO Alliance member
  • AMLREU AML Regulation ready

Integration · Didit MCP

Run Didit from your own AI agent

Connect Didit to Claude, Cursor, VS Code or ChatGPT and just ask in plain words. Your agent can do anything you can do in the console, with the same permissions you have.

Add to ClaudeChatGPT
Didit Academy · Lesson 04 · Use Didit with MCP
  • Build workflowsDescribe the checks you need. The agent creates and publishes the flow.
  • Run investigationsAsk why a session was declined, review cases, search people and companies.
  • Change rulesCreate payment rules, test them on past data and switch them on.
  • Pull reportsAsk for numbers, exports or the audit log.

Verify your first user today.

Start free

Free sandbox. Credit applies to work-email sign-ups.