Swarmz

Top up credits

Add purchased credits to a tenant. Purely additive, idempotent on your key, and never replaces existing balances.

POSThttps://api.swarmz.net/functions/v1/platform-topup

Adds purchased credits to a tenant. The operation is purely additive — it increments the tenant's top-up balance and never replaces or resets existing balances.

Address the tenant by tenant_id or external_ref — supply exactly one.

Parameters

Prop

Type

Request

curl -X POST https://api.swarmz.net/functions/v1/platform-topup \
  -H "Authorization: Bearer sk_live_..." \
  -H "Content-Type: application/json" \
  -d '{
    "external_ref": "whmcs:1234",
    "amount": 100,
    "idempotency_key": "whmcs:1234:topup-2026-05-23-0001"
  }'
const res = await fetch('https://api.swarmz.net/functions/v1/platform-topup', {
  method: 'POST',
  headers: {
    Authorization: 'Bearer sk_live_...',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    external_ref: 'whmcs:1234',
    amount: 100,
    idempotency_key: 'whmcs:1234:topup-2026-05-23-0001',
  }),
});

const data = await res.json();
import requests

res = requests.post(
    "https://api.swarmz.net/functions/v1/platform-topup",
    headers={"Authorization": "Bearer sk_live_..."},
    json={
        "external_ref": "whmcs:1234",
        "amount": 100,
        "idempotency_key": "whmcs:1234:topup-2026-05-23-0001",
    },
)
data = res.json()

Response

{
  "ok": true,
  "balances": {
    "included_credits": 0,
    "included_credits_used": 0,
    "rollover_credits": 0,
    "rollover_credits_used": 0,
    "topup_credits": 100,
    "daily_bonus_limit": 50,
    "daily_bonus_used": 0
  }
}

For platform tenants, only topup_credits, daily_bonus_limit, and daily_bonus_used are meaningful — the other fields are returned for completeness.

Errors

StatuserrorreasonWhen
400missing_fieldstenant_id or external_ref requiredNeither identifier supplied
400missing_fieldsidempotency_key requiredidempotency_key absent
400invalid_amountamount must be a positive finite numberamount non-positive, non-finite, or not a number
401unauthorizedSee Authentication
404tenant_not_foundNo tenant matched the identifier under your account
405method_not_allowedAnything other than POST
409suspendedThe tenant is suspended
409tenant_not_activeThe tenant is not in an active state
410terminatedThe tenant has been terminated
429rate_limitedper_key / per_ipRate limit hit — see Rate limits
500topup_failedRPC messageTop-up failed server-side; safe to retry

Idempotency

Top-up is idempotent on idempotency_key, scoped per tenant. A retry with the same key is a no-op and returns the current balances rather than adding the amount again. See Idempotency.

Notes

A suspended tenant rejects top-ups

Topping up a suspended tenant returns 409 suspended. Queue the top-up and replay it after unsuspend. Because the idempotency key is scoped per tenant, the queued retry remains safe — re-sending it once the tenant is active applies the credit exactly once.

This endpoint is limited to 60 requests/min per key and 120/min per IP. See Rate limits.

On this page