Automating API Contract Testing with Didit in CI/CD
Contract-test the Didit API in CI/CD: pin the OpenAPI file, create sandbox sessions with fixed scenarios, assert decision and error shapes on every pull request. Sandbox sessions are never billed.

Contents
In this guide
Jump to the part you need.
This guide is for teams that call the Didit API and want its contract checked on every pull request rather than by hand. Contract tests run against a sandbox application, where sessions are never billed, so sandbox API usage is free, while your CI provider may charge for runtime. Sandbox testing is free on every plan; live KYC lists at $0.33. The caveat is scope: sandbox outcomes come from scenarios and magic values, so the tests confirm the deterministic response shapes and statuses the scenarios produce, not production provider behavior.
Last updated: November 26, 2026. Prices checked against the live Didit price feed on November 26, 2026.
| Contract area | Call | What the test asserts |
|---|---|---|
| Session create | POST /v3/session/ on verification.didit.me | 2xx status, session_id and session_url present, session_kind matches the workflow type |
| Decision read | GET /v3/session/{session_id}/decision/ | session_kind is user or business, status is one of the ten published values, feature fields are plural arrays or absent |
| Error contract | The same routes, broken on purpose | 403 for no key, 401 for a bad key, 404 for an unknown session, and the error body shape you parse |
| Webhook contract | Your receiver or a stored fixture | environment is sandbox, the decision envelope parses, arrays stay plural |
| Account API | apx.didit.me with a bearer token | Register returns a code; verify-email returns both application keys |
Start free in the sandbox at business.didit.me, with no sales call. If you would rather have an AI assistant draft the first version of the suite, connect Didit through the Didit MCP server. The end-to-end integration recipe is on the Didit integration prompt page, next to pricing. The calls you will test are documented in Create session and Retrieve session.
What API contract testing means for a Didit integration
A contract is the agreement between your code and the Didit API about request fields, response fields, types, statuses and error codes. Contract testing checks that agreement without running your whole application: you send a request to a sandbox application, then assert the response against the pinned schema. Didit is the provider and your integration is the consumer, and the test fails the moment either side drifts.
In CI/CD the value is timing. A breaking change caught in a pull request costs minutes. The same change can reach staging or production before your integration detects it. This is the practical advantage of API contracts: the schema is written once, reviewed like code, and reused by tests, mocks and documentation. Because the decision response is also what your compliance team reads, pinning it beats testing by eye.
Prerequisites
- A sandbox application. Every sandbox application runs as a separate mode of an application, all products are on inside it, and application-level features from every plan are available in the sandbox. Organization-wide features still follow your plan.
- A sandbox API key. New keys start with
sk_test_followed by 43 URL-safe characters. You get one from theverify-emailresponse during programmatic registration, or from Developers, then API keys in the Business Console. Keep it server-side and store it as a CI secret. - A workflow UUID from
/v3/workflows/. You send it asworkflow_id; the workflow type decides whether a user or a business session is created. curlandjq1.6 or newer in the CI image. TheINfunction in the assertion below needs that version.- The OpenAPI file that covers your integration, committed to the repo as a pinned copy.
Step 1: pin the contract to the published OpenAPI
Didit lists two OpenAPI files as sources of truth: /openapi-25.json for verification endpoints and /openapi-auth.json for account, organization and application endpoints. Copy the one that covers your integration into the repository, commit it, and add a scheduled job that fetches the current file daily and opens a pull request when it differs. The committed copy is a consumer-controlled contract snapshot: your team decides when to update it. The scheduled fetch is a change-detection workflow: it tells you when the published file differs, then a reviewer updates the snapshot and the tests together. From then on the committed file is what your tests assert against, so a Didit change arrives as a reviewable diff instead of a red pipeline hours before a release.
Step 2: put the sandbox key in the CI secret store
The verification API does not use OAuth bearer tokens. Every route under verification.didit.me authenticates with a long-lived key in the x-api-key header, while account routes on apx.didit.me use a bearer token from the login endpoint. Never validate a key by its prefix, because keys created before the current format have none and keep working. If a key leaks, rotate it in the console rather than editing the contract.
Step 3: create a session with a fixed scenario
The call is POST https://verification.didit.me/v3/session/ with the x-api-key header and workflow_id in the body. Send vendor_data as your CI run identifier so the sessions you create are easy to find in the console later.
On a sandbox application you can add sandbox_scenario, a slug read from GET /v1/sandbox/scenarios/. The scenario expands its bundled magic values onto contact_details and expected_details, so the session reproduces one outcome instead of a random one. The same field is rejected with 400 on a live application. If the session is still Not Started, you can arm or re-arm it with POST /v3/session/{session_id}/sandbox/arm/.
One detail saves debugging time: every sandbox application already contains example user verifications, business verifications and transactions, the API returns them, and no webhook is sent for them. Scope your assertions to the session_id you just created instead of asserting on list endpoints.
Step 4: assert the decision response
Read the result with GET https://verification.didit.me/v3/session/{session_id}/decision/ and the same x-api-key header. The key needs the read:sessions privilege. Four assertions cover most of the drift you will meet:
session_kindisuserorbusiness, and your handler branches on it before reading anything else.statusis one of the published values: Approved, Declined, In Review, In Progress, Not Started, Expired, Abandoned, Kyc Expired, Resubmitted, Awaiting User.- Feature fields are plural arrays.
id_verifications,liveness_checks,face_matches,aml_screenings,phone_verifications,poa_verificationsand the rest are arrays when present, and absent or null when the feature did not run. They are never a placeholder object. - Warning objects keep their shape:
feature,risk,additional_data,log_type,short_description,long_description,node_id.

Step 5: add negative tests for the error contract
Happy paths break loudly. Error contracts break quietly and take down your retries. Assert three calls whose answers are documented: no key returns 403, a wrong or malformed key returns 401, an unknown session returns 404. Then assert the body shape you actually parse, because error bodies do not share one envelope. Most carry detail, some carry detail and a code, validation errors carry field keys or non_field_errors, standalone APIs carry error, and a 5xx may have no JSON at all, so your parser has to read the status first and the code second.
Step 6: test the webhook payload
Webhooks for status.updated and data.updated carry the same decision envelope as the API response, so one fixture serves both. Sandbox webhooks carry environment set to sandbox and live ones to live, which makes the environment itself worth asserting. Keep a captured payload in the repo as a fixture, validate it on every push, and a receiver-side schema change fails before deploy. No webhook is sent for the example data in a sandbox application.
If your CI has no public URL to receive a webhook, validate the stored fixture instead. Use the documented webhook and retrieve-decision routes.

aml_screenings.Step 7: gate the pipeline and keep the suite cheap
Run the OpenAPI diff and the contract suite on every pull request that touches the integration, and fail the job on any mismatch. Run the wide suite once a night. A sandbox application enforces a quota of 500 session creates per 24 hours, and on Enterprise that quota can be raised on request. Create one session per test case and reuse its id for the decision and negative checks rather than creating a session per assertion.
The runnable script
This script uses only documented calls. It creates one sandbox session, reads the decision, and asserts the parts of the contract that change most often.
#!/usr/bin/env bash
set -euo pipefail
: "${DIDIT_API_KEY:?set DIDIT_API_KEY to the sandbox application key}"
: "${WORKFLOW_ID:?set WORKFLOW_ID to a workflow UUID from /v3/workflows/}"
BASE="https://verification.didit.me"
# 1. Create a sandbox session. SANDBOX_SCENARIO is a slug from GET /v1/sandbox/scenarios/
BODY=$(jq -n --arg wf "$WORKFLOW_ID" --arg vendor "ci-${CI_PIPELINE_ID:-local}" --arg scenario "${SANDBOX_SCENARIO:-}" '{workflow_id: $wf, vendor_data: $vendor} + (if $scenario == "" then {} else {sandbox_scenario: $scenario} end)')
CODE=$(curl -sS -o create.json -w '%{http_code}' -X POST "$BASE/v3/session/" -H "x-api-key: $DIDIT_API_KEY" -H 'Content-Type: application/json' -d "$BODY")
case "$CODE" in 2*) ;; *) echo "create failed: $CODE"; cat create.json; exit 1;; esac
SESSION_ID=$(jq -er '.session_id' create.json)
# 2. Read the decision
CODE=$(curl -sS -o decision.json -w '%{http_code}' "$BASE/v3/session/$SESSION_ID/decision/" -H "x-api-key: $DIDIT_API_KEY")
test "$CODE" = "200" || { echo "decision failed: $CODE"; cat decision.json; exit 1; }
# 3. Assert the contract
jq -e '
(.session_kind == "user" or .session_kind == "business")
and (.status | IN("Approved","Declined","In Review","In Progress","Not Started","Expired","Abandoned","Kyc Expired","Resubmitted","Awaiting User"))
and ((.id_verifications // []) | type == "array")
and ((.aml_screenings // []) | type == "array")
' decision.json > /dev/null || { echo 'contract mismatch'; jq . decision.json; exit 1; }
jq -r '"session_kind=\(.session_kind) status=\(.status)"' decision.json
echo 'contract ok'
Expected output
For a sandbox scenario that resolves to an approval on a user workflow, the job prints two lines and exits 0:
session_kind=user status=Approved
contract ok
The three documented negative calls continue the script above: BASE and SESSION_ID are already set there. They print 403, 401 and 404 in that order:
# Continuation of the script above: BASE and SESSION_ID are set.
curl -s -o /dev/null -w 'no key: %{http_code}\n' "$BASE/v3/session/$SESSION_ID/decision/"
curl -s -o /dev/null -w 'bad key: %{http_code}\n' "$BASE/v3/session/$SESSION_ID/decision/" -H 'x-api-key: sk_test_invalid'
curl -s -o /dev/null -w 'unknown session: %{http_code}\n' "$BASE/v3/session/00000000-0000-0000-0000-000000000000/decision/" -H "x-api-key: $DIDIT_API_KEY"
Failure cases and recovery
| Status | Likely cause in a contract suite | Recovery |
|---|---|---|
| 400 | A field failed validation, a document could not be read, the callback is outside the application's allowed domains, or sandbox_scenario was sent to a live application | Read the body, fix the request, rerun. Keep scenario slugs out of live jobs |
| 401 | The key is wrong, malformed, revoked or expired | Rotate the CI secret and rerun |
| 403 | No x-api-key header, a scoped key without access, or a call from outside the key's IP list | Check the header name and the key's scope in the console |
| 404 | The session is outside the key's workflow or status limits, or the id is wrong | Use a key whose limits include that session |
| 409 | A reused Idempotency-Key, or a step that already ran | Read code, reload the session state, then decide |
| 410 | The session or invitation expired | Create a new session; do not retry the old id |
| 415 | The body is not JSON | Send Content-Type: application/json |
| 429 | A rate limit or quota was reached | Wait for the interval in the response, then retry with backoff |
| 500, 502, 503 | An unexpected error, a dependency error, or a query timeout | Retry with backoff. A 503 may carry query_timeout |
Two of these deserve a comment in the suite. A 403 is not a 401: the first usually means the header never arrived, the second means it arrived and was refused. And a 5xx body may not parse as JSON, so the test has to read the status code before it tries the body.
Inputs and outputs
| Item | Where it comes from | Used for |
|---|---|---|
DIDIT_API_KEY | Sandbox application key, sk_test_ prefix, from the verify-email response or Developers, then API keys | x-api-key header on every verification call |
workflow_id | Workflow UUID from /v3/workflows/ | Decides whether the session is user or business |
vendor_data | Your CI pipeline id | Binds the session to an entity and makes it findable in the console |
sandbox_scenario | Slug from GET /v1/sandbox/scenarios/ | Makes the outcome deterministic |
session_id | Create response | Path parameter for the decision read and the negative checks |
session_kind | Decision response | Branching in your handler |
status | Decision response | One of ten published values |
| Feature arrays | Decision response | Shape assertions per feature |
Worked cost example
Contract testing itself is free. Sandbox sessions are never billed, the balance check is bypassed, and sandbox testing is free on every plan. Free means no billing, not unlimited volume: the sandbox still enforces a quota of 500 session creates per 24 hours. Take a suite of six test cases run on 20 pull requests a month:
- 6 cases x 20 pull requests = 120 sandbox sessions.
- 120 sessions x $0.00 = $0.00.
The only paid surface appears if you also point the same suite at a live application. Live calls are billed per completed check from prepaid credit, and a full ID check (KYC) lists at $0.33, made up of ID document verification at $0.15, passive liveness at $0.10, face match 1:1 at $0.05 and device and IP analysis at $0.03. Four live smoke runs of six cases a month:
- 4 runs x 6 cases = 24 completed checks.
- 24 x $0.33 = $7.92 at list price.
- On Growth, with 4% off every Didit price: 24 x $0.3168 = $7.60.
An organization created through the API starts with no credit, so a live smoke job needs a top-up first. Most teams skip it and keep the whole suite in the sandbox.
Paid steps and review boundaries
Nothing in this guide is paid when it runs against a sandbox application, including the scenario field and the arm endpoint. A live run is paid per completed check, and the price depends on which modules the workflow runs. Manual review is a product feature, not a test step: a session can carry reviews and a status_override when a person changed the outcome, and decision_trace.decided_by records whether the status came from automatic logic, a manual review or the Investigator agent. Contract tests should assert that those fields exist and keep their shape. They should not depend on triggering a review.
Why contracts pay off on an identity integration
- Breaking changes surface in the pull request that caused them, not in a staging run three days later.
- The pinned schema doubles as documentation for the fields your compliance team reads.
- Error and retry logic is tested on purpose, so a 403 does not get retried like a 500.
- The same fixtures validate your webhook receiver, so a provider change and a consumer change fail in the same place.

Sources
- Sandbox test data: scenarios, magic values and documents
- API authentication
- Create session API
- Retrieve session decision API
- Data models
- Didit API errors: status codes, bodies and fixes
- API rate limiting
- API keys in the Business Console
- Didit pricing, prices read November 26, 2026
- Pricing in the docs
- Didit MCP server
- Didit integration prompt
Open a sandbox application and run the script above against it: business.didit.me takes no sales call, and sandbox sessions are never billed.
Try it
Try this in the sandbox
Run the check this guide describes, free.
The product this post is about, taken from its topic. Run it free in the sandbox.
Author
Alejandro Rosas
Co-founder and CTO

Questions
Frequently asked questions
How do I test the Didit API in a CI/CD pipeline?
Create a session with POST /v3/session/ against a sandbox application, read it with GET /v3/session/{session_id}/decision/, and assert the response fields you depend on. Both calls use the x-api-key header and a sandbox key. Keep the suite in the sandbox so providers are mocked and sessions are never billed. Do not upload real PII.
Does API contract testing with Didit cost anything?
No, when it runs in the sandbox: sandbox sessions are never billed and the balance check is bypassed. Costs start only if you point the same tests at a live application, where each completed check is billed from prepaid credit. A full ID check lists at $0.33.
Which Didit endpoints should a contract test cover first?
Start with session create, the decision read, and the error responses for both. Add the webhook payload once your receiver exists. If you manage applications and keys programmatically, add the account endpoints on apx.didit.me, which use a bearer token rather than an API key.
How do I get a sandbox API key for a CI job?
Register programmatically with POST /auth/v2/programmatic/register/, then call verify-email with the six-character code. The response returns both applications inline, and you want sandbox_application.api_key, which starts with sk_test_. You can also create a separate key in the console under Developers, then API keys.
What is sandbox_scenario and can I use it in production?
sandbox_scenario is a slug from the sandbox catalog at GET /v1/sandbox/scenarios/ that makes a session reproduce one outcome. It is rejected with 400 on a live application, so keep it out of live jobs. You can arm or re-arm a scenario after create while the session is still Not Started.
Why does my contract test get 403 instead of 401?
A 403 means the request reached the API without a usable header or from an address outside the key's IP list, so nothing authenticated. A 401 means a key was sent and it was wrong, malformed, revoked or expired. Assert both in the suite, because retry logic should treat them differently.
How do I test Didit webhooks from CI?
Capture one payload per event type as a fixture and validate it on every push, then assert environment is sandbox for sandbox traffic. Webhooks carry the same decision envelope as the API response, so the same schema assertions apply. No webhook is sent for the example data that ships inside a sandbox application.
How many test sessions can I create in the sandbox?
A sandbox application enforces a quota of 500 session creates per 24 hours, and Enterprise can request a higher quota. Create one session per test case and reuse its id for the following assertions. Use a nightly wide run instead of running hundreds of sessions per push.
What are the advantages of API contracts for identity checks?
A pinned contract catches breaking changes in the pull request that caused them, documents the exact fields your compliance team reads, and gives you one place to test error and retry behaviour. It also keeps the webhook receiver and the API client on the same schema, so a change fails once instead of twice.
How do I avoid breaking tests when Didit ships a change?
Diff the published OpenAPI file on a schedule and review the diff before it reaches your pipeline. Assert on the fields you actually use rather than whole objects, and remember that feature arrays are always plural in the current API version. When a diff changes a field you use, update the pinned file and the test in the same pull request.
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.
Your obligations · 3 regions
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.
- 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.
Didit Academy


