> ## Documentation Index
> Fetch the complete documentation index at: https://docs.lerian.studio/llms.txt
> Use this file to discover all available pages before exploring further.

# Antifraud partner contract

> What an antifraud partner implements to answer Lerian Pix and TED plugins: headers, answers, authentication, the resolve and feedback calls, and the four payload schemas field by field.

This page is for the team that builds the antifraud partner of an institution, or the transformer in front of it. Pix and TED plugins ask the partner about an operation with an HTTP call. The partner answers `ALLOW`, `REVIEW` or `DENY`.

The plugin pages say when each plugin asks, and what each answer does: [Pix Lerian](https://docs.lerian.studio/en/interfaces/pix-lerian/pix-lerian-antifraud.md), Pix BTG, Pix JD, [TED Lerian](https://docs.lerian.studio/en/interfaces/ted-lerian/ted-lerian-antifraud.md) and TED JD.

## The evaluation call

***

The plugin sends a `POST` of a JSON body to the `endpoint` of the route. Your institution writes the route. The call carries these headers:

| Header | Value |
| - | - |
| `Idempotency-Key` | The stable key of the evaluation. The same key returns the same analysis. For a TED, the transfer id, with a suffix on the recipient side of a P2P transfer: `.in` in TED JD and `:in` in TED Lerian. For a Pix, the key that the plugin page names. Treat the key as opaque text, never as a UUID. |
| `X-Lerian-Decide-By` | The absolute deadline of the decision, in RFC 3339 UTC. |
| `X-Lerian-Payload-Schema` | The schema of the body: `ted-out.v1`, `ted-in.v1`, `pix-out.v1` or `pix-cashin.v1`. |
| `X-Webhook-Timestamp` | The Unix time in seconds. Only with the auth mode `hmac-v1`. |

The endpoint can also receive a `HEAD` request with no authentication. The plugin sends it to keep the connection warm and ignores the answer.

The schemas are open: none forbids extra properties. Validate a body with the schema that the header names, and ignore every field you do not know. A body can match more than one schema, so trust the header, never the shape.

### Authentication

The route names one `auth.mode`. Every mode sends the headers above. A route can add its own static headers, and the credential bundle can add more. The headers of the contract cannot be overridden.

| Mode | What you verify |
| - | - |
| `hmac-v1` | `X-Webhook-Signature` is `v1,sha256=` followed by the hex HMAC-SHA256 of `v1:<timestamp>.<raw body>`. The key is the shared secret, which has at least 32 characters. `<timestamp>` is the decimal value of `X-Webhook-Timestamp`. The plugin signs the exact body bytes and uses a new timestamp on every attempt. Replay protection is yours: reject a stale timestamp. |
| `lerian-m2m` | A bearer token that the plugin gets from the Lerian M2M client credentials flow, with the `clientId` of the route and the `secret` of the credential. |
| `oauth2-client-credentials` | A bearer token that the plugin gets from the `tokenUrl` of the route, with the `clientId`, the `secret` and the optional `scopes`. |

The plugin caches the token and refreshes it. A `401` on a call with a token drops the token, and the plugin repeats the call once at once. A second `401` is final.

### The answer

Answer `200` with a JSON body:

| Field | Meaning |
| - | - |
| `decision` | `ALLOW`, `REVIEW` or `DENY`, in upper case. Any other value is not a decision. |
| `analysisId` | 1 to 64 printable ASCII characters, with no space. Required with `REVIEW`. It travels raw in the `X-Idempotency` header of the resolve call. |
| `score` | Optional. A string or a number. The plugin keeps it as text and never decides by it. |
| `reasons` | Optional. A list of objects with a required `code` and an optional `description`. |

```json theme={null}
{
  "decision": "REVIEW",
  "analysisId": "an-8841",
  "score": "0.82",
  "reasons": [{ "code": "NEW_PAYEE", "description": "First transfer to this payee" }]
}
```

A `202` answer counts as `REVIEW`, and it needs an `analysisId`, unless the body says `DENY`. A `DENY` is honored in a `202` too, and it needs no `analysisId`.

The plugin reads a body of at most 64 KiB, and ignores unknown fields. It drops a malformed side field and keeps the decision. The side fields are a `reasons` entry with an empty, non-string or control-character `code`, an invalid `analysisId` on `ALLOW` or `DENY`, and a `score` that is not a string or a number.

A `DENY` or a `REVIEW` with a reason that has the `code` `AG01`, on a received Pix, makes Pix Lerian refuse the Pix with `AG01` and Pix BTG and Pix JD refuse it with `DS04`, without the fraud mark. See the plugin pages.

### What is not a decision

Any status other than `200` or `202` is not a decision. So is a `decision` outside the three values, and a `REVIEW` with no valid `analysisId`. In every case the `posture` of the route decides: an `OPEN` band allows, and a `CLOSED` band denies. A received TED is the exception: TED JD and TED Lerian hold it for a person of your institution, and no `posture` applies.

| Status | What the plugin does |
| - | - |
| `401`, `403` | An authentication error. The plugin does not repeat it, except the single `401` retry with a fresh token. |
| `408`, `429`, `5xx`, a network error | The plugin repeats the call with the same `Idempotency-Key`, up to `maxAttempts`, inside the shorter of `X-Lerian-Decide-By` and `syncBudgetMs`. It waits at least the `Retry-After` time. A circuit breaker per route opens after repeated failures, and the posture decides while it is open. |
| Any other status | An invalid answer. The plugin does not repeat it. |

The plugin never follows a redirect. In BYOC, the plugin refuses an `http` destination or a private address unless the deploy lists the host. The plugin does not repeat a call to a destination whose certificate does not verify, and it denies the operation in any posture.

## The resolve call

***

When the plugin holds an operation on a `REVIEW`, the partner decides later and sends the final decision to the plugin. The route is the plugin's own, in its own vocabulary. The plugin page names it. The call takes the `Authorization` header with the token of an application that holds the decision permission of the plugin, and these fields:

| Part | Meaning |
| - | - |
| `X-Idempotency` | Send the raw text `<analysisId>:<decision>`, 1 to 128 printable ASCII characters. Repeat a `5xx` with the same key and the same body. |
| `analysisId` | Required. The id that you sent with the `REVIEW`. |
| `decision` | Required. `ALLOW` or `DENY`. Only these two are final. |
| `reasons` | Optional. The same shape as in the answer. A bad entry is dropped, never the request. |

The body is at most 16 KiB.

```json theme={null}
{
  "analysisId": "an-8841",
  "decision": "DENY",
  "reasons": [{ "code": "CONFIRMED_FRAUD" }]
}
```

| Status | Meaning |
| - | - |
| `200` | The plugin applied the decision. |
| `404` | The operation is unknown. |
| `409` | Final, do not repeat. Another decision, the deadline or a cancel closed the analysis first, or the `analysisId` does not match. |
| `422` | The body is not valid. |
| `5xx` | A temporary failure, including `503` with `Retry-After`. Repeat with the same key and the same body. |

## The feedback call

***

When the route has a `feedbackEndpoint`, the plugin can report how an evaluated operation ended. It sends a `POST` to that address with the same auth mode as the evaluation. The `Idempotency-Key` is the key of the evaluation, a colon and the `outcome`. The partner must apply each outcome once, and answers `200` or `202`.

| Field | Meaning |
| - | - |
| `evaluationKey` | Required. The `Idempotency-Key` of the evaluation. |
| `analysisId` | Optional. The id of the analysis, when there was one. |
| `decisionOrigin` | Required. `PROVIDER` when the partner decided, `FALLBACK` when the posture decided. |
| `outcome` | Required. `SETTLED`, `REJECTED`, `CANCELLED`, `RETURNED`, `EXPIRED` or `FRAUD_CONFIRMED`. Each plugin page says which operations it reports and the outcomes it sends. |
| `occurredAt` | Required. When the operation ended, in RFC 3339 UTC. |

```json theme={null}
{
  "evaluationKey": "0193a6f2-6d3e-7c4b-9a51-2f7d8e1c4b10",
  "analysisId": "an-8841",
  "decisionOrigin": "PROVIDER",
  "outcome": "SETTLED",
  "occurredAt": "2026-11-11T14:31:07Z"
}
```

The plugin repeats the report after a transient failure: a `408`, a `429`, a `5xx`, a network error or an open breaker. A refused report, such as a `4xx` or a malformed one, is final.

## Common rules of the payloads

***

* A field that the rail did not bring is absent. Absent means that the rail did not say.
* The `amount` is a string with two decimals, with 1 to 16 integer digits, for example `1500.00`. The `currency` is always `BRL`.
* Times are RFC 3339 UTC.
* `payer` pays and `payee` receives, from the point of view of the money.
* `flow` is `EXTERNAL` when the other side is at another institution, and `INTRA` when both sides are accounts of your institution.
* `metadata` is a JSON object that the origin of the operation sent. The plugin passes it on without reading it. Where a plugin page says that it carries metadata, the partner receives it only on this call.

Every `party` has these fields. Only `ispb` is always present. The sections below say which others each schema requires.

| Field | Format |
| - | - |
| `name` | Text of 200 characters at most. |
| `taxId` | A CPF of 11 digits, or a CNPJ of 12 letters or digits and 2 digits. |
| `personType` | `NATURAL_PERSON` or `LEGAL_PERSON`. |
| `ispb` | 8 letters or digits in upper case. |
| `branch` | 1 to 4 digits. |
| `account` | 1 to 20 characters. |
| `accountType` | `CACC`, `SVGS`, `TRAN`, `SLRY` or `OTHR`. |
| `key` | The Pix key, of 77 characters at most. |
| `accountId` | The UUID of the account in the ledger of your institution. |

## ted-out.v1

***

A TED that your institution sends, or an internal transfer seen from the payer side.

| Field | Required | Format |
| - | - | - |
| `transferId` | Yes | A UUID. |
| `flow` | Yes | `EXTERNAL` or `INTRA`. |
| `amount` | Yes | The amount string. |
| `currency` | Yes | `BRL`. |
| `purposeCode` | With `EXTERNAL` | A number from 1 to 99999, as a string. |
| `description` | No | Text of 200 characters at most. |
| `clientReference` | No | Text of 64 characters at most. |
| `payer` | Yes | A party with `taxId`, `account` and `accountId` required. |
| `payee` | Yes | A party with `taxId` and `account` required. |
| `createdAt` | Yes | The creation time. |
| `metadata` | No | An object. |

```json theme={null}
{
  "transferId": "0193a6f2-6d3e-7c4b-9a51-2f7d8e1c4b10",
  "flow": "EXTERNAL",
  "amount": "1500.00",
  "currency": "BRL",
  "purposeCode": "5",
  "description": "Pagamento de fornecedor",
  "clientReference": "INV-2026-0042",
  "payer": {
    "name": "Empresa Exemplo Ltda",
    "taxId": "11222333000181",
    "ispb": "12345678",
    "branch": "0001",
    "account": "123456",
    "accountType": "CACC",
    "accountId": "0193a6f2-6d3e-7c4b-9a51-2f7d8e1c4b20"
  },
  "payee": {
    "name": "Maria Silva",
    "taxId": "52998224725",
    "ispb": "87654321",
    "branch": "1234",
    "account": "98765",
    "accountType": "CACC"
  },
  "createdAt": "2026-11-11T14:30:00Z",
  "metadata": { "orderId": "A-1001", "channel": "api" }
}
```

## ted-in.v1

***

A TED that your institution receives, or an internal credit seen from the payee side.

| Field | Required | Format |
| - | - | - |
| `transferId` | Yes | A UUID. |
| `flow` | Yes | `EXTERNAL` or `INTRA`. |
| `amount` | Yes | The amount string. |
| `currency` | Yes | `BRL`. |
| `messageCode` | With `EXTERNAL` | The STR message, for example `STR0008R2`. |
| `numCtrlStr` | With `EXTERNAL` | The control number of the STR message, 20 characters at most. |
| `settledAt` | With `EXTERNAL` | When the STR settled the TED. |
| `nuop` | No | 23 letters or digits in upper case. |
| `purposeCode` | No | A number from 1 to 99999, as a string. |
| `description` | No | Text of 200 characters at most. |
| `payer` | Yes | A party. `accountId` is absent when the payer has no account in your ledger. |
| `payee` | Yes | A party with `account` and `accountId` required. |
| `createdAt` | Yes | When the plugin received the TED. |
| `metadata` | No | An object. Absent on a received TED. On a P2P transfer, the `metadata` of the origin. |

```json theme={null}
{
  "transferId": "0193a6f2-6d3e-7c4b-9a51-2f7d8e1c4b12",
  "flow": "EXTERNAL",
  "amount": "980.00",
  "currency": "BRL",
  "messageCode": "STR0008R2",
  "numCtrlStr": "STR20261111000123",
  "settledAt": "2026-11-11T15:00:05Z",
  "nuop": "12345678901234567890123",
  "purposeCode": "10",
  "description": "Reembolso",
  "payer": {
    "name": "Maria Silva",
    "taxId": "52998224725",
    "ispb": "87654321",
    "branch": "1234",
    "account": "98765",
    "accountType": "CACC"
  },
  "payee": {
    "name": "Empresa Exemplo Ltda",
    "taxId": "11222333000181",
    "ispb": "12345678",
    "branch": "0001",
    "account": "123456",
    "accountType": "CACC",
    "accountId": "0193a6f2-6d3e-7c4b-9a51-2f7d8e1c4b20"
  },
  "createdAt": "2026-11-11T15:00:06Z"
}
```

## pix-out.v1

***

A Pix that your institution sends, or an internal Pix seen from the payer side.

| Field | Required | Format |
| - | - | - |
| `transferId` | Yes | A UUID. |
| `endToEndId` | No | 32 letters or digits. Absent only when the sending rail has not created it yet. Correlate by `transferId`, which is always present. |
| `flow` | Yes | `EXTERNAL` or `INTRA`. |
| `initiationType` | Yes | `MANU`, `DICT`, `QRES`, `QRDN`, `INIC`, `AUTO`, `APDN` or `APES`. |
| `transactionType` | No | `TRANSFER`, `CHANGE`, `WITHDRAWAL`, `INSTANT_PAYMENT_REFUND` or `REFUND_AUTOMATIC_PIX`. |
| `amount` | Yes | The amount string. |
| `currency` | Yes | `BRL`. |
| `description` | No | Text of 200 characters at most. |
| `txId` | No | Text of 1 to 35 characters. |
| `payer` | Yes | A party with `taxId` and `account` required. `accountId` is absent when the payer has no account in your ledger. `ispb`, `account` and `taxId` still identify the payer. |
| `payee` | Yes | A party with `taxId` and `account` required. |
| `createdAt` | Yes | The creation time. |
| `metadata` | No | An object. The `metadata` that the caller sent to the plugin. |

```json theme={null}
{
  "transferId": "0193a6f2-6d3e-7c4b-9a51-2f7d8e1c4b14",
  "endToEndId": "E12345678202611111430a1B2c3D4e5F",
  "flow": "EXTERNAL",
  "initiationType": "DICT",
  "transactionType": "TRANSFER",
  "amount": "1500.00",
  "currency": "BRL",
  "description": "Pagamento de fornecedor",
  "txId": "TX20261111001",
  "payer": {
    "name": "Empresa Exemplo Ltda",
    "taxId": "11222333000181",
    "ispb": "12345678",
    "branch": "0001",
    "account": "123456",
    "accountType": "CACC",
    "accountId": "0193a6f2-6d3e-7c4b-9a51-2f7d8e1c4b20"
  },
  "payee": {
    "name": "Maria Silva",
    "taxId": "52998224725",
    "ispb": "87654321",
    "branch": "1234",
    "account": "98765",
    "accountType": "CACC",
    "key": "maria@example.com"
  },
  "createdAt": "2026-11-11T14:30:00Z",
  "metadata": { "orderId": "A-2001" }
}
```

## pix-cashin.v1

***

A Pix that your institution receives, or an internal Pix seen from the payee side. It never carries a received return.

| Field | Required | Format |
| - | - | - |
| `endToEndId` | Yes | 32 letters or digits. |
| `flow` | Yes | `EXTERNAL` or `INTRA`. |
| `initiationType` | No | `MANU`, `DICT`, `QRES`, `QRDN`, `INIC`, `AUTO`, `APDN` or `APES`. An unknown value is omitted. |
| `transactionType` | No | `TRANSFER`, `CHANGE`, `WITHDRAWAL`, `INSTANT_PAYMENT_REFUND` or `REFUND_AUTOMATIC_PIX`. |
| `amount` | Yes | The amount string. |
| `currency` | Yes | `BRL`. |
| `description` | No | Text of 200 characters at most. |
| `txId` | No | Text of 1 to 35 characters. |
| `payer` | Yes | A party with `taxId` required. |
| `payee` | Yes | A party with `account` and `accountId` required. |
| `metadata` | No | An object. Absent unless the plugin page says that it carries one. |

```json theme={null}
{
  "endToEndId": "E12345678202611111930k7Qz9XwP2aB",
  "flow": "EXTERNAL",
  "initiationType": "DICT",
  "amount": "1500.00",
  "currency": "BRL",
  "description": "aluguel novembro",
  "payer": {
    "name": "Maria Silva",
    "taxId": "12345678909",
    "personType": "NATURAL_PERSON",
    "ispb": "12345678",
    "branch": "1",
    "account": "123456",
    "accountType": "CACC"
  },
  "payee": {
    "name": "Joao Souza",
    "taxId": "98765432100",
    "personType": "NATURAL_PERSON",
    "ispb": "87654321",
    "branch": "1",
    "account": "654321",
    "accountType": "CACC",
    "key": "joao@example.com",
    "accountId": "0193a6f2-6d3e-7c4b-9a51-2f7d8e1c4b20"
  }
}
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.