Per-user quotas and billing
~10 min Python TypeScriptGoal: Cap each of your end-users so they cannot exhaust your MIOSA allocation, then pull a monthly usage rollup per user to generate accurate invoices.
What you’ll use: Sandboxes (external attribution), Quotas API, Usage API
Overview
Every sandbox created with an external_user_id is automatically attributed. Two APIs build on top of that:
- Quotas - hard caps per
external_user_id: max sandboxes, max concurrent, max credits. - Usage - period-based metering rollup queryable by
computer_id, filterable and paginated.
Your platform
│
├─ Create sandbox ──── external_user_id="user-42" ──► MIOSA
│
├─ Set quota ────────── max_sandboxes=5 ──────────► MIOSA
│
└─ Invoice run ──────── usage.report(period_start, period_end) ──► billing system Step 1 - Attribute every sandbox to an end-user
Pass external_user_id on every create. MIOSA propagates it to every usage record and audit event automatically.
Step 2 - Set per-user quotas
Call client.quotas.set once during onboarding (or whenever a user upgrades their plan). Limits take effect immediately for all subsequent sandbox creates.
Step 3 - Check current quota state
Before creating a sandbox on behalf of a user, check whether they have headroom. This lets you surface a friendly upgrade prompt rather than a raw API error.
Step 4 - Monthly invoice rollup
At the end of each billing period, pull a usage report. The response gives you the data you need to generate per-user line items.
Connecting to Stripe (optional)
Once you have the per-user credit totals, map them to money and charge via Stripe:
What you learned
- Every sandbox created with
external_user_idis attributable - no extra tagging step required after create. client.quotas.set(user_id, {...})enforces hard caps per user. Call it on plan changes, not on every request.client.quotas.get(user_id)returns both the limits and current usage in a single call - use it for proactive upgrade prompts.client.usage.sessions()gives you the raw per-session metering rows you need to build an invoice rollup.- Connecting to Stripe is a thin adapter layer - MIOSA gives you the credits; you decide the USD rate.
Related
Full walkthrough of tagging, filtering, browser tokens, and per-tenant usage in a SaaS context.
Listen for sandbox lifecycle events to trigger billing actions (e.g., credit deduction on destroy).
Full parameter reference and enforcement semantics for the Quotas API.