Skip to main content
POST
debit capacity for a long-lived process to spend locally

Authorizations

Authorization
string
header
required

Bearer authentication header of the form Bearer <token>, where <token> is your auth token.

Body

application/json

The lease request

key
string
required

The budget's key, chosen by you and unique within the project. Up to 128 letters, digits, and : / _ . @ -, starting with a letter or digit.

Pattern: ^[A-Za-z0-9][A-Za-z0-9:/_.@-]{0,127}$
Example:

"customer:acme"

leaseKey
string
required

Up to 256 characters, one per lease, chosen by the client. Retrying a grant with the same key, amount, and ttlMs replays it, and replays a 402 for 10 minutes; another amount or ttlMs returns 409. Lease keys and idempotency keys are separate.

Required string length: 1 - 256
Example:

"lease_01J9Z3"

amount
string
required

Capacity to debit now against every hard limit and spend locally. Near a limit less is granted; when nothing fits, 402.

Pattern: ^\d{1,19}(\.\d{1,8})?$
Example:

"0.05"

ttlMs
integer
required

How long the lease lives without a report, in milliseconds: at least 1000 and at most the budget's holds.maxTtlMs. A report renews it once less than half remains. A lease still open at expiry counts its whole grant as used until the window resets.

Required range: x > 0
Example:

60000

ifMissing
object

The budget to create when the key has none: an upsert body without the key, created as a runtime key would. An existing budget ignores it and is never changed by it. The reply says created: true when this call created the budget.

Response

The lease

lease
object
required
terms
object
required

The budget's hold TTL bounds and close time, so holds spent locally follow them

replayed
boolean
required

True when this answer replays an earlier request instead of applying it again

balance
object
required
created
boolean
required

Whether this call created the budget from its ifMissing

Example:

false