Layers

GET & PATCH /v1/organizations/:orgId/credit-config

Read and set a child organization's monthly cap and auto-refill rule.

View as Markdown

A child organization's spend governance lives in its credit config — the monthly cap and the auto-refill rule. You read and set it with your parent (org:admin) key; a child key never sees or changes its own config. All amounts are in credits (not cents), and each is nullable: null means "no cap" / "no auto-refill".

GET/v1/organizations/{orgId}/credit-config
Phase 1stable
Auth
Bearer
Scope
org:admin

Returns the child's current config plus its live balance and available, so a single call answers "what are this customer's limits, and where's their wallet?".

Path
  • orgId
    string (org_…)required
    The child organization. Must be a direct child of your org — otherwise 404.

GET example

curl https://api.layers.com/v1/organizations/org_d4e5f6a7-8b9c-4d0e-9f2a-3b4c5d6e7f80/credit-config \
  -H "Authorization: Bearer $PARENT_KEY"
200OK
{
  "organizationId": "org_d4e5f6a7-8b9c-4d0e-9f2a-3b4c5d6e7f80",
  "config": {
    "monthlyCreditCap": 5000,
    "refillThreshold": 1000,
    "refillAmount": 2000,
    "autoRefillEnabled": true
  },
  "balance": 5000,
  "available": 4880
}
PATCH/v1/organizations/{orgId}/credit-config
Phase 1stableidempotent
Auth
Bearer
Scope
org:admin

Partial update: send only the fields you're changing. A number sets, null clears, an omitted field is left unchanged. Returns the merged config with the same shape as GET.

Body
  • monthlyCreditCap
    integer ≥ 0 | nulloptional
    Per-billing-period spend ceiling, in credits. `null` removes the cap.
  • refillThreshold
    integer ≥ 0 | nulloptional
    When the child's `available` drops below this, auto-refill fires. Paired with `refillAmount`.
  • refillAmount
    integer > 0 | nulloptional
    Credits moved from the parent on each auto-refill. Paired with `refillThreshold`.
Headers
  • Idempotency-Key
    string (UUID)optional
    Honored — a replay returns the same result without re-applying the patch.

Auto-refill is both-or-neither. After your patch, refillThreshold and refillAmount must be both set (to enable) or both null (to disable). A patch that would leave exactly one set is rejected with 422 (details.code: REFILL_REQUIRES_THRESHOLD_AND_AMOUNT). Setting one side while the other is already set in the stored config is fine — the rule is checked against the merged result. autoRefillEnabled is derived (read-only): it's true exactly when both are set.

PATCH example

# Cap this customer at 5,000 credits/month and auto-refill 2,000 when they drop below 1,000.
curl -X PATCH https://api.layers.com/v1/organizations/org_d4e5f6a7-8b9c-4d0e-9f2a-3b4c5d6e7f80/credit-config \
  -H "Authorization: Bearer $PARENT_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
    "monthlyCreditCap": 5000,
    "refillThreshold": 1000,
    "refillAmount": 2000
  }'
200OK — config updated, current balances echoed
{
  "organizationId": "org_d4e5f6a7-8b9c-4d0e-9f2a-3b4c5d6e7f80",
  "config": {
    "monthlyCreditCap": 5000,
    "refillThreshold": 1000,
    "refillAmount": 2000,
    "autoRefillEnabled": true
  },
  "balance": 5000,
  "available": 4880
}

To turn auto-refill off, clear both refill fields: { "refillThreshold": null, "refillAmount": null }. To remove the cap, { "monthlyCreditCap": null }. An empty body {} is a no-op that echoes the current config.

Field notes

  • All three knobs are credits, never cents.
  • autoRefillEnabled is computed from the two refill fields — you don't (and can't) set it directly.
  • The same config object rides along on the GET /v1/organizations/:orgId summary as summary.creditConfig.
  • A never-funded child (no wallet row yet) returns an all-null config with autoRefillEnabled: false and balance/available of 0GET never 404s on this. A PATCH on such a child creates its config row.
  • What a child experiences from these settings is covered in the Credits concept: an over-cap reservation gets 402 BILLING_EXHAUSTED with details.reason: "cap"; auto-refill tops the child up transparently from the parent.

Errors

StatusCodeWhen
403FORBIDDEN_SCOPEKey lacks org:admin.
404NOT_FOUND:orgId is not a direct child of your org (anti-enumeration).
409CONFLICTThe child is archived — a terminal org's config can't be changed.
422VALIDATIONA field is out of bounds, or the patch breaks the both-or-neither refill rule (details.code: REFILL_REQUIRES_THRESHOLD_AND_AMOUNT).
503KILL_SWITCHYour key or org is suspended.

See also

On this page