GET & PATCH /v1/organizations/:orgId/credit-config
Read and set a child organization's monthly cap and auto-refill rule.
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".
/v1/organizations/{orgId}/credit-config- 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?".
orgIdstring (org_…)requiredThe 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"{
"organizationId": "org_d4e5f6a7-8b9c-4d0e-9f2a-3b4c5d6e7f80",
"config": {
"monthlyCreditCap": 5000,
"refillThreshold": 1000,
"refillAmount": 2000,
"autoRefillEnabled": true
},
"balance": 5000,
"available": 4880
}/v1/organizations/{orgId}/credit-config- 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.
monthlyCreditCapinteger ≥ 0 | nulloptionalPer-billing-period spend ceiling, in credits. `null` removes the cap.refillThresholdinteger ≥ 0 | nulloptionalWhen the child's `available` drops below this, auto-refill fires. Paired with `refillAmount`.refillAmountinteger > 0 | nulloptionalCredits moved from the parent on each auto-refill. Paired with `refillThreshold`.
Idempotency-Keystring (UUID)optionalHonored — 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
}'{
"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.
autoRefillEnabledis computed from the two refill fields — you don't (and can't) set it directly.- The same
configobject rides along on theGET /v1/organizations/:orgIdsummary assummary.creditConfig. - A never-funded child (no wallet row yet) returns an all-null
configwithautoRefillEnabled: falseandbalance/availableof0—GETnever 404s on this. APATCHon 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_EXHAUSTEDwithdetails.reason: "cap"; auto-refill tops the child up transparently from the parent.
Errors
| Status | Code | When |
|---|---|---|
| 403 | FORBIDDEN_SCOPE | Key lacks org:admin. |
| 404 | NOT_FOUND | :orgId is not a direct child of your org (anti-enumeration). |
| 409 | CONFLICT | The child is archived — a terminal org's config can't be changed. |
| 422 | VALIDATION | A field is out of bounds, or the patch breaks the both-or-neither refill rule (details.code: REFILL_REQUIRES_THRESHOLD_AND_AMOUNT). |
| 503 | KILL_SWITCH | Your key or org is suspended. |
See also
- Credits concept → caps and auto-refill — what these settings do.
- Allocate credits — manual parent→child funding.
- Child wallet — read
balance/available.