Skip to content

Python SDK

rem_payments 0.2.0 - link an app with one token, open checkouts, read subscriptions, spend REM Credits and verify webhooks from Python.

rem_payments (version 0.2.0) is the server-side Python SDK REM's own apps use (REM CloudHub and REM Vibe Coder). It needs httpx.

from rem_payments import connect, PaymentsClient, CreditsClient, verify_webhook, WebhookProcessor, payer_ref

An app needs only REM Payments' address and one API token pinned to its organization:

out = connect("https://rempayments.com", token=PTK, app="vibecoder",
              webhook_url="https://remvibecoder.com/api/payments/webhook", app_url="https://remvibecoder.com")
# {"org_id": 1, "publishable_key": "pk_...", "webhook_secret": "whsec_...", "endpoint_id": 7, "app": {...}, "credits": {"code": "vibecoder", "path": "/internal/v1"}}

connect is re-runnable: the same endpoint and secret come back. It also creates the app's REM Credits identity.

Payments

pay = PaymentsClient("https://rempayments.com", out["publishable_key"], token=PTK, org_id=out["org_id"], app="vibecoder")

pay.plans()                                  # the catalogue's plans (cached 60 s)
s = pay.checkout("pro", payer="org:42", email="owner@example.com",
                 success_url="https://remvibecoder.com/billing?cs={CHECKOUT_ID}")
redirect(s["hosted_url"])

pay.subscription("org:42")                   # the payer's current subscription, or None
pay.invoices("org:42"); pay.payments("org:42")
pay.cancel_subscription(sub_id, at_period_end=True, reason="downgrade")
pay.keep_subscription(sub_id)                # undo a scheduled cancellation
pay.entitlements("org:42")                   # what this payer may use

The payer reference stored in REM Payments is payer_ref("vibecoder", "org:42") = "vibecoder:org:42".

Credits

credits = CreditsClient("https://rempayments.com", PTK, code="vibecoder")

credits.balance("vibecoder:org:42")          # cached 5 s; fresh=True to skip the cache
h = credits.hold("vibecoder:org:42", "build", idempotency_key="build-7731")   # raises InsufficientCredits (402)
credits.start(h["hold_id"])
credits.settle(h["hold_id"], {"input_tokens": 5120, "output_tokens": 830}, call_id="call-7731")
# or: credits.release(h["hold_id"], reason="timeout", call_failed=True)
credits.ledger("vibecoder:org:42", limit=50)

Webhooks

from rem_payments import verify_webhook, WebhookError

def payments_webhook(request):
    try:
        event = verify_webhook(request.body, request.headers, WEBHOOK_SECRET)   # constant-time HMAC + 5-minute window
    except WebhookError:
        return HttpResponse(status=400)
    processor.handle(event)          # WebhookProcessor: plan, seats and status, once per event id
    return HttpResponse(status=200)

WebhookProcessor keeps the app's plan state (plan, seats, status), tolerates redelivery and events arriving out of order, and calls on_credits when credits change. DjangoStore keeps that state in two Django models; MemoryStore is for tests.

Last updated 18 Nov 2026

Python SDK · REM Platforms Blog