Skip to main content

Idempotency Keys and Didit Session Creates in Python

Keep one operation key and your stable vendor_data, then store the returned session ID. A reused Idempotency-Key is one possible 409 cause; our Create Session reference defines no endpoint-specific idempotency or retry contract.

Idempotency Keys and Didit Session Creates in Python

Contents

In this guide

Jump to the part you need.

This guide is for Python developers who create Didit sessions from a backend and need to handle a timeout without guessing whether a session exists. Sandbox calls are free; a live full ID check costs $0.33 per completed check. The caveat: our Create Session reference does not define an endpoint-specific idempotency or retry contract, while our error reference lists a reused Idempotency-Key as one possible cause of HTTP 409.

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

Documented session-create facts at a glance
ItemValue
EndpointPOST https://verification.didit.me/v3/session/
Auth headerx-api-key
Operation keyStore one in your own records per logical operation
Reused Idempotency-KeyOur error reference lists it as one possible cause of HTTP 409. Our Create Session reference does not document replay, duplicate prevention, or a retry contract for this endpoint
Create rate limit600/min in the session-create scope and 300/min in the shared generic-write scope by default. The first exhausted scope returns 429.
Sandbox costFree. You can create sandbox sessions without spending credit, and the checks are mocked.
Live full ID check$0.33 per completed check

Start free in the sandbox at https://business.didit.me/, with no sales call. Developers can connect Didit to an AI assistant through the Didit MCP server.

What you build, and the method we recommend

The session is a Didit User Verification session when the workflow is KYC. Every price is on didit.me/pricing. After a timeout or dropped connection, keep the outcome unknown. If you have a session ID, retrieve its decision. Otherwise, pause before sending another create and reconcile the original attempt.

A duplicate create can leave the same user with two verification sessions. If both links are delivered, the user may open either one. That is the product cost, and it is separate from the per-check price.

  • Keep one operation key in your own records. Generate it when you decide to verify someone, store it, and reuse it in your logs and internal state. Do not treat it as a documented replay key for POST /v3/session/.
  • Use your stable entity ID. Pass your stable identifier for the user or business in vendor_data. Our Create Session reference strongly recommends it because it binds the session to an entity and is used for duplicate detection across sessions. It does not replace storing the returned session ID.
  • Store the returned session ID as soon as you have it. A known session ID is the documented recovery path when you need to read a decision.
  • Treat HTTP 409 as a conflict. Read code and reload the state. Our error reference lists a reused Idempotency-Key as one possible cause, not the only one, and it does not promise that the first response is replayed.
A session overview with its warnings in the Didit Business Console
The state you reload after a conflict: one session, its status and its warnings.

Prerequisites

  • Python and the requests library, or the official Didit Python SDK (pip install didit-sdk, Python 3.10 or newer) from the Python SDK page.
  • A Didit API key, created under Developers then API keys in the Business Console. Sandbox keys start with sk_test_ and live keys with sk_live_. Keys made before that format have no prefix and still work, so never validate a key by its prefix.
  • A workflow UUID. Its type decides whether a create produces a user verification session or a business verification session. There is no separate KYB endpoint.
  • Two environment variables: DIDIT_API_KEY and DIDIT_WORKFLOW_ID. Keep the key server side only.
  • Optional callback URL. If the application has an allowlist, an HTTP or HTTPS callback must match an allowed origin, including scheme, host, and port. Custom URL schemes are accepted.

Step by step: create a session and recover without guessing

  1. Get a sandbox key. Register programmatically or copy the sandbox key from the console. Sandbox testing is free. You can create sandbox sessions without spending credit, and the checks in those sessions are mocked. See API authentication.
  2. Collect your workflow UUID. Copy it from the console, or read it from /v3/workflows/. Pass it as workflow_id.
  3. Create the operation key in your own records. In Python, import uuid and str(uuid.uuid4()) are enough. A UUIDv4 is a practical random identifier for a logical operation. Do not use timestamps, and do not regenerate it inside a retry loop.
  4. Send the documented create request. Use the fields in the example: workflow_id, vendor_data and callback. The sample does not send Idempotency-Key because our Create Session reference does not document it for this endpoint.
  5. Save the returned session ID on a 2xx response. Read the exact response fields from the Create Session API page. A 2xx means a session was created; it is not proof that only one session exists.
  6. If you know the session ID, read the decision. Call GET https://verification.didit.me/v3/session/{session_id}/decision/ with x-api-key. Webhooks also carry session_id, vendor_data and status.updated, which helps you match a later update to your original request.
  7. Exercise the unknown-outcome branch. Use a simulated timeout in your Python caller and verify that it sends no second POST.
import json
import os

import requests

API_KEY = os.environ['DIDIT_API_KEY']
WORKFLOW_ID = os.environ['DIDIT_WORKFLOW_ID']
CREATE_URL = 'https://verification.didit.me/v3/session/'


def create_session(vendor_data):
    headers = {
        'x-api-key': API_KEY,
        'Content-Type': 'application/json',
    }
    body = {
        'workflow_id': WORKFLOW_ID,
        'vendor_data': vendor_data,
        'callback': 'https://myapp.com/return',
    }
    try:
        response = requests.post(CREATE_URL, headers=headers, json=body, timeout=30)
    except (requests.exceptions.Timeout, requests.exceptions.ConnectionError) as exc:
        return 'unknown', {'transport_error': str(exc)}
    raw = response.text
    try:
        payload = json.loads(raw) if raw else {}
    except json.JSONDecodeError:
        payload = {}
    return response.status_code, payload


def get_decision(session_id):
    url = f'https://verification.didit.me/v3/session/{session_id}/decision/'
    response = requests.get(url, headers={'x-api-key': API_KEY}, timeout=30)
    return response.status_code, response.text


status, payload = create_session('user-42')
print(status)
# On a 2xx, save the returned session ID from the documented response.
# To read a known session later, call get_decision('SESSION_ID').

The sample catches a requests timeout or connection error and returns an explicit unknown outcome without sending a second POST. A timeout puts you in the unknown-outcome state, and our docs do not define an endpoint-specific retry contract that would let the sample safely decide for you.

Expected output

A successful create returns a 2xx response with a session. The exact success status and response fields are in the Create Session reference; read the returned session ID from there and save it against your operation record. Do not treat a 2xx as proof of exactly-once execution.

2xx with a session
409 conflict, with detail and, when present, code
429 rate limit, with Retry-After

Error bodies do not share one envelope, so parse defensively. Branch on the status first and on code when it is present, because message text can change. See Didit API errors for the documented bodies.

The hosted verification flow showing its processing screen
The user sees one flow. Your recovery policy must not create a second one by accident.

Known session, unknown outcome, conflict and rate limit

These four states need different handling. Mixing them is how a retry loop creates a duplicate session.

  • Known session ID. Read the decision with the documented GET call. Use the decision before treating the session as approved or declined. A webhook with status.updated can also update your record, and its session_id and vendor_data fields are the correlation keys.
  • Unknown outcome after a timeout. You did not receive a response, so you do not know whether a session exists. Check your own record first. If there is no session ID, do not assume the API deduplicated anything. Record the transport error and the internal operation ID. Check whether you already saved a session ID. If you have one, retrieve its decision. Otherwise, keep the outcome unknown and pause before issuing another create.
  • Conflict. HTTP 409 means the request conflicts with the current state, for example a reused Idempotency-Key or a step that already ran. Read code and reload the state. Recovery depends on code.
  • Rate limit. HTTP 429 from the documented rate-limit middleware means a rate limit was reached. Endpoint-specific caps and cooldowns can have separate response contracts. Use Retry-After as the floor, then add bounded exponential backoff with jitter. Stop after a small ceiling and alert instead of looping.

Failure cases and recovery

What each response means for your recovery policy
StatusWhat happenedRecovery
409The request conflicts with current state, for example a reused Idempotency-Key or a step that already ran. Recovery depends on code when present.Read code, then reload the state. If the body has no stable code, branch on the status. Do not assume key reuse or a replayed response.
429A rate limit was reached in the documented rate-limit middleware. The first exhausted scope returns 429. Endpoint-specific caps and cooldowns can have separate response contracts.Wait for Retry-After as the floor, then use bounded exponential backoff with jitter. Stop after a small ceiling.
500An unexpected error on our side.Read code when present. If you have a session ID, retrieve its decision. If the original create may have succeeded and you have no session ID, keep the outcome unknown and reconcile the attempt before sending another create.
502 / 503A dependency failed, is unavailable, or the request timed out.Read code when present. If you have a session ID, retrieve its decision. If the original create may have succeeded and you have no session ID, keep the outcome unknown and reconcile the attempt before sending another create.
400 on callbackThe callback is not on the application's allowed origins.Correct the callback URL or the application's allowed origins.
400, not enough creditsPOST /v3/session/ cannot be paid for, so no check ran.Top up the balance before submitting again.
401The key is invalid, revoked or expired.Check whether the key is invalid, revoked or expired.
403The key is missing or restricted by scope or IP, or the contract billing is suspended. The application may also have been deleted.Read the error body. Check whether the key is missing or restricted by scope or IP. If the code is application_deleted, stop retrying with that key. If the code is contract_billing_suspended, resolve the billing restriction before trying again.
404The resource does not exist, or the session sits outside the key's workflow or status limits.Do not retry. Check the id and the key limits.
410The resource expired, for example the session.Create a new one with a new operation key, because it is a new operation.

The rate limits behind the 429s are documented on API rate limiting: 600/min in the session-create scope and 300/min in the shared generic-write scope by default. The first exhausted scope returns 429. This header guidance applies to the documented rate-limit middleware response; endpoint-specific caps and cooldowns can have separate response contracts. We emit X-RateLimit-* headers on the 429 response itself, not on successful responses, so use Retry-After rather than reading headers after a success.

Inputs and outputs

Fields this example uses
InputRequiredWhat it does
x-api-keyYesAuthenticates the call against the application that owns the key.
workflow_idYesWorkflow UUID. The workflow type decides KYC or KYB.
vendor_dataStrongly recommendedYour stable id for the user or business. It binds the session to an entity and is used for duplicate detection across sessions.
callbackOptionalOptional callback URL. If the application has an allowlist, an HTTP or HTTPS callback must match an allowed origin, including scheme, host, and port. Custom URL schemes are accepted.
Responses your recovery policy must handle
OutputMeaning
2xx with a sessionA session was created. Save the returned session ID. This does not prove exactly-once execution.
HTTP 409, with code when presentThe request conflicts with current state. Reload the state and branch on code when present; if the body has no stable code, branch on the status.
429 with Retry-AfterBack off from the documented floor and add jitter.
Webhook with status.updatedThe session moved state. session_id and vendor_data come back in the payload, which is how you correlate a later update with your record.

Webhook payloads carry event_id, session_id, vendor_data and any metadata you sent. The docs tell you to update state idempotently on your side too. See Webhooks for the signature headers and the event list.

  • Sandbox is free. You can create sandbox sessions without spending credit, and the checks in those sessions are mocked. Use a sandbox scenario to reproduce a decline or an AML hit without spending credit.
  • Live billing is per completed check. A create call that returns a session is not a completed check on its own. The pricing page lists the few lookups and retries that are billable, and every number is on pricing in the docs.
  • A 409 changes nothing about a decision. It is a conflict on the request. It does not approve, decline or skip anything.
  • Human review stays human. If a session lands In Review, follow your review path. Check the known session's decision before treating it as approved or declined. A conflict response does not move a session past that boundary.
  • Going live is a key swap plus balance. Point DIDIT_API_KEY at the live key once the organization has credit. The Free plan includes $10 of credit a month for eligible organizations, and top-ups last 12 months.

Worked cost example

Assume 50,000 planned creates in a month, with one completed full ID check for each planned create. Assume one retry on 2% of those creates, which is 1,000 retried creates.

At list price, a full ID check is $0.33, made up of ID document verification $0.15 + passive liveness $0.10 + face match 1:1 $0.05 + device and IP analysis $0.03.

  • Planned check charges: 50,000 x $0.33 = $16,500.00.
  • Conditional duplicate exposure: if all 1,000 retries create an extra session and all those sessions complete a full ID check, 1,000 x $0.33 = $330.00.
  • Conditional total at list price: $16,500.00 + $330.00 = $16,830.00.
  • On Scale at 10% off, a check is $0.33 x 0.9 = $0.297. Planned check charges: 50,000 x $0.297 = $14,850.00. Conditional duplicate check charges: 1,000 x $0.297 = $297.00.

The $330 is not a prediction. It is the conditional list-price exposure if every retried create opens an extra session that a user then completes. These Scale amounts are check charges before the $299 a month subscription fee and before plan credits. A 409 alone does not tell you whether the original request completed or incurred a charge.

Didit billing explained: credits, auto-recharge and volume discounts
Our billing explainer. The $0.33 list price for a full ID check and the Scale 10% discount come from the live Didit price feed, read November 26, 2026.

Conflicts and billing

We bill per completed check from prepaid credit. A failed duplicate request adds no completed check of its own. The conflict response does not tell you whether the original request completed a billable check. If you have the session ID, retrieve the decision and check its status before treating it as approved or declined.

Sources

Open the sandbox at https://business.didit.me/ and run one documented create against a test workflow. Save the session ID if the create succeeds. To test timeout recovery, simulate a transport error and verify that the caller records an unknown outcome and sends no second POST. Sandbox testing is free, with no sales call.

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 does a 409 from Didit mean for a session create?

HTTP 409 means the request conflicts with the current state. Our error reference gives a reused Idempotency-Key as one example and tells you to read code and reload the state. Recovery depends on code when present; if the body has no stable code, branch on the status. Do not assume the original response body is replayed, because our Create Session reference does not document replay for this endpoint.

Does POST /v3/session/ support an Idempotency-Key header?

Our error reference lists a reused Idempotency-Key as one possible cause of HTTP 409, but our Create Session reference does not document that header, a retention period, duplicate prevention, replay, or a retry contract for POST /v3/session/. The example sends only x-api-key and Content-Type. Do not depend on the header until the endpoint documentation states the contract.

How do I generate an internal operation identifier in Python?

Run import uuid, then use str(uuid.uuid4()). Generate it once when you decide to verify a person or a business, store it in your own records, and reuse that exact string in your logs for the same logical operation. The example does not transmit this identifier to Didit.

How do I handle a timeout after creating a Didit session?

If you saved the session ID, call GET https://verification.didit.me/v3/session/{session_id}/decision/ and read the decision. If you did not save it, you are in the unknown-outcome state. Our docs do not define endpoint-specific deduplication for POST /v3/session/. Record the transport error and the internal operation ID. Check whether you already saved a session ID. If you have one, retrieve its decision. Otherwise, keep the outcome unknown and pause before issuing another create.

Should I retry a Didit 500 or 503?

A 500 may have no JSON body, so rely on the status first. Read code when present. If you have a session ID, retrieve its decision. If the original create may have succeeded and you have no session ID, keep the outcome unknown and reconcile the attempt before sending another create.

Does a retried create call cost another check?

We bill per completed check from prepaid credit. A failed duplicate request adds no completed check of its own. The cost risk is a second session that your user then completes, which is why the duplicate guard matters more than the per-call price.

How do I stop two internal systems creating two sessions for the same user?

Use one stable vendor_data value per user or business, and give one system ownership of session creation. Share the returned session ID with the other system instead of starting a second create. Our Create Session reference does not document an idempotency contract that would make a shared key sufficient by itself.

Can I look up a session by its idempotency key?

Our Create Session and API error references do not describe a session lookup by idempotency key. If you have a session ID, retrieve its decision through the documented GET endpoint. Write the operation key, vendor_data and returned session ID to one record at create time.

How do I test timeout handling without spending credit?

Run one documented create against a sandbox workflow. To test your caller's recovery separately, simulate a transport timeout and verify that the caller reports an unknown outcome and sends no second POST.

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.