Credits
How usage is counted
Meters charge after authentication and before the request is processed. Usage is recorded daily per project.
Overview
Before a metered Cloud handler runs, Gray3 checks the remaining allowance, then atomically increments a daily usage row for that organization, project, day, and meter. Failed auth does not consume credits; an exhausted allowance fails before any chain data is requested.
Flow
- Authenticate project credentials
- Resolve plan + owner credit period
- Look up the cost for the meter, using the default table or your plan's custom rate
- If
used + cost > allowance, returncredits_exhausted(402) - Otherwise increment usage and proceed
javascript
// Conceptual — not a public client API
const charged = cost(meter); // e.g. portfolio_get → 1
if (used + charged > allowance) throw credits_exhausted;
// upsert usageDaily { organizationId, projectId, day, meter } += chargedAttribution
- Project — which
proj_…made the call - Organization — billing parent that owns the allowance
- Day — UTC day buckets for charts
- Meter — which operation class was charged
Credit period
Usage sums across the owner's current credit period (from creditPeriodStart to creditPeriodEnd). The remaining balance is the allowance minus the credits used in the period and minus this charge.
Console mapping: How usage maps to Cloud calls.