Skip to content

External credits and billing ​

Stripe is not the only way to bill your customers. If you invoice through your own system, such as bank transfers, another payment provider, a marketplace or manual sales, you can grant and deduct prepaid credits over the API. MicroAuth keeps the ledger and the balance and enforces it. Your system stays the source of truth for payments.

Authentication: automation key ​

The credits endpoint is part of the management API, so it authenticates with an automation key (mak_...), not the SDK secret key:

Authorization: Bearer mak_...

Create one in the dashboard under Workspace settings, in the Advanced section (see automation keys). The key acts with admin access on behalf of the workspace and can manage every API in it. The full key is shown once, when you create it.

Do not mix up the key types

mas_ (SDK secret key) is for the SDK API only. mak_ (automation key) is for management endpoints like this one. See API keys at a glance.

The endpoint ​

POST https://api.microauth.com/v1/tenants/{tenantId}/customers/{customerId}/credits

In REST paths an API is still called a tenant.

  • tenantId is your API's UUID. It is in the dashboard URL (/t/{tenantId}/...) and in GET /v1/tenants.
  • customerId is the customer's UUID. A customer is always a team, never an individual portal user. Even a solo signup gets a one-person team, and the credit balance belongs to that team. Look customers up with GET /v1/tenants/{tenantId}/customers, or copy the ID from the customer's page in the dashboard.

Customer-list and billing responses represent an assigned plan as plan_id: string | null and plan_name: string | null. The plan ID is a UUID string. Do not deserialize it as an integer or assume the display name is an identifier.

Request body:

FieldTypeRequiredMeaning
amount_microintegeryesCredit amount in micro-USD (1,000,000 = $1.00). Positive to grant, negative to deduct. Must be non-zero.
descriptionstring (≤ 300)noFree-text shown in the ledger, e.g. "Invoice #2026-081"
external_refstring (≤ 120)noIdempotency key from your billing system. Strongly recommended

Response:

json
{ "credit_balance_micro": 22500000, "applied": true }

The response contains the balance after the operation and whether this request applied a new ledger entry. An idempotent replay returns applied: false.

Example: grant $10 for a paid invoice ​

bash
curl -X POST \
  "https://api.microauth.com/v1/tenants/$TENANT_ID/customers/$CUSTOMER_ID/credits" \
  -H "Authorization: Bearer mak_..." \
  -H "Content-Type: application/json" \
  -d '{
    "amount_micro": 10000000,
    "description": "Invoice #2026-081 paid via wire",
    "external_ref": "inv_2026_081"
  }'

The same in Python:

python
import requests

r = requests.post(
    f"https://api.microauth.com/v1/tenants/{TENANT_ID}/customers/{CUSTOMER_ID}/credits",
    headers={"Authorization": f"Bearer {WORKSPACE_KEY}"},
    json={
        "amount_micro": 10_000_000,          # $10.00
        "description": "Invoice #2026-081 paid via wire",
        "external_ref": "inv_2026_081",      # idempotency key
    },
    timeout=10,
)
r.raise_for_status()
print("new balance:", r.json()["credit_balance_micro"] / 1_000_000, "USD")

To deduct (a refund or chargeback), send a negative amount with its own reference, e.g. "amount_micro": -10000000, "external_ref": "refund_inv_2026_081". A deduction that would make the balance negative returns 409 and does not write a ledger entry.

Idempotency with external_ref ​

Billing systems retry. Webhooks fire twice. Networks fail after the request was applied but before you saw the response. external_ref makes all of that safe:

  • Each external_ref is unique per API. The first request with a given reference applies the adjustment and writes a ledger entry.
  • An identical replay for the same customer, amount, kind, and description changes nothing. It returns 200, the current balance, and applied: false.
  • Reusing that reference for a different customer, amount, or description returns 409. MicroAuth does not silently accept a conflicting replay.
  • Omitting external_ref disables idempotency for that adjustment. Every retry can create another ledger entry.

So the safe pattern is simply: give every adjustment a stable reference derived from your system (invoice ID, payment intent ID, refund ID), and retry freely on timeouts.

One reference = one adjustment

Do not reuse a reference for a different operation. A refund needs its own reference, not the original invoice's. If a timeout leaves the outcome unknown, retry the exact original body.

Reading the ledger ​

Every adjustment lands in the customer's credit ledger, whether it came from this endpoint, Stripe, a plan's monthly credit or a usage charge:

bash
curl "https://api.microauth.com/v1/tenants/$TENANT_ID/customers/$CUSTOMER_ID/ledger?limit=50&offset=0" \
  -H "Authorization: Bearer mak_..."
json
{
  "total": 3,
  "entries": [
    {
      "id": "5c1f...",
      "amount_micro": 10000000,
      "kind": "external_topup",
      "description": "Invoice #2026-081 paid via wire",
      "external_ref": "inv_2026_081",
      "created_at": "2026-08-03T18:04:11Z"
    }
  ]
}

External adjustments have kind: "external_topup" (for grants and deductions alike); Stripe top-ups, plan credit grants and other movements have their own kinds. The same ledger is visible in the dashboard on the customer's page, where these entries read Credit adjustment, and to the customer on their portal's Billing page.

All API timestamps, including created_at, use RFC 3339 with an explicit timezone. A Z suffix and +00:00 both mean UTC.

How it plays with enforcement ​

The balance you adjust here is the same prepaid balance the SDK enforces:

  • SDKs pick up the new balance on their next snapshot refresh (every 30 seconds by default), so a customer who just paid is unblocked within moments.
  • Usage charges deduct from this balance automatically as usage is reported. You only need to put credits in, or claw them back.

See also ​

  • Customers and limits for granting credit by hand from the dashboard.
  • Custom integration for how usage gets charged against the balance.
  • The API reference for full schemas under the Customers tag, including customer listing, custom limits and the suspension endpoints you may want in your billing automation.

MicroAuth is a product of Zyref, LLC.