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

# Sponsor a net debit payment

> Pay a settlement cycle's net debit to the ClearingHouse with the facilitator paying gas.

`POST /clearing/pay`

After a cycle is committed, a net debtor pays its net debit to the `ClearingHouse` before the payment deadline. This endpoint submits that payment and pays the gas. The funds come from the debtor's own signed authorization, which binds the `ClearingHouse` as receiver, the committed amount, and the cycle. The facilitator resolves the amount and the Merkle proof from core, so the caller decides only whether the debit is paid.

The debtor is the authorization's `from`. Send exactly one of `authorization` (EIP-3009) or `permit2Authorization`, as for [`POST /deposit`](https://docs.4mica.io/api-reference/facilitator/deposit). A net debit in native ETH cannot be sponsored; pay it with a transaction of your own.

`POST /clearing/pay/verify` takes the same body, runs every check without broadcasting, and answers with the [`/verify` response shape](https://docs.4mica.io/api-reference/facilitator/verify#responses).

## Request body

**network** `string`

CAIP-2 network ID. When omitted, the facilitator uses the first network it serves whose core knows the cycle. Send it.

**cycleId** `string` *required*

The cycle's text ID: `cycle_id_text` from [`GET /core/participants/{participant}/positions`](https://docs.4mica.io/api-reference/operator/positions).

**assetTransferMethod** `string`

Optional. It must agree with the authorization you send.

**authorization** `object`

EIP-3009 authorization: `from`, `validAfter`, `validBefore`, `nonce`, `v`, `r`, `s`.

**permit2Authorization** `object`

Permit2 authorization: `from`, `nonce`, `deadline`, `signature`.

**eip2612Permit** `object`

Only with `permit2Authorization`: `value`, `deadline`, `v`, `r`, `s`.

## Responses

Every request the facilitator can parse returns `200`. Read `success`.

**success** `boolean` *required*

**transaction** `string`

Transaction hash. Present on success, and on a failure that happened after broadcast.

**network** `string`

**debtor** `string`

The address that paid.

**cycleId** `string`

The cycle's on-chain ID, 32 bytes as hex.

**amount** `string`

The committed net debit, in base units.

**errorReason** `string`

A machine-readable reason code. Present on failure.

**errorMessage** `string`

**extra.retryable** `boolean`

Whether repeating the same request later may succeed. Present on failure.

```bash cURL theme={null}
curl -X POST "https://testnet.payment.4mica.io/clearing/pay" \
  -H "Content-Type: application/json" \
  -d '{
    "network": "eip155:84532",
    "cycleId": "0xba50cd2a20f6da35d788639e581bca8d0b5d4d5f:1796256000",
    "authorization": {
      "from": "0x1111111111111111111111111111111111111111",
      "validAfter": "0x0",
      "validBefore": "0x6b0f1a80",
      "nonce": "0x4444444444444444444444444444444444444444444444444444444444444444",
      "v": 27,
      "r": "0x7777777777777777777777777777777777777777777777777777777777777777",
      "s": "0x8888888888888888888888888888888888888888888888888888888888888888"
    }
  }'
```

```javascript title="Fetch" theme={null}
const response = await fetch("https://testnet.payment.4mica.io/clearing/pay", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({ network: "eip155:84532", cycleId, authorization }),
});
console.log(await response.json());
```

```python Python theme={null}
import requests
body = {"network": "eip155:84532", "cycleId": cycle_id, "authorization": authorization}
print(requests.post("https://testnet.payment.4mica.io/clearing/pay", json=body).json())
```

```json 200 Paid theme={null}
{
  "success": true,
  "transaction": "0x9999999999999999999999999999999999999999999999999999999999999999",
  "network": "eip155:84532",
  "debtor": "0x1111111111111111111111111111111111111111",
  "cycleId": "0x4444444444444444444444444444444444444444444444444444444444444444",
  "amount": "370000"
}
```

```json 200 Refused theme={null}
{
  "success": false,
  "errorReason": "chain_unavailable",
  "errorMessage": "the chain could not be reached; retry shortly",
  "extra": { "retryable": true }
}
```

## Reason codes

| `errorReason` | Meaning |
| - | - |
| `invalid_payload` | The body is malformed, or `cycleId` is not a cycle text ID (the on-chain `0x` hash is refused). |
| `unsupported_transfer_method` | `assetTransferMethod` is neither `eip3009` nor `permit2`. |
| `invalid_signature` | The signature is malformed or does not recover to `from`. |
| `clearing_action_unavailable` | Core served no net debit for this address in this cycle: the cycle is unknown, not yet committed, or the address is not a net debtor in it. |
| `clearing_action_mismatch` | Core's terms prove a different participant from the authorization's `from`. The facilitator does not submit them. |
| `authorization_expired` | The authorization's validity window has ended. |
| `authorization_not_yet_valid` | The authorization's validity window has not started. |
| `nonce_already_used` | The authorization was already spent. |
| `insufficient_funds` | The debtor does not hold the amount. |
| `permit2_allowance_required` | The debtor has not approved Permit2 for the token. |
| `simulation_reverted` | The payment would revert, for example after the payment deadline. |
| `sponsorship_unavailable` | The facilitator is not set up to sponsor gas on this network. |
| `relayer_underfunded` | The relayer cannot pay for gas right now. |
| `gas_ceiling_exceeded` | The payment needs more gas than the facilitator sponsors. |
| `rate_limited` | Too many requests. Retry shortly. |
| `duplicate_in_flight` | The same authorization is already being submitted. |
| `chain_unavailable` | The chain, or this network's core or gas relayer, could not be reached. Retry shortly. |
| `broadcast_failed` | The transaction could not be broadcast. |
| `settlement_pending` | The transaction was broadcast but its receipt could not be read. `transaction` carries the hash. |
| `invalid_transaction_state` | The transaction was mined and reverted. |

## Status codes

| Code | Description |
| - | - |
| `200` | The facilitator processed the request. Check `success`. |
| `400`, `415`, `422` | The body is not JSON the endpoint can parse. The response is plain text. |


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