> ## 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 credit claim

> Claim a settlement cycle's net credit from the ClearingHouse with the facilitator paying gas.

`POST /clearing/claim`

A net creditor claims its net credit from the `ClearingHouse` once the cycle's debtors have paid, or once unpaid debits have been taken from collateral. This endpoint submits `claimNetCreditFor` and pays the gas. The request carries no signature: the payout goes to `creditor` for the amount the committed Merkle leaf fixes, so the caller can only choose which claim is submitted.

Send `cycleId` to claim one cycle. Leave it out and the facilitator claims every open credit the creditor has, up to 20 cycles in one call.

`POST /clearing/claim/verify` takes the same body with `cycleId` required, 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 or holds an open credit. Send it.

**creditor** `string` *required*

The address that is owed.

**cycleId** `string`

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

## Responses

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

**success** `boolean` *required*

For a call without `cycleId`, `true` means the sweep ran. Read each entry of `claims` for its own outcome.

**transaction** `string`

Single claim only. Transaction hash.

**network** `string`

**creditor** `string`

**cycleId** `string`

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

**amount** `string`

Single claim only. The committed net credit, in base units. In a cycle marked as a shortfall the on-chain payout can be a pro rata share of this.

**claims** `array`

Sweep only. One entry per open credit.

**claims\[].cycleId** `string`

**claims\[].cycleIdText** `string`

**claims\[].outcome** `string`

`claimed`, `already_claimed`, `cycle_finalized`, `not_claimable_yet`, or a reason code from the table below.

**claims\[].transaction** `string`

**claims\[].amount** `string`

Present when `outcome` is `claimed`.

**claims\[].retryable** `boolean`

Present when the cycle was not claimed.

**claims\[].message** `string`

Present when the cycle was not claimed.

**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/claim" \
  -H "Content-Type: application/json" \
  -d '{
    "network": "eip155:84532",
    "creditor": "0x2222222222222222222222222222222222222222",
    "cycleId": "0xba50cd2a20f6da35d788639e581bca8d0b5d4d5f:1796256000"
  }'
```

```bash Every open credit theme={null}
curl -X POST "https://testnet.payment.4mica.io/clearing/claim" \
  -H "Content-Type: application/json" \
  -d '{
    "network": "eip155:84532",
    "creditor": "0x2222222222222222222222222222222222222222"
  }'
```

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

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

```json 200 Claimed theme={null}
{
  "success": true,
  "transaction": "0x9999999999999999999999999999999999999999999999999999999999999999",
  "network": "eip155:84532",
  "creditor": "0x2222222222222222222222222222222222222222",
  "cycleId": "0x4444444444444444444444444444444444444444444444444444444444444444",
  "amount": "370000"
}
```

```json 200 Sweep theme={null}
{
  "success": true,
  "network": "eip155:84532",
  "creditor": "0x2222222222222222222222222222222222222222",
  "claims": [
    {
      "cycleId": "0x4444444444444444444444444444444444444444444444444444444444444444",
      "cycleIdText": "0xba50cd2a20f6da35d788639e581bca8d0b5d4d5f:1796256000",
      "outcome": "claimed",
      "transaction": "0x9999999999999999999999999999999999999999999999999999999999999999",
      "amount": "370000"
    },
    {
      "cycleId": "0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
      "cycleIdText": "0xba50cd2a20f6da35d788639e581bca8d0b5d4d5f:1796342400",
      "outcome": "not_claimable_yet",
      "retryable": true,
      "message": "claim would revert: cycle is funded to 0 of the 370000 required; it becomes claimable once debtors pay"
    }
  ]
}
```

```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). |
| `clearing_action_unavailable` | Core served no net credit for this address in this cycle: the cycle is unknown, not yet committed, or the address is not a net creditor in it. |
| `clearing_action_mismatch` | Core's terms prove a different participant from `creditor`. The facilitator does not submit them. |
| `simulation_reverted` | The claim would revert: it was already claimed, the cycle is finalized, or the cycle's payments are not final yet. |
| `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 claim needs more gas than the facilitator sponsors. |
| `rate_limited` | Too many requests. Retry shortly. |
| `duplicate_in_flight` | The same claim 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.