comecerodocs

Set a customer's spending limit

PUT
/customers/{customer_id}/usage/{subscription_id}/spend_limit

Sets or clears the customer's own spending limit on one subscription's usage. The limit covers usage charges only, before tax (not the plan's regular price); 0 means no usage spend. Usage past it is neither billed nor drawn from prepaid credit. The shop must let customers set one (allow_spend_limit in usage_customer_settings); this holds for your own tokens too. Every change is logged with who made it, when and from where. Raising the limit may bill usage already recorded this period that the old limit held back. A new limit applies at once to usage not billed yet; what this period's bills already committed still counts, so a limit below it means no more usage spend this period. expected_revision is required, so a change made since you read it is never overwritten. Send an Idempotency-Key header so a retry is harmless: for a day, the same key with the same amount and expected_revision changes nothing and answers what the first request answered (the limit and revision as that change left them), even after a later change; the key with another body is refused. The key is noted before the change is made, so a retry of a request that never answered never makes the change twice. An empty header counts as none. Setting the same amount again changes nothing. A shopper's token sets only its own customer's (me works). To raise a limit with the customer's recorded consent, quote it (POST .../spend_limit/quotes) and accept it with PATCH.

Authorization

headerAuthorizationBearer <token>

A secret, trusted or limited token. See Authentication.

Path Parameters

customer_id*string

The Comecero customer id, or me.

subscription_id*string

The customer's subscription.

Header Parameters

Idempotency-Key?string

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

Match^[ -~]{0,128}$
Lengthlength <= 128

Request Body

application/json
  1. body

The customer's own spending limit. amount and expected_revision are the only fields; anything else is refused (400, reference UbV145).

amount*|

The limit on usage charges before tax (not the plan's regular price), an amount of 0 or more as a decimal string in the plan's currency, such as "50", no finer than the currency (at most 2 decimals, or a whole number for a currency without them). 0 means no usage spend. Null clears it, so the shop's default applies again, if there is one.

Match^(?=\.?[0-9])(?:0*[0-9]{0,9}(?:\.[0-9]{0,6}0*)?|0*1000000000(?:\.0*)?)$
expected_revision*integer

Required. The revision read with GET. The change is made only when the limit is still at it; otherwise 409 (reference UbV153): read it again. Missing, not a whole number or below 0 is a 400 (reference UbV154).

Range0 <= value

Response Body

The spending limit now. changes is left out for a shopper's token.

application/json
  1. response

A customer's spending limit on one subscription's usage, in the usage plan's currency. The limit covers usage charges only, before tax: not the plan's regular price, and not tax, which is added on the invoice as usual. Usage paid with prepaid credit counts toward it too, and usage past it in a period is neither billed nor drawn from credit: the limit is shared out across the usage first, and only that share is paid with credit or cash. A limit of 0 means no usage spend. A change applies at once to usage not billed yet; what this period's bills already committed still counts, so a limit below it means no more usage spend this period. The customer gets a warning email at 50 and 80% and an email at 100%; at 100% you get the usage:spend_limit_reached webhook, once per period and limit (again after a change). While your shop uses spending limits, a period that has ended, and its late usage, is billed under the limit in force at its end: the customer's own limit and your allow_spend_limit and default_spend_limit as they were then. While it uses none (allow_spend_limit false and default_spend_limit null), an ended period whose first bill runs then has no limit, and late usage for a period billed under a limit keeps the limit that bill used. Amounts are decimal strings.

object?string
subscription_id?string
currency?string

The currency of the subscription's usage plans, which every amount is in.

amount?|

The customer's own limit. Null when they set none, when the shop does not let customers set one (customer_can_set false), or when it was set for a plan in another currency.

default?|

The shop's limit for customers who set none (default_spend_limit). Null when there is none.

effective?|

The limit now, amount or else default. Null when there is none.

source?|

Where effective comes from, customer (their own) or default (the shop's). Null when there is no limit.

Value in"customer""default"null
spent?string

The usage spend this period so far, before tax: what the period's bills already took (committed) and the usage not billed yet, credit paid and cash, every usage plan of the subscription.

committed?string

The part of spent that bills of this period already charged.

remaining?|

What is left of this period's limit, before tax, never below 0, with this period's one-time extra (burst) while it is in force. Null when there is no limit.

reset_at?|

When the period ends and spent starts again from 0. Null when not known.

Formatdate-time
customer_can_set?boolean

Whether the shop lets customers set their own limit (allow_spend_limit).

revision?integer

Goes up by one with every change; 0 before any. Send it back as expected_revision to change the limit only if nobody changed it since.

Range0 <= value
changes?array<>

Every change, newest first (the last 500), as evidence for a dispute. Secret and trusted tokens only: left out for a shopper's token.

burst_offered?boolean

Whether the customer can ask for a one-time extra this period now (POST .../spend_limit/quotes with operation burst): the shop offers one, the limit in force is above 0, and this period has had none. Left out when the shop never set spend_limit_burst.

burst?

This period's one-time extra, in any status. Left out when the period has none.

effective_limit_amount?string

The most this period's usage may be charged, before tax: the limit in force (effective) plus the one-time extra while it is in force, never below what this period's bills already committed. After the extra is taken back, the limit, or what was committed if that is more. Left out when the period has no extra (the most is then effective).

Example Request
curl -X PUT 'https://api.comecero.com/api/v1/customers/string/usage/string/spend_limit' \  -H 'Idempotency-Key: 3f2b6c1e-9d4a-4e8b-a1f7-5c0d2e9b8a64' \  -H 'Content-Type: application/json' \  -d '{  "amount": "50",  "expected_revision": 2}'
Example Response
{  "object": "usage_spend_limit",  "subscription_id": "SB0123456789",  "currency": "USD",  "amount": "50",  "default": null,  "effective": "50",  "source": "customer",  "spent": "41.5",  "committed": "0",  "remaining": "8.5",  "reset_at": "2026-12-01T00:00:00Z",  "customer_can_set": true,  "revision": 3}

Raise a customer's spending limit with their consent PATCH

Accepts a raise quoted with `POST .../spend_limit/quotes` (`operation` `raise`): the limit becomes the quote's `amount`, and the customer's consent (the quote's `consent_text`, when and from where) is kept in the change log as evidence. Only from the customer's own login, before the quote's `expires_at` (10 minutes, never past the end of the billing period it was made in), in that same period, and only while the limit and the shop's settings are as they were quoted. The same quote sent again answers what the first request answered and changes nothing more. An `Idempotency-Key` header is required, new for each change, so a retry after a timeout answers the first answer (for a day) even if the change was made but its answer was lost; the key with another body is refused. The customer gets an email confirming it (notification `subscription:spend_limit_changed`, when it is on) and you get the `usage:spend_limit_changed` webhook. A plain `PUT` still sets, lowers or clears the limit.

Quote a spending limit raise or a one-time extra POST

Prices a change of the customer's spending limit for them to accept, with the words they accept (`consent_text`). Nothing is changed. `raise` quotes a new limit above the one in force (only when the shop lets customers set one; set a first limit or lower one with `PUT .../spend_limit`). `burst` quotes this period's one-time extra: the shop's `spend_limit_burst`, fixed now, on a limit above 0, ending at the renewal, once per period. A raise quoted while this period's extra is in force names the most the period may then be charged, the new limit plus the extra (`max_total_amount`, `burst_amount`). A raise never states less than what the period already committed, which stays billed: with 115 committed, a raise from 100 to 105 states 115 for this period, and its words say why. Every amount in the words is before tax, and they say that usage already recorded this period, which the limit held back, may be billed. The quote is for the billing period it is made in and can be accepted until `expires_at` (10 minutes, or the end of the period if that comes first), once: a raise with `PATCH .../spend_limit`, an extra with `PUT .../spend_limit/burst`, each only from the customer's own login. A shopper's token quotes only for its own customer (`me` works).