Ir al contenido

Credits

Credits give a customer currency or metric capacity that billing can apply to eligible charges. A credit grant is the commercial entitlement; an allowance is an individual financial occurrence of that entitlement. A recurring contract grant can produce multiple allowances. Credit notes are separate fiscal correction documents; these APIs do not create credit notes.

All paths below start at /api/v1/public. Both APIs share financial capacity and history. Choose one creation workflow for each purchase; sending it to both APIs creates two grants.

Need API Reference section Endpoint
Create customer currency credits with an explicit billing profile One-off Credits POST /credits/grants
Grant metric units or free promotional credits One-off Credits POST /credits/grants
Create a purchase invoice draft together with credits One-off Credits POST /credits/grants
Inspect or revoke an individual financial allowance One-off Credits GET /credits/grants/{grant_id}, POST /credits/grants/{grant_id}/revoke
Read stable customer or contract-phase grant configuration, refresh rules, and integration IDs Credit Grants GET /credit-grants, GET /credit-grants/{id}
Create a customer currency grant using the compatibility payload Credit Grants POST /credit-grants
Inspect scoped balances and journal activity Credit Balances & History GET /credits/balances, GET /credits/customers, GET /credits/ledger

Contract-phase grants are authored through contract configuration, not by posting a recurring grant to either customer creation endpoint. The read-only configuration view at /credit-grants includes these recurring grants.

Contract One-off credits: /credits/grants Stable grants: /credit-grants
Field names and enums snake_case; lowercase enums camelCase; uppercase enums
Capacity Currency or metric units Customer creation: currency only; reads also expose contract metric grants
Billing profile selection Required billing_entity_id belonging to customer_id Customer must have exactly one active billing profile; ambiguity is rejected
Numbers Exact decimal strings, including metric quantities Exact JSON numbers; up to 15 integer and 10 fractional digits
Availability Issued during creation; effective window still applies Creation returns PENDING; a durable worker issues after commit
Purchase invoice Optional atomic draft with create_invoice and purchase_invoice Not supported by the customer creation payload
Time Offset-aware instants; microseconds retained; expiry exclusive UTC calendar dates; expiry date inclusive
List pagination limit 1–100, default 50; cursor → next_cursor limit 1–100, default 20; after or before, with sortOrder
Identity Financial allowance ID Stable commercial grant ID; a phase ID is not an allowance ID

Do not translate IDs between these representations by assumption. A recurring configuration can have multiple financial occurrences. Use the identifiers returned by the operation you are calling.

Use a bearer API token bound to the organization. Writes require credits:write, which also permits reads. Reads accept credits:read or the reviewed full_read scope. Credentials determine the organization; never send an organization ID in native credit payloads.

Before creating credits:

  1. Find or create the customer using the Customers API.
  2. Read its Billing Entities and select the legal billing account receiving the credits. Use that account’s public ID as billing_entity_id; a customer ID is not a billing-entity ID.
  3. For metric credits, select an existing billable metric. For a purchase invoice, select your issuer billing entity and an active catalog item, and check the applicable invoice tax policy.
  4. Generate an Idempotency-Key once for the intended purchase or promotion. Retain it for retries.

Billing-entity lookup, catalog, and metric operations require their own token scopes; each operation in the API Reference lists them.

This example grants USD 100 of capacity for a USD 80 purchase and creates its purchase invoice draft. Replace the example IDs with resources from your organization. Face value is the capacity the customer receives; purchase price is what the customer pays.

Ventana de terminal
curl --request POST 'https://app.relvoerp.com/api/v1/public/credits/grants' \
--header "Authorization: Bearer $RELVO_API_KEY" \
--header 'Content-Type: application/json' \
--header 'Idempotency-Key: purchase-prepaid-2026-11-17-001' \
--data @purchase.json

Save this request body as purchase.json:

{
"customer_id": "019a8e00-0000-7000-8000-000000000001",
"billing_entity_id": "019a8e00-0000-7000-8000-000000000002",
"name": "Prepaid USD capacity",
"origin": "purchased",
"face_value": {
"kind": "money",
"money": {"amount": "100.00", "currency": "USD"}
},
"purchase_price": {"amount": "80.00", "currency": "USD"},
"expires_at": "2027-01-01T00:00:00.000000Z",
"create_invoice": true,
"purchase_invoice": {
"issuer_billing_entity_id": "019a8e00-0000-7000-8000-000000000003",
"item_id": "019a8e00-0000-7000-8000-000000000004",
"title": "Prepaid capacity purchase",
"issue_date": "2026-11-17",
"payment_terms_days": 30
}
}

A successful 201 response returns the immutable command receipt: id, version, face_value, purchase_invoice_id, and changed. Location points to the allowance detail and ETag carries its version. Read that location for current counters; retrying the creation returns the original receipt even if capacity has since changed.

create_invoice: true requires purchase_invoice and origin: "purchased". The grant and complete invoice draft commit together, or neither does. The receiving billing entity comes from the grant; the issuer is selected separately using issuer_billing_entity_id. The invoice net price is purchase_price; tax references must agree with invoicing fiscal policy.

This creates a draft. It does not finalize or fiscally issue an invoice, contact a fiscal provider, charge a payment method, or wait for payment before making issued credits spendable. Continue through the normal invoice workflow using purchase_invoice_id.

For credits without an invoice, omit purchase_invoice and omit create_invoice or set it to false. Supplying invoice details while the flag is false is rejected.

For a promotion, use origin: "promotional" and a zero purchase_price; promotions cannot create purchase invoices. For metric capacity, replace face_value with:

{
"kind": "metric",
"metric_id": "019a8e00-0000-7000-8000-000000000005",
"quantity": "1000.125"
}

Metric units and monetary purchase price are independent. Use decimal strings and a decimal-capable client; do not round-trip values through binary floating point. Currency inputs must satisfy the currency’s precision without rounding.

Omitting effective_at makes the grant effective at the operation instant. Availability includes effective_at and excludes expires_at; a null expiry means no expiry. A future-effective grant is issued but is not yet spendable. Issuance, validity, revocation, and depletion are separate facts.

Native credit instants require an explicit timezone offset and preserve up to six fractional digits. purchase_date and invoice issue_date are calendar dates spelled YYYY-MM-DD. For the compatibility API, an expiryDate of 2026-12-31 includes that whole UTC day, equivalent to an exclusive native expiry of 2027-01-01T00:00:00Z.

  • GET /credits/grants?customer_id=…&grant_scope=customer lists customer-wide allowances. Without grant_scope, the list also includes contract allowances. Filter billing_schedule_id to inspect a contract lineage.
  • GET /credits/balances?customer_id=… returns that customer’s complete scoped balances without another page. Keep billing entities, currencies, and metrics separate; their values cannot be added into one spendable total.
  • GET /credits/customers pages customer summaries and includes complete balances for each selected customer.
  • GET /credits/ledger?customer_id=… pages immutable movements. Use grant_id or invoice_id to reconcile a specific allowance or invoice. occurred_from is inclusive and occurred_before exclusive; microseconds are preserved.

Spendability considers issuance, reservations, revocation, and the effective window. Expired capacity is not spendable even before an expiry journal entry is posted. Time-sensitive reads include evaluated_as_of. Reads never issue, consume, or repair credits.

For native paginated lists, repeat the same filters and pass next_cursor as cursor until it is null. Cursors are signed and tied to the operation, organization, and filters. They are not interchangeable with /credit-grants before/after cursors. Pages reflect current state rather than a frozen snapshot.

Read GET /credits/grants/{grant_id}, retain its ETag, then call:

Ventana de terminal
curl --request POST \
"https://app.relvoerp.com/api/v1/public/credits/grants/$GRANT_ID/revoke" \
--header "Authorization: Bearer $RELVO_API_KEY" \
--header "If-Match: $GRANT_ETAG" \
--header 'Idempotency-Key: revoke-prepaid-2026-11-17-001' \
--header 'Content-Type: application/json' \
--data '{"reason":"Unused capacity retired at customer request"}'

GRANT_ETAG must contain the complete header value from the detail response, including its quotes. Revocation preserves consumed capacity and financial history. It cannot delete a grant, undo consumed credits, cancel an invoice, or proceed while invoice reservations are outstanding.

Response Meaning and next action
400 missing/invalid idempotency key Supply a valid key; retain the same key and intent for retries.
400 invalid_cursor Restart the list with the intended filters.
403 Check the API token’s operation scope.
404 Check customer, billing entity, or allowance ownership within the token’s organization.
409 idempotency_key_reused The key was already used for a different intent. Correct the request or create a new intentional operation with a new key.
409 transition/concurrency conflict Read the current allowance and reservations before deciding the next action.
412 The allowance changed. Read a fresh ETag, reassess, and submit a new intended operation with a new key.
428 Supply If-Match for revocation.
422 Correct invalid amounts, scope/asset combinations, dates, or invoice terms using the error details.

After a timeout, retry the same request with its original key. Do not issue a new key merely because the response was lost. See Idempotency and Errors for the shared error envelope and concurrency rules.

Sequence’s customer credit workflow supports cash or metric units, expiry, and an optional invoice draft. Relvo’s one-off API covers those workflows with explicit receiver/issuer selection and an atomic draft. Sequence’s older create-credit endpoint is /api/credits; Relvo’s counterpart is POST /api/v1/public/credits/grants.

Sequence’s stable credit-grant resource exposes customer and schedule grants, state, refresh configuration, and integration identifiers. Relvo exposes that view through /api/v1/public/credit-grants. This is payload compatibility for supported operations, not a drop-in transport replacement: authentication, base paths, errors, and the native financial API follow Relvo’s contracts.

Migration concern Relvo behavior
Sequence createInvoice Native create_invoice plus required purchase_invoice details; creates a draft only.
Sequence costOfCredit and amount Native purchase_price and face_value are separate; use exact decimal strings.
Sequence expiry dates Preserve inclusive dates for /credit-grants; convert deliberately to an exclusive instant for native credits.
Deleting a mistaken grant Revoke unused capacity; financial records and journal history remain auditable.
Stable schedule grant ID Inspect configuration via /credit-grants; use the actual financial allowance ID for native detail and revocation.

Check each endpoint in the API Reference when migrating. Similar field names do not guarantee identical lifecycle, validation, pagination, or precision rules.