> ## 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.

# How TED Lerian works

> The lifecycle of each TED Lerian transfer, sent, received and returned, with the statuses the API returns and what each one means for your customer.

## Sending a TED

***

**1. Validate**

TED Lerian checks the amount format, the 5-digit purpose code, the recipient's bank in the STR participant list. It also checks that the recipient document is a CPF or a CNPJ. A failure here creates no transfer.

**2. Apply the policy**

It checks the effective window (the official STR schedule, the institution's cut-off and the holidays), the usage limits and, when configured, the fee calculated by Midaz.

**3. Hold**

TED Lerian holds the amount plus the fee on the source account. Status `RESERVED`.

**4. Send to the STR**

Lerian SPB accepts the command and returns the `nuop`. Status `SUBMITTED`. This is the status the create response usually shows.

**5. Settle**

The STR decides asynchronously: it settles, rejects or keeps the entry pending. The outcome arrives as an event and on a read.

### Statuses of a sent transfer

| Status | What it means | What you can do |
| - | - | - |
| `CREATED` | Recorded; nothing is held yet. On an internal transfer it also means the ledger answer was indeterminate, which the reprocessing resolves. | Cancel |
| `RESERVED` | Amount and fee held; about to go to the STR. | Cancel |
| `SUBMITTED` | Sent to the STR, waiting for its decision. | Wait |
| `PENDING_STR` | The STR accepted the entry and holds it as pending. The hold stays. | Ask the STR to cancel (`202`) |
| `SETTLED` | Settled; the debit is final. Final status. | Nothing. A return from the other institution shows in `returned`. |
| `REJECTED` | Refused by the ledger, Lerian SPB, the STR or an operator, with `rejection.code`, `reason` and `source`. The hold is released. Final status. | Nothing |
| `CANCELLED` | Cancelled; the hold is released. Final status. | Nothing |
| `AWAITING_RECONCILIATION` | No answer in time. The hold is never released on a timeout; reconciliation asks Lerian SPB for the outcome. | An operator unblocks with evidence |
| `EXHAUSTED` | Automatic reconciliation ran out of attempts; the outcome is still unknown. | An operator unblocks with evidence |

> [!NOTE]
>
> Accepted is not settled. A `201` confirms that the TED was accepted and, as a rule, sent. The money left only when the status is `SETTLED`. A refusal by the ledger or by Lerian SPB can already come in the create response (`rejection.source` `LEDGER` or `RAIL`). A refusal by the STR or by an operator shows only on a later read.

## Internal transfers

***

When the recipient's bank is the institution's own ISPB, TED Lerian finds the recipient account in the Midaz CRM. It settles everything in one Midaz transaction. The STR window does not apply, but usage limits and, when configured, the fee do. The response has `type=INTERNAL` and `recipient.accountId` filled in. If the recipient does not exist or belongs to another organization, TED Lerian refuses the request with `TED-1021` and creates no transfer.

## Receiving a TED

***

**1. Record**

Lerian SPB reports that the STR settled a TED for the institution. The 60 minute deadline starts at `interbankSettledAt`.

**2. Route**

TED Lerian finds the ISPB binding of the receiving institution. Without a binding, the TED goes to manual review.

**3. Find and check**

TED Lerian looks up the recipient's branch, account and document in the Midaz CRM. The holder and the account type have to match.

**4. Decide**

It credits the customer, returns the TED with the official reason, or sends it to manual review.

| Status | What it means |
| - | - |
| `RECEIVED` | The STR settled the TED and TED Lerian recorded it. The decision is in progress. |
| `CREDITED` | The amount was credited to the customer. |
| `RETURN_REQUESTED` | The return went to the STR with the official reason. |
| `RETURNED` | The STR settled the return; the money went back to the sending institution. |
| `MANUAL_REVIEW` | TED Lerian could not finish on its own, or the STR refused the return. An operator decides. |

When Lerian SPB delivers a TED twice, TED Lerian credits it only once.

## When another institution returns your TED

***

TED Lerian finds the original transfer, records the return in the transfer's `returned` block and credits the sender back. The transfer stays `SETTLED`, and `transfer.returned` tells your system. By default, TED Lerian does not refund the sending fee. `returned.feeRefunded` says whether it did.

If no settled transfer carries the control number of the returned TED yet, TED Lerian holds the return. It applies the return when that transfer settles. An operator lists the held returns with `GET /v1/reconciliation/held-returns`.

## Cancellation

***

| Current status | Result |
| - | - |
| `CREATED`, `RESERVED` | `200`, cancelled at once, hold released. While a call to Midaz or Lerian SPB for the transfer is in progress, `409 TED-0061`. |
| `PENDING_STR` | `202`, cancellation requested from the STR. The result arrives as `transfer.cancelled` or `transfer.settled`. This cancellation is off by default. While it is off, the answer is `503 TED-1012`. |
| `CANCELLED` | `200`, with no new effect. |
| `SUBMITTED`, `SETTLED`, `REJECTED` | `409 TED-0061`. For money that already left, the path is a return by the other institution. |
| `AWAITING_RECONCILIATION`, `EXHAUSTED` | `409 TED-0061`. The real status at the STR is unknown; unblock with evidence instead. |

Incoming TEDs are never cancellable.

## Reconciliation and unblocking

***

A transfer with no answer in time enters the reconciliation queue with its age and last known status. By default, TED Lerian asks Lerian SPB for the outcome 15 minutes after it accepts the transfer, and tries up to 8 times. Settled turns the hold into a debit, and rejected releases the hold. Any other answer, not found included, keeps the hold until the next attempt. When the attempts run out, the transfer becomes `EXHAUSTED` and an operator unblocks it with the evidence. Nothing is reversed without evidence.

A periodic check also looks for inconsistencies between Midaz and the transfer statuses, such as a return with no recredit or an orphan hold. It lists them for the operator.


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