# Create collect

URL: https://docs.hanzo.ai/docs/openapi/billing/collectinvoice

> Collects an issued invoice: credit grants first, then prepaid balance, then the card on file — the same waterfall the dunning workflow runs.

`POST /v1/billing/invoices/{id}/collect`

> [Billing →](https://docs.hanzo.ai/docs/openapi/billing) · [All API references →](https://docs.hanzo.ai/docs/openapi) · [Get started →](https://docs.hanzo.ai/docs/guides)

|               |                                                         |
| ------------- | ------------------------------------------------------- |
| **Address**   | `https://api.hanzo.ai/v1/billing/invoices/{id}/collect` |
| **Method**    | `POST`                                                  |
| **Operation** | `collectInvoice`                                        |
| **Auth**      | `Authorization: Bearer $HANZO_API_KEY`                  |

Collects an issued invoice: credit grants first, then prepaid balance, then the
card on file — the same waterfall the dunning workflow runs. It spends the
named customer's money, so it is the org admin's act; a member is refused 403.

A DECLINE IS NOT AN ERROR. It answers with paid=false, a reason, and the
invoice still open, because a declined collection is a normal business outcome
that must remain retryable — and because sealing it as a failure would wedge
dunning behind a replayed decline. Only a successful collection is sealed, so a
retry of a paid invoice replays the receipt instead of charging again.

A named handler, not a closure, so zipdoc can lift this prose into the registry.

## Request

1 field.

| Field | In   | Type   | Required | Description           |
| ----- | ---- | ------ | -------- | --------------------- |
| `id`  | path | string | yes      | ID is the invoice id. |

## Response

| Status    | Body              | Meaning |
| --------- | ----------------- | ------- |
| `200`     | billing.Collected | ok      |
| `default` | problem-details   | refused |

`200` body — 23 fields.

| Field                         | In   | Type                   | Always | Description                                                                                                                                      |
| ----------------------------- | ---- | ---------------------- | ------ | ------------------------------------------------------------------------------------------------------------------------------------------------ |
| `balanceUsedCents`            | body | integer (int64)        | —      | BalanceUsedCents is how much was covered by prepaid balance.                                                                                     |
| `cardChargedCents`            | body | integer (int64)        | —      | CardChargedCents is how much was charged to the card on file.                                                                                    |
| `creditUsedCents`             | body | integer (int64)        | —      | CreditUsedCents is how much was covered by credit grants.                                                                                        |
| `invoice`                     | body | billing.Invoice        | —      |                                                                                                                                                  |
| `invoice.amountDueCents`      | body | integer (int64)        | —      | AmountDueCents is what remains collectible.                                                                                                      |
| `invoice.amountPaidCents`     | body | integer (int64)        | —      | AmountPaidCents is what has been collected so far.                                                                                               |
| `invoice.createdAt`           | body | string                 | —      | CreatedAt is when the draft was raised, RFC3339.                                                                                                 |
| `invoice.currency`            | body | string                 | —      | Currency is the ISO 4217 code.                                                                                                                   |
| `invoice.customerEmail`       | body | string                 | —      | CustomerEmail is where it is sent.                                                                                                               |
| `invoice.id`                  | body | string                 | —      | ID is the invoice id — what the issue, collect and void ops address.                                                                             |
| `invoice.lines`               | body | billing.InvoiceLine\[] | —      | Lines are the charges on the invoice.                                                                                                            |
| `invoice.lines[].amount`      | body | integer (int64)        | —      | Amount is the line total in whole cents (250000 is $2,500.00).                                                                                   |
| `invoice.lines[].description` | body | string                 | —      | Description is the human-readable line, e.g. "Advisory retainer — August".                                                                       |
| `invoice.lines[].quantity`    | body | integer (int64)        | —      | Quantity is the number of units, when the line is metered.                                                                                       |
| `invoice.lines[].unitPrice`   | body | integer (int64)        | —      | UnitPrice is the per-unit price in cents, when the line is metered.                                                                              |
| `invoice.number`              | body | string                 | —      | Number is the human-facing invoice number, e.g. "INV-0042".                                                                                      |
| `invoice.paymentRef`          | body | string                 | —      | PaymentRef is the processor reference for the collection, once paid.                                                                             |
| `invoice.status`              | body | string                 | —      | Status is draft, open, paid, void or uncollectible.                                                                                              |
| `invoice.subtotalCents`       | body | integer (int64)        | —      | SubtotalCents is the sum of the lines.                                                                                                           |
| `invoice.userId`              | body | string                 | —      | UserID is the customer billed.                                                                                                                   |
| `paid`                        | body | boolean                | —      | Paid reports whether the invoice is now settled in full.                                                                                         |
| `processorRef`                | body | string                 | —      | ProcessorRef is the processor's reference for any card charge — the field that proves money moved at the gateway rather than only in our ledger. |
| `reason`                      | body | string                 | —      | Reason explains a decline or partial collection.                                                                                                 |

Failure carries the platform error shape — see [Errors](https://docs.hanzo.ai/docs/errors).

## Examples

**CLI**

```bash
hanzo billing invoices collect <id>
```

**SDK**

**.ts**

```ts
import { Configuration, BillingApi } from 'hanzoai';

const api = new BillingApi(new Configuration({ accessToken: process.env.HANZO_API_KEY }));
const { data } = await api.collectInvoice({ id: 'id' });
```

**.py**

```python
from hanzoai.cloud import ApiClient, Configuration
from hanzoai.cloud.api import BillingApi

client = ApiClient(Configuration(access_token=os.environ["HANZO_API_KEY"]))
result = BillingApi(client).collect_invoice(id='id')
```

**.go**

```go
cfg := hanzoai.NewConfiguration()
cfg.AddDefaultHeader("Authorization", "Bearer "+os.Getenv("HANZO_API_KEY"))
client := hanzoai.NewAPIClient(cfg)

resp, _, err := client.BillingAPI.CollectInvoice(context.Background()).Execute()
if err != nil {
	return err
}
```

**.rs**

```rust
use hanzo_client::apis::{configuration::Configuration, billing_api};

let mut cfg = Configuration::new();
cfg.bearer_access_token = std::env::var("HANZO_API_KEY").ok();

let result = billing_api::collect_invoice(&cfg, Default::default()).await?;
```

**.java**

```java
import ai.hanzo.cloud.ApiClient;
import ai.hanzo.cloud.api.BillingApi;

ApiClient client = new ApiClient();
client.setBearerToken(System.getenv("HANZO_API_KEY"));

var result = new BillingApi(client).collectInvoice();
```

**HTTP**

```bash
curl -X POST https://api.hanzo.ai/v1/billing/invoices/<id>/collect \
  -H "Authorization: Bearer $HANZO_API_KEY"
```

**MCP**

Tool `billing`, op `collectInvoice` — POST the JSON-RPC envelope to `https://api.hanzo.ai/v1/mcp`.

```bash
curl -X POST https://api.hanzo.ai/v1/mcp \
  -H "Authorization: Bearer $HANZO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
       "jsonrpc": "2.0",
       "id": 1,
       "method": "tools/call",
       "params": {
         "name": "billing",
         "arguments": {
           "op": "collectInvoice",
           "input": {
             "id": "<id>"
           }
         }
       }
     }'
```

---

[Billing API](https://docs.hanzo.ai/docs/openapi/billing) · [All Hanzo APIs](https://docs.hanzo.ai/docs/openapi) · [Interactive reference](https://docs.hanzo.ai/docs/openapi/reference)
