# Buy prepaid credit (/api/usage/create-customer-credit-purchase)

`POST https://api.comecero.com/api/v1/customers/{customer_id}/credit_purchases`

Makes an open invoice with one "Prepaid credit" line of `amount`, in the plan's currency, for the customer to pay through the normal invoice payment page. Once it is paid the credit is added to the subscription's usage plan, once whatever repeats. The credit is the line's price before tax, at most `amount`: where prices include tax, it is less than the total paid. The invoice says how much in `credit_purchase.credit_granted` (and in its line's `meta`). The first purchase makes the plan's credit and pays its meters from it. A refund or chargeback of the invoice takes back its share of the credit, as far as it is unused. Your shop must sell credit (`usage_customer_settings` on `/settings/subscription`). A shopper's token buys only for its own customer (`me` works, and needs a customer's login). Here `customer_id` is the Comecero customer id, not your own id. Send an `Idempotency-Key` header so a retry after a timeout never makes a second invoice: the same key with the same body answers the first invoice (`200`) for a day. A plan may have at most 20 unpaid credit invoices at once.

## Parameters

- `customer_id` (path, required): The Comecero customer id, or me.
- `Idempotency-Key` (header): Makes a retry harmless: the same request again with the same key (after a timeout, say) changes nothing more and answers as the first one did. 1 to 128 printable ASCII characters, sent once (`400`, reference `UbV150`); an empty header counts as none. Use a new random key, such as a UUID, for each change you mean to make. The same key with another body is refused (`409`, reference `UbV151`).

Request body: the `credit_purchase_request` schema.

Responses: 200, 201, 400, 401, 403, 404, 409, 500.

Full schemas: operation `create_customer_credit_purchase` in /openapi.json.