API integration guide
Base URL:
https://api.defayke.ai ·
test key = free sandbox,
live key = production · questions:
@martybr (Telegram)
Quick reference
| What you get | Per receipt: a forensic verdict (clean / review / tampered) with reason_codes, extracted fields, a match against your order and — with order_ref — the order state whose confirmable flag is the one signal to credit a deposit on. |
| Hosts | API: https://api.defayke.ai · portal (keys, billing, webhooks): this site. /v1 is served on the API host only. |
| Keys | rk_test_… — free sandbox, full pipeline, sees only test verifications, orders and usage; no top-ups · rk_live_… — production, 1 check per verification. Keys are created on API keys once your account is approved. |
| Limits | POST /v1/verify: 60 / min per key and 200 / min per IP (plus 300 requests / min per IP for all of /v1) → 429 + Retry-After. File ≤ 10 MiB. Analysis ≤ 60 s — set your client timeout to ≥ 90 s (batch: ~70 s × files). Batch ≤ 10 files. |
| Retries | A repeated POST /v1/verify is a new check: charged again and flagged duplicate_receipt (with order_ref the same file is never counted twice in the order). On a slow network prefer mode=async + webhook over retrying. |
| Amounts | Decimal strings in major units with 2 decimals ("1500.00" UAH). Send expected_amount the same way — never in kopecks. |
| Times | Our timestamps (created_at, first_seen_at, computed_at, webhook created_at) are UTC, ISO without a suffix. Receipt values (fields.transaction.date, match.got.date) are copied as printed on the receipt — bank-local time, e.g. 06.07.2026 14:32. A bare expected_* date is read as Europe/Kyiv time (or your organisation's timezone); append Z for UTC. |
| Compatibility | We add fields without notice — ignore unknown keys. Changes that alter meaning are listed in the changelog. |
| Support | Telegram @martybr — organisation settings (timezone, registry add-on, retention) are switched on request. |
1
Authentication
Pass your key in a header (either form works):
Authorization: Bearer rk_live_xxx
# or
X-API-Key: rk_live_xxx
Start with a test key — it runs the full pipeline for free (sandbox, credits_charged: 0) and sees only test verifications and orders; the registry add-on is not billed for it and does not run on it: a receipt the registry would check comes back with registry.status: skipped · registry.reason: sandbox (the registry answers live keys only). Smoke-test it with GET /v1/me:
curl -H "Authorization: Bearer rk_test_xxx" https://api.defayke.ai/v1/me
2
Verify a receipt
POST a PDF or a screenshot / photo (JPG / PNG / WEBP — convert HEIC to JPG first); we return a verdict + reason codes + extracted fields. Unsupported or unreadable files → 415 / 422, never charged. Optional geo_code form field (ua | uz | kz | tr; default ua) — send it for non-UA receipts.
curl -X POST \
-H "Authorization: Bearer rk_live_xxx" \
-F "file=@receipt.pdf" \
https://api.defayke.ai/v1/verify
RESPONSE
{
"verification_id": 42,
"status": "completed", // completed | pending | failed (the last two only in async mode)
"verdict": "clean", // clean | review | tampered (pending / failed while status is)
"level": "positive", // positive | warning | negative — same scale as verdict
"reason_codes": [], // why — see the reason code table below
"bank_key": "монобанк", // issuing bank, registry key — see the bank table below
"fields": { // extracted from the receipt text;
"transaction": { // every value is a string or null
"amount": "1500.00",
"currency": "UAH",
"date": "06.07.2026 14:32", // as printed (bank-local time)
"reference": "1234-5678-9012-3456",
"fee": "0.00"
},
"recipient": { "name": "…", "card": "…", "iban": "…", "bank": "…" },
"payer": { "name": "…", "card": "…", "iban": "…", "bank": "…" }
},
"duplicate": { // same file seen before?
"is_duplicate": false, // sha256 match against your history
"seen_count": 0,
"first_seen_at": null, // UTC
"seen_elsewhere": false // seen by ANOTHER platform — a receipt shopped around
},
"receipt_age_hours": 3, // whole hours since the receipt time (bank-local); null if no date
"match": null, // per-field block when expected_* sent (see 2c)
"order": null, // order state when order_ref sent (see 2e)
"registry": null, // registry add-on only: {"status":"pending"} or the final result (see 2f)
"check_depth": { "depth": "deep", "reasons": [] }, // deep | basic
"sha256": "…",
"mode": "live",
"credits_charged": 1,
"balance_remaining": 117
}
A live key charges 1 check per call (any verdict). Out of balance → HTTP 402. Field extraction is best-effort — treat null as normal, and ignore unknown keys (new fields are added without notice). GET /v1/verifications/{id} returns the same keys later (plus outcome).
The full catalogue of
reason_codes (with meanings and effect on the verdict), the
check_depth reasons and the list of banks /
bank_key values with registry coverage are shown to partners after
sign-in.
2b
Async verification
Add mode=async: the call returns 202 immediately and the result arrives via the verification.completed webhook. Acceptance errors (400/402/413/415/429) still surface synchronously; the credit is debited up front and auto-refunded if the run fails (the webhook then carries data.status: "failed" + credits_refunded).
curl -X POST \
-H "Authorization: Bearer rk_live_xxx" \
-F "file=@receipt.pdf" \
-F "mode=async" \
https://api.defayke.ai/v1/verify
RESPONSE · 202
{ "verification_id": 42, "status": "pending", "mode": "live",
"credits_charged": 1, "balance_remaining": 117 }
No webhook configured or missed it? Poll GET /v1/verifications/42 until status leaves pending. A failed run (status: failed, error: file_damaged | verification_failed) is refunded automatically.
2c
Order matching (deposits)
Pass your order's requisites and the response gains a per-field match block — is this receipt about this order? The forensic verdict itself is never changed by matching. All fields are optional form fields on the same /v1/verify call:
order_ref=ORD-12350 # your order / deposit id — send it on EVERY call (needed for order.confirmable)
expected_amount=1500.00 # full order amount, major units
expected_currency=UAH
expected_card=4000 00** **** 0002 # the card you asked to be paid to (full or masked, as printed) …
expected_iban=UA213000000000026000000000001 # … and the IBAN when you have one — IBAN-only receipts (Privat, PUMB, A-Bank) need it
expected_bank=monobank # optional: brand name or bank_key; unknown → 400
expected_order_date=2026-07-06T14:00Z # order creation time; Z = UTC, a bare value = Europe/Kyiv
# date window — pick ONE of:
# (default) receipt between the order time and +8 h
# expected_date_window_hours=24 receipt between the order time and +24 h (only AFTER the order)
# expected_date_tolerance_hours=24 receipt within ±24 h of the order time (order created after the payment)
# instead of expected_order_date you may send an explicit range: expected_date_from=… expected_date_to=…
# instead of expected_card: expected_card_first4=5354 and/or expected_card_last4=2721
RESPONSE FRAGMENT
"match": {
"overall": "matched", // matched | partial | mismatched | unknown
"amount": "match", // per-field: match | mismatch | unknown (+ partial | over with order_ref)
"currency": "match",
"recipient": "match", // card/iban aggregate (either counts)
"card": "match",
"date": "match",
"order_ref": "ORD-12350", "order_ref_source": "explicit", // with order_ref (see 2e)
"amount_expected": "1500.00", "amount_paid": "1500.00", "amount_remaining": "0.00", "receipts_count": 1,
"expected": { "amount": "1500.00", "order_date": "2026-07-06T14:00Z" }, // what you sent
"got": { "amount": "1500.00", "date": "06.07.2026 17:12:40" }, // what the receipt says (Kyiv time)
"date_window": { "from": "2026-07-06T17:00", "to": "2026-07-07T01:00", "tz": "Europe/Kyiv" } // accepted range, receipt-local
}
Reason codes of a mismatch (amount_mismatch, recipient_mismatch, receipt_outside_window, …) are added to the top-level reason_codes; match itself has no reason_codes key.
Per-field values: match / mismatch / unknown (not extractable from this receipt — never a false mismatch); with order_ref the amount can also be partial (order not yet covered) or over (receipts exceed the order).
overall: matched = everything sent matches and the order is covered; mismatched = at least one contradiction; partial = no contradiction but something is still unconfirmed (unknown field or order not yet covered); unknown = nothing could be compared.
Recipient: send both expected_card and expected_iban when you have them — Privat / PUMB / A-Bank payment instructions print only the IBAN; matching either one counts.
Dates: YYYY-MM-DDTHH:MM, DD.MM.YYYY HH:MM or DD-MM-YYYY HH:MM. Receipts print Kyiv wall time; a bare value is read as Kyiv time. Storing UTC? Append Z (2026-09-14T15:33Z) or ask support to set your organisation's timezone — expected.tz then shows it. The default window is asymmetric (order time → +8 h); use expected_date_tolerance_hours when the order can be created after the payment. expected_date_window_hours and expected_date_tolerance_hours are mutually exclusive, both need expected_order_date, 1–720 h.
Not both: expected_order_date with expected_date_from/to, or expected_card with expected_card_first4/last4 → 400 (nothing charged).
2e
Partial payments, batch & order state
One order is often paid with 2–3 transfers and 2–3 receipts. Tag every receipt of the order with your order id in order_ref and pass the full order amount — the amount is checked cumulatively and the API tells you when the order is covered. Two equivalent ways to send:
A · ONE FILE PER CALL (receipts arrive over time)
curl -X POST -H "Authorization: Bearer rk_live_xxx" \
-F "file=@part1.pdf" -F "order_ref=ORD-12350" -F "expected_amount=12350" -F "expected_card=4000 00** **** 0002" \
https://api.defayke.ai/v1/verify
# … later, the second receipt — same order_ref, same full amount:
curl -X POST -H "Authorization: Bearer rk_live_xxx" \
-F "file=@part2.png" -F "order_ref=ORD-12350" -F "expected_amount=12350" -F "expected_card=4000 00** **** 0002" \
https://api.defayke.ai/v1/verify
B · ALL FILES IN ONE CALL — POST /v1/verify-batch (up to 10 files, sync only)
curl -X POST -H "Authorization: Bearer rk_live_xxx" \
-F "order_ref=ORD-12350" -F "expected_amount=12350" -F "expected_card=4000 00** **** 0002" \
-F "files=@part1.pdf" -F "files=@part2.png" -F "files=@part3.png" \
https://api.defayke.ai/v1/verify-batch
{
"order_ref": "ORD-12350", "files": 3, "verified": 2, "failed": 1,
"results": [
{ "index": 0, "file_name": "part1.pdf", "verification_id": 101, "verdict": "clean", "match": { … }, "credits_charged": 1, … }, // = single-call response
{ "index": 1, "file_name": "part2.png", "verification_id": 102, "verdict": "clean", "match": { … }, … },
{ "index": 2, "file_name": "part3.png", "error": { "status": 415, "detail": "Unsupported file type …" } } // not charged, batch continues
],
"order": { … }, // the order after all files (below)
"credits_charged": 2, "balance_remaining": 998
}
A and B are interchangeable: send what you have in a batch, send a late receipt with a single call — same order_ref, same order. A re-sent file is never counted twice.
THE ORDER BLOCK · in every response with order_ref, in GET /v1/verifications/{id}, in the webhook, and on demand: GET /v1/orders/{order_ref}
"order": {
"order_ref": "ORD-12350", "source": "explicit", // explicit | implicit (support-enabled fallback when no order_ref is sent)
"status": "settled", // settled | open | conflicted | unknown
"confirmable": false, // ← the auto-confirm condition (see below) — false here: receipt 102 still waits for the registry
"amount_expected": "12350.00", "amount_paid": "12350.00", "amount_remaining": "0.00",
"receipts_count": 2, // receipts COUNTED into amount_paid
"receipts": [
{ "verification_id": 101, "verdict": "clean", "overall": "partial", "amount": "7000.00", "counted": true, "reason": null, "unverified": [], "registry": "confirmed", "reused_from": null },
{ "verification_id": 102, "verdict": "clean", "overall": "matched", "amount": "5350.00", "counted": true, "reason": null, "unverified": [], "registry": null, "reused_from": null }
],
"conflicts": [], // [{verification_id, reason}] — tampered | recipient_mismatch | date_mismatch | bank_mismatch | currency_mismatch | registry_not_found | registry_mismatch | amount_over
"unverified": [], // counted receipts with an expected field left unknown: [{verification_id, fields:["recipient"]}] — "date" also when an old receipt (> 72 h) was sent without expected_order_date; "registry" when the registry add-on could not read the receipt's code or bank
"review_receipts": [], // counted receipts with verdict review
"reused_receipts": [], // counted receipts that already COUNTED in another of your orders — same file, or the same receipt code + amount: [{verification_id, first_order_ref}]
"registry": { "confirmed": 1, "confirmed_mismatch": 0, "not_found": 0, "pending": 1, "skipped": 0, "error": 0, "none": 0 }
}
| Situation | Receipt (match) | Order (order) | What you do |
| One receipt, full amount, all fields match | overall: matched | settled · confirmable: true | credit automatically |
| Receipt(s) below the order amount | amount: partial | open · amount_remaining > 0 | wait for the next receipt |
| Overpaid within tolerance (default 1 %, min 1.00, max 100.00 — expected_amount_tolerance overrides) | amount: match · amount_overpaid | settled · amount_overpaid | credit; the overpay is reported, not disputed |
| Underpaid by at most 1.00 in the order's currency (the payer rounded down: 19033.25 → 19033.00; amount_underpay_tolerance) | amount: match · amount_underpaid | settled · amount_underpaid · amount_remaining: 0.00 | credit; the shortfall is reported, not disputed |
| Receipts exceed the order beyond tolerance | amount: over | conflicted · amount_over | investigate (large overpayment or wrong receipt) |
| Paid to another card / IBAN | recipient: mismatch | conflicted · recipient_mismatch | dispute that receipt; others stay counted |
| Paid outside the order's date window | date: mismatch | conflicted · date_mismatch | dispute; compare got.date with date_window |
| Forged receipt | verdict: tampered | conflicted · tampered | reject / escalate |
| Bank registry does not know the receipt | registry.status: not_found | conflicted · registry_not_found | escalate |
| Registry knows the code, but its amount / date / recipient differ from the file | registry.status: confirmed_mismatch · registry.match | conflicted · registry_mismatch | reject / escalate — another receipt's code was put into this file |
| Registry confirmed the receipt, but the photo was read poorly (no amount, or less than the bank's) | registry.status: confirmed / confirmed_mismatch | counted at the bank's amount · amount_source: registry | as usual, by confirmable |
| Requisite not readable (scan, IBAN-only receipt) | recipient: unknown | settled · confirmable: false · unverified | manual check, or send expected_iban too |
| Verdict review | verdict: review | settled · not confirmable · review_receipts | look at it |
| The receipt says the payment is still processing («В обробці») | verdict: review · reason_codes: payment_in_processing | settled · not confirmable · review_receipts | ask for the final receipt or check the incoming payment |
| Same file sent again to the same order | duplicate.is_duplicate | reason: duplicate_file | nothing — not counted twice |
| The same payment already counted in another of your orders (same file, or the same receipt code + amount in a re-saved file) | duplicate.is_duplicate (same file) | settled · confirmable: false · reused_receipts | do not credit — one payment cannot fund two deposits; check first_order_ref. A receipt that was rejected in the other order (wrong card, forged…) does not count as used. |
| Old receipt (> 72 h) and no expected_order_date sent | reason_codes: stale_receipt | settled · confirmable: false · unverified: date | manual check — or always send expected_order_date |
| Receipt code or bank not readable (cropped / blurred screenshot) — registry add-on | registry.status: skipped · registry.reason: no_code | missing_code | low_confidence_bank | settled · confirmable: false · unverified: registry | manual check, or ask for the full receipt (best: the PDF from the banking app). Hiding the code is not a way around the registry. |
| Registry still running (registry add-on) | registry.status: pending | settled · confirmable: false · registry.pending > 0 | wait: re-read GET /v1/orders/{ref} in a few seconds or take external_verification.completed. Receipts the registry does not cover come back skipped at once and never hold the order. |
Rule of thumb: order.confirmable == true → credit the deposit. It is true only when the order is settled and every counted receipt is clean, has its recipient (card / IBAN) and date verified (no unverified — an unknown bank or currency does not block, check match.bank / match.currency yourself if you rely on them), not already used for another order (reused_receipts), and — with the registry add-on — answered by the registry (a receipt the registry does not cover, or an error, does not block: the forensic verdict stands; a receipt whose code or bank could not be read is unverified: registry and does block). conflicted → open a dispute on the receipts listed in conflicts. open → wait. settled but not confirmable → look at unverified / review_receipts / reused_receipts / registry.pending; a pending registry answer usually arrives within seconds. The per-receipt match.amount is the running total at the time that receipt was checked; order is recomputed on every call and is the source of truth.
2f
Bank registry auto-check (add-on)
Switched on per organisation (ask support). Every eligible receipt is also looked up in the official source —
check.gov.ua or the
PrivatBank registry (coverage per bank: the
bank table) — in the background, right after the response. A receipt the registry does not cover comes back
skipped at once.
POST /v1/verify → "registry": { "status": "pending" } // the check has started
GET /v1/verifications/42 (2–5 s later) → "registry": {
"provider": "check_gov", // check_gov | privat | skip (null on error)
"status": "confirmed", // pending | confirmed | confirmed_mismatch | not_found | skipped | error (any other value, e.g. request_failed: treat as error)
"code": "E000-AB12-3456-CDEF", // receipt code sent to the registry
"reason": "eligible", // routing note; for skipped the why: no_code | missing_code | low_confidence_bank (not readable → order not confirmable) | payment_method_not_covered | bank_disabled | insufficient_balance | sandbox (test key — the registry is not asked) | …
"fields": { "amount": 150000, "sender": "…", "recipient": "400000******0002", "op_date": "2026-07-06T11:12:40Z" }, // check.gov: amount in kopecks, date in UTC
"match": { // confirmed / confirmed_mismatch only: the registry's answer against the file itself
"overall": "match", // match | mismatch | unknown
"amount": "match", "date": "match", "recipient": "match", // per field; unknown = the registry did not return it
"registry": { "amount": "1500.00", "date": "2026-07-06", "recipient": "400000******0002" },
"receipt": { "amount": "1500.00", "date": "2026-07-06", "recipient": "400000******0002" }
},
"completed_at": "2026-07-06T11:12:44"
}
confirmed alone only says "a receipt with this code exists", so the amount and date (one day of slack) the registry returns are compared with what the file prints; a contradiction is confirmed_mismatch — a real code put into another receipt. Fields the registry did not return stay unknown and never hurt the status. The recipient is arbitrated by your expected_card / expected_iban (match.recipient_note): the registry names your requisite → match (the file was misread); the file shows your requisite but the registry names another → confirmed_mismatch (registry_contradicts_expected — the money went elsewhere); neither → unknown.
The same summary arrives as the external_verification.completed webhook (section 4) and is folded into order.registry; a not_found or confirmed_mismatch receipt becomes an order conflict. skipped = the bank / payment type is outside the registry's coverage — rely on the forensic verdict and the match.
Price: a plain verification costs 1 check; a receipt the registry actually answered (confirmed / confirmed_mismatch / not_found) costs 2 checks in total — the second is debited when the answer arrives (registry.credits_charged). skipped / error cost nothing extra; test keys are free and never reach the registry (skipped · sandbox).
!
Error codes
Error bodies are {"detail": "…"} — except a malformed request (missing / misnamed form field, wrong JSON type), where FastAPI returns 422 with detail as a list of {loc, msg, type}. No error is ever charged.
| HTTP | Meaning | What to do |
| 400 | Invalid expected_* value or unknown expected_bank | Fix the parameter; nothing was charged |
| 401 | Missing, invalid or revoked API key | Check the key on API keys |
| 402 | Out of credits (live keys only) | Top up on Billing (instant via @CryptoBot) or POST /v1/topups; test keys are free |
| 403 | Organisation not active (suspended / awaiting approval) · top-ups with a test key | Contact support · use a live key |
| 404 | Verification / order / top-up not found — a verification or order of the other key mode (test ↔ live) is "not found" too | Check the id and the key |
| 409 | Top-ups: 3 unpaid invoices already, or the invoice can no longer be cancelled | Pay or cancel one |
| 413 | File larger than 10 MiB | Send the original, smaller file |
| 415 | Unsupported file type, empty file, or an image we cannot decode (e.g. HEIC) | Send PDF or JPG / PNG / WEBP |
| 422 | Analysis timed out · the PDF is damaged or truncated · malformed request (list-shaped detail) | Retry once / send the original file / fix the request |
| 429 | Rate limit (see Quick reference), header Retry-After | Back off and retry after the given seconds |
| 503 | Top-ups only: @CryptoBot unavailable | Retry later |
| 5xx | Our fault | Retry with backoff; tell us if it persists |
POST /v1/verify-batch never fails as a whole for a per-file problem: each file's slot carries its own error: {status, detail} (402 / 413 / 415 / 422 / 429) and is not charged; the rest are checked.
Top up the balance
One @CryptoBot invoice, priced in USD, payable in USDT, USDC, TON, BTC, ETH, LTC, BNB or TRX — checks are credited automatically seconds after payment (no fees).
The same flow is on
Billing. Live keys only.
curl -X POST https://api.defayke.ai/v1/topups \
-H "Authorization: Bearer rk_live_…" -H "Content-Type: application/json" \
-d '{"amount_usdt": "30"}'
→ 201 { "topup_id": 42, "status": "pending", "amount_usdt": "30.00", "checks": 1000,
"pay_url": "https://t.me/CryptoBot?start=IV…", "expires_at": "…" }
GET /v1/topups/42 → "status": "approved", "checks": 1000, "paid_asset": "USDT", "paid_amount": "30.03"
GET /v1/topups → { "balance_credits": …, "topups": [ … ] }
DELETE /v1/topups/42 → "status": "cancelled" (409 if already paid / expired)
Checks = floor(amount / check price), frozen when the invoice is issued (30 USDT = 1,000 checks). Invoices live 24 h, up to 3 unpaid at a time; cancel one with DELETE /v1/topups/{id}.
Calling POST again with the same amount while that invoice is unpaid returns the same invoice (200) — no duplicates.
Errors: 400 bad amount · 403 test key · 409 3 unpaid invoices already · 429 >10 calls/min per key · 503 @CryptoBot unavailable, retry later.
Auto-refill: on balance.low (repeats after every charged check while the balance is ≤ 10) call POST /v1/topups with your usual amount and pay the pay_url; balance.topped_up confirms.
3
Usage & history
Aggregate stats and per-verification records. /v1/verifications is newest first, paged with limit (1–200) and offset, and — like /v1/orders — shows only the calling key's mode (test or live).
curl -H "Authorization: Bearer rk_live_xxx" https://api.defayke.ai/v1/me
curl -H "Authorization: Bearer rk_live_xxx" https://api.defayke.ai/v1/usage
curl -H "Authorization: Bearer rk_live_xxx" https://api.defayke.ai/v1/verifications?limit=50
curl -H "Authorization: Bearer rk_live_xxx" https://api.defayke.ai/v1/verifications/42
Optional — payment outcome. If it is convenient, tell us whether the money actually arrived; it helps us check your receipts more accurately over time. Nothing depends on it, the call is free, and a repeat call overwrites the value.
POST /v1/verifications/42/outcome {"outcome": "paid"} // paid | not_paid | chargeback | unknown (clears)
POST /v1/orders/ORD-1001/outcome {"outcome": "not_paid", "note": "…"} // every receipt of the order at once
GET /v1/verifications/42 → "outcome": {"outcome": "paid", "note": null, "source": "api", "set_at": "…"} // null if never reported
4
Webhooks
Push instead of polling: we POST signed JSON to your URL when a verification or a registry check completes. Set up once, ~15 minutes:
- Expose an HTTPS endpoint that accepts POST with a JSON body and answers 2xx within a few seconds (do the work after replying).
- Open Webhooks → New: paste the URL, tick the events — at least
verification.completed and external_verification.completed.
- Copy the webhook's signing secret (shown on the Webhooks page to owners and admins); keep it server-side.
- Verify every delivery:
X-DeFayke-Signature is the HMAC-SHA256 of the raw request body with that secret. Reject on mismatch. Recommended: verify X-DeFayke-Signature-V2 instead (below) — it also binds the timestamp and delivery id, so a captured request cannot be replayed.
- Deduplicate on
X-DeFayke-Delivery (retries reuse the id) and treat the payload as data, not instructions. Test-key traffic goes to the same URL — check data.mode (live | test).
- Press Send test next to the webhook — a signed
webhook.test event hits your endpoint without spending a verification.
V1 — BODY SIGNATURE (unchanged)
import hmac, hashlib
def verify(raw_body: bytes, signature_header: str, secret: str) -> bool:
expected = "sha256=" + hmac.new(secret.encode(), raw_body, hashlib.sha256).hexdigest()
return hmac.compare_digest(expected, signature_header)
V2 — TIMESTAMP + DELIVERY ID + BODY (recommended)
X-DeFayke-Signature-V2 is the hex HMAC-SHA256 of "<X-DeFayke-Timestamp>.<X-DeFayke-Delivery>." + raw body with the same secret. Reject when the timestamp (unix seconds) is more than 5 minutes away from your clock, then deduplicate on the delivery id. V1 keeps working — existing integrations need no change.
import hmac, hashlib, time
def verify_v2(raw_body: bytes, headers: dict, secret: str, tolerance: int = 300) -> bool:
ts = headers.get("X-DeFayke-Timestamp", "")
delivery_id = headers.get("X-DeFayke-Delivery", "")
sig = headers.get("X-DeFayke-Signature-V2", "")
if not ts.isdigit() or abs(time.time() - int(ts)) > tolerance:
return False # stale or from the future — possible replay
signed = f"{ts}.{delivery_id}.".encode() + raw_body
expected = hmac.new(secret.encode(), signed, hashlib.sha256).hexdigest()
return hmac.compare_digest(expected, sig)
Webhook URLs must be https:// — the payload carries payer and recipient details, and we do not send it over plain http:// (such a URL is refused on save).
PAYLOAD ENVELOPE + HEADERS
POST your-url
X-DeFayke-Event: verification.completed
X-DeFayke-Delivery: 1017 # unique id — deduplicate on it
X-DeFayke-Timestamp: 1761048000 # unix seconds — reject if |now - ts| > 300
X-DeFayke-Signature: sha256=
X-DeFayke-Signature-V2: # HMAC-SHA256(secret, "1761048000.1017." + body)
{ "event": "verification.completed",
"created_at": "2026-09-15T12:00:00",
"data": { // the POST /v1/verify response minus billing fields (credits_charged, balance_remaining)
"verification_id": 101, "status": "completed", "verdict": "clean", "reason_codes": [], "mode": "live",
"fields": { … }, "duplicate": { … }, "match": { … },
"order": { "order_ref": "ORD-12350", "status": "open", "confirmable": false, … } // when order_ref was sent
} }
{ "event": "external_verification.completed", // registry add-on, 1–20 s after the verification
"created_at": "2026-09-15T12:00:03",
"data": { "verification_id": 101, "provider": "check_gov", "status": "confirmed",
"code": "E000-AB12-3456-CDEF", "bank_key": "монобанк", "reason": "eligible", "mode": "live",
"fields": { "amount": 150000, "sender": "…", "recipient": "400000******0002", "op_date": "…" } } }
Events: verification.completed (sync + async; a failed async run arrives with data.status: "failed" and credits_refunded),
external_verification.completed (registry add-on — on receipt, re-read GET /v1/orders/{order_ref}: the order may have become confirmable, or conflicted on not_found / confirmed_mismatch),
balance.low, balance.depleted, balance.topped_up (checks credited — data.checks, balance_remaining), webhook.test.
Delivery: at least once, not strictly ordered (use the ids, and re-read GET /v1/orders/{order_ref} for the final state). Timeout 10 s; redirects are not followed (a 3xx counts as a failure).
Retries: non-2xx or timeout → 1m → 5m → 30m → 2h → 6h, then marked exhausted (visible on the Webhooks page).
No webhook? Poll GET /v1/verifications/{id} / GET /v1/orders/{order_ref} 2–5 s after the response.
5
Python example
Deposit flow with requests: verify every receipt of the order, decide on order.confirmable:
import time, requests
API = "https://api.defayke.ai"
H = {"Authorization": "Bearer rk_live_xxx"}
order = { # your order — the same for every receipt
"order_ref": "ORD-12350",
"expected_amount": "12350.00",
"expected_card": "4000 00** **** 0002",
"expected_iban": "UA213000000000026000000000001", # send both when you have both
"expected_order_date": "2026-09-14T15:33Z", # UTC → append Z (or ask us to set your org timezone)
"expected_date_tolerance_hours": "24",
}
# A) one call per receipt (works for receipts that arrive later, too)
for path in ["part1.pdf", "part2.png"]:
r = requests.post(f"{API}/v1/verify", headers=H, files={"file": open(path, "rb")}, data=order, timeout=90)
r.raise_for_status()
print(path, r.json()["verdict"], r.json()["match"]["amount"], r.json()["order"]["status"])
# B) or all receipts at once
files = [("files", open(p, "rb")) for p in ["part1.pdf", "part2.png"]]
batch = requests.post(f"{API}/v1/verify-batch", headers=H, files=files, data=order, timeout=70 * len(files)).json()
for item in batch["results"]:
print(item["file_name"], item.get("verdict") or item["error"])
# decide — with the registry add-on a receipt may still be checked: wait a little
state = batch["order"] # the order block of the batch answer
for _ in range(10): # up to ~30 s
if state["registry"]["pending"] == 0:
break
time.sleep(3)
state = requests.get(f"{API}/v1/orders/{order['order_ref']}", headers=H, timeout=30).json()
if state["confirmable"]:
credit_deposit() # amount covered, receipts genuine, requisites confirmed
elif state["status"] == "conflicted":
open_dispute(state["conflicts"]) # [{verification_id, reason}]
elif state["status"] == "open":
wait_for_more_receipts(state["amount_remaining"])
else: # settled but something is not proven
manual_review(state["unverified"], state["review_receipts"],
state["reused_receipts"], state["registry"])
Changelog
- 2026-11-24 — test keys no longer query the registry: an eligible receipt returns registry.status: skipped · reason: sandbox (live keys are unchanged). The file type is decided by the file's own bytes, not by its name or MIME type: PDF, JPG, PNG and WEBP are accepted, anything else is 415. A request body above the documented size is refused with 413 before it is read.
- 2026-11-02 — expected_currency now decides the region when it is a country's own money (KZT → kz), over geo_code. Receipts of Kazakhstan, Uzbekistan and Türkiye are compared in their own zone, shown in date_window.tz. Kaspi: a picture of several receipts counts their sum and its oldest date; the transfer form shot before sending shows no amount (amount_unknown), it proves no payment. A-Bank's registry time is now read correctly, so a receipt from a phone in another zone no longer gives a false date_mismatch.
- 2026-11-01 — the bank's answer outranks the file in the order block: a registry-confirmed receipt is counted at the bank's amount when the file shows none or, on a photo, a smaller one (amount_source: registry; a file showing MORE than the bank stays registry_mismatch), and the recipient / date are verified when the registry names your requisite / falls inside date_window; a review verdict over picture-only hints (no_status_bar_detected, photo_of_screen, IBAN/MFO misreads) no longer holds a registry-confirmed receipt. reused_receipts also matches on the registry-confirmed code. registry.status of the receipt itself does not change.
- 2026-09-30 — order.confirmable is now false while a counted receipt waits for the registry, when the same payment already counted in another of your orders — same file, or the same receipt code + amount (new reused_receipts, receipts[].reused_from), and for a receipt older than 72 h sent without expected_order_date (unverified: ["date"]). Receipts outside registry coverage are skipped in the response itself. order.registry now also counts rejected receipts. GET /v1/verifications/{id} returns duplicate, receipt_age_hours, check_depth (null for older records), registry: {"status": "pending"} while the registry is checking, and error for failed async runs; verification.completed carries registry too. A damaged / truncated PDF → 422 (was tampered, charged). Verification reads, outcomes and /v1/usage are scoped to the key's mode; top-ups need a live key for every call. Webhook payloads carry mode (webhook.test: test). receipt_age_hours is measured in receipt-local time (fresh receipts were off by −3 h). expected_amount of NaN / Infinity → 400.
- 2026-09-30 — top-ups by API: POST / GET / DELETE /v1/topups, event balance.topped_up.
- 2026-09-20 — registry answers are compared with the file: confirmed_mismatch → order conflict registry_mismatch; optional outcome feedback endpoints.
- 2026-09-15 — order_ref partial payments, the order block, GET /v1/orders/{ref}, POST /v1/verify-batch.